How to rotate a line around a point?

Started by
3 comments, last by CherylCantrell 3 years, 10 months ago

I have tried everything around the internet and nothing worked. I'm pretty sure I am doing something stupidly wrong.

Basically, I have a line which is drawn (startX, startY, endX, endY) and I want to rotate it around the center (where the player's X and Y is).

Here's the image:

The little dot is the center

I actually have a triangle::

So I have three lines, each of them have their startX, startY, endX, endY coordinates.

I am trying to do it step by step, so how would I even rotate one line first?

Advertisement

Think of it another way. It's not the lines that move, but your perception of them that rotates. Like rotating a camera around an object, or a doing a barrel roll with a space ship. Same concepts.

If you know how to rotate points, you can rotate line segments, just by rotating the ends. If you know how to rotate points around the origin, you can rotate points around arbitrary points, by first subtracting the coordinates of the center of rotation, then rotating around the origin, then adding back the coordinates of the center of rotation. Rotating a point around the origin is much easier to find online. My favorite way to do it is by using multiplication of complex numbers, where multiplying by cos(a)+sin(a)*i is a rotation by the angle ‘a’.

alvaro said:

If you know how to rotate points, you can rotate line segments, just by rotating the ends. If you know how to rotate points around the origin, you can rotate cpstest points around arbitrary points, by first subtracting the coordinates of the center of rotation, then rotating around the origin, then adding back the coordinates of the center of rotation. Rotating a point around the origin is much easier to find online. My favorite way to do it is by using multiplication of complex numbers, where multiplying by cos(a)+sin(a)*i is a rotation by the angle ‘a’.

Yeah @alvaro is right!

This topic is closed to new replies.

Advertisement