Need Help with Angles

Ok so I need assistance converting absolute transformations to local transformations assuming there’s only a difference of angle on the Z axis. This is for something 2D so normal cframe stuff doesn’t apply here.

For example. Lets say there was a UI element at 0.5,0.5 and I wanted to move it to the right. I would obviously just add to the X position, and then it would be translated right.

The problem is, sometimes this UI has a rotation and I still need it to move to the correct spot. So if it’s rotated 45 degrees, in order to move it right, I need to add half of the movement on the x position, and half on the right.

What is an equation/formula I can use to reconcile the difference in rotation to get the correct translation?

Here’s a chart to help visualize what I mean:

deg - 0 = 1x, 0y = rad - 0
deg - 45 = 0.5x, 0.5y = rad - 0.78539816339745
deg - 90 = 0x, 1y = rad - 1.5707963267949
deg - 135 = -0.5x, 0.5y = rad - 2.3561944901923
deg - 180 = -1x, 0y = rad - 3.14
deg - 225 = -0.5x, -0.5y = 3.9269908169872
deg - 270 = 0x, -1y = rad - 4.7123889803847
local localTransform = function(pos,angle)
	angle = math.rad(angle)
	return Vector2.new(math.cos(angle)*pos.X + -math.sin(angle)*pos.Y, math.sin(angle)*pos.X + math.cos(angle)*pos.Y)
end

You put in a Vector2 and the rotation in degrees and it gives you a Vector2 with applied rotation.

Rotation matrices are really helpful for this if you ever feel like looking into them. http://mathworld.wolfram.com/RotationMatrix.html

2 Likes