Advertisement

How to rotate a line around a point?

Started by June 06, 2020 03:55 AM
4 comments, last by fleabay 4ย years, 3ย 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?

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.

Advertisement

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!

A rotation matrix is used. It's simple and it's standard.

๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚<โ†The tone posse, ready for action.

This topic is closed to new replies.

Advertisement