Inverse of math.atan2?
Apparently, something like this will help:
x = cos(theta)
y = sin(theta)
Simple Google search threw this up, and the guy who asked the question said it solved it.
Given only the angle you can only derive a unit vector pointing to (dx, dy)
. To get the original (dx, dy)
you also need to know the length of the vector (dx, dy)
, which I'll call len
. You also have to convert the angle you derived from degrees back to radians and then use the trig equations mentioned elsewhere in this post. That is you have:
local dy = y1-y2
local dx = x1-x2
local angle = atan2(dy,dx) * 180 / pi
local len = sqrt(dx*dx + dy*dy)
Given angle
(in degrees) and the vector length, len
, you can derive dx
and dy
by:
local theta = angle * pi / 180
local dx = len * cos(theta)
local dy = len * sin(theta)