Jump to content
• Advertisement

# Method to Calculate the MidPoint of a shape that is rotated

This topic is 2826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hello

I am developing a HTML5 Canvas Web App & I am having difficulty finding a formula/algorithm that will allow me to find the mid-point of a shape when it is rotated around a certain point.

I am given information about an arrow & I need to draw that arrow on the canvas - it gets tricky when the shape is rotated.

Can you suggest an algorithm I can use to calculate the mid-point of a shape.

The information I am know:
- x,y pos(which is the red dot) - width, height
- Arrow width, Arrow height
- Rotation in degrees

#### Share this post

##### Share on other sites
Advertisement
So arrow rotates around it's corner, not center, right?
Do you know center of unrotated arrow?
If you do, then just rotate center and add it to the point.

For example, point is at (10,10), arrow width & height are (20,10), then center of an arrow will be (10,5). Now lets say you rotate it by 45 degrees, that'll be (3.54, 10.6). Add this to your point and you get (13.54, 20.6). That's the new center.

#### Share this post

##### Share on other sites
Exactly what "mid point" means is not clear but, whatever it is, it will be a barycenter (a weighted average of points), and barycenters are preserved by affine transformations, which include rotations.

This means that you can either compute the mid point of the unrotated arrow and then rotate it, or you can compute it after the rotation, and you will get the same answer.

#### Share this post

##### Share on other sites
I'm assuming this is 2d. Anyway, you need to transform the "mid point" by the rotated translation vector from the center to the midpoint. If this is gibberish, allow me to elaborate in psuedocode:

Vector midpoint = Wherever you define the middle of your arrow. I'm guessing Vector<ArrowSpriteWidth/2,ArrowSpriteHeight/2>
Vector center = The point about which you rotate. In your picture, it looks like one of the corners.
Vector translation = midpoint - center

Now, I'll assume you have some rotation value theta (easy in 2d, eh?). the new midpoint after rotation is simply center+Vector<translation.x*cos(theta), translation.y*sin(theta)>. Unless I'm mistaken.

#### Share this post

##### Share on other sites

• Advertisement
• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• Advertisement

• ### Popular Now

• 16
• 15
• 9
• 11
• 15
• Advertisement
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!