How to calculate an angle from points?

前端 未结 5 1720
天涯浪人
天涯浪人 2020-12-02 22:03

I want to get a simple solution to calculate the angle of a line (like a pointer of a clock).

I have 2 points:

cX, cY - the center of the line.
eX, e         


        
5条回答
  •  情书的邮戳
    2020-12-02 22:48

    You find here two formulas ,one from positive axis x and anticlockwise

    and one from the north and clockwise.

    There is x=x2-x1 and y=y2=y1 .There is E=E2-E1 and N=N2-N1.

    The formulas are working for any value of x,y, E and N.

    For x=y=0 or E=N=0 the result is undefined.

    f(x,y)=pi()-pi()/2*(1+sign(x))*(1-sign(y^2))

         -pi()/4*(2+sign(x))*sign(y)
    
         -sign(x*y)*atan((abs(x)-abs(y))/(abs(x)+abs(y)))
    

    f(E,N)=pi()-pi()/2*(1+sign(N))*(1-sign(E^2))

         -pi()/4*(2+sign(N))*sign(E)
    
         -sign(E*N)*atan((abs(N)-abs(E))/(abs(N)+abs(E)))
    

提交回复
热议问题