Author Topic: rotating vertices around an origin =/= 0,0  (Read 883 times)



90 degree rotation. need formula for rotation.

referring to some code i wrote semi-recently:

for a given central Z axis and vertex, you can calculate the rotation of θ radians with:
dx = xvertex - xaxis
dy = yvertex - yaxis

x = cos(θ) * dx - sin(θ) * dy + xaxis
y = sin(θ) * dx - cos(θ) * dy + yaxis


z just stays the same

the fact that it isn't around the origin doesn't really make a difference, it effectively just acts as an offset, so you just have to subtract it out then add it back at the end
« Last Edit: June 11, 2017, 09:45:50 AM by otto-san »

wait so is the formula you gave correct or do i have an extra step?

the formula includes accounting for the axis, i was just giving some additional information that might help in the future


if you're only doing 90 degree rotations, you can simplify it without sin/cos

clockwise:
newX = oldY;
newY = -oldX;

counterclockwise:
newX = -oldY;
newY = oldX;

(pivot is the origin, rotations are looking down at it)

if you're using any other angle besides 90 for rotations, use sin/cos



its not torque related but i asked because i would get faster answers here. anyways its a success. essentially what i was trying to do was rotate collision box points with the map, because love2d is able to rotate graphics on its own but not vectors. so normally the map should be rotating with the points, but this is just a debug