Inverse of math.atan2?

前端 未结 4 804
面向向阳花
面向向阳花 2021-02-07 06:46

What is the inverse of the function

math.atan2

I use this in Lua where I can get the inverse of math.atan by math.tan

4条回答
  •  名媛妹妹
    2021-02-07 07:01

    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)
    

提交回复
热议问题