سؤال

enter image description here

In above image the blank arrow will rotate randomly and stop at particular box.

I know the X & Y of each box how can i find the angle made by blank arrow. basically i want to find out at what angle each box is. I need to calculate this in javascript.

هل كانت مفيدة؟

المحلول

You can use slop to calculate angle

deltaY = Y  //(of Box Point 2 is (0,0) so Delta = Y2-Y1=Y2);
deltaX = X  //(of Box);

Than angle in degrees is

Degrees = arctan(deltaY / deltaX) * 180 / PI

If atan2 is present in library use(JavaScript)

Degrees = Math.atan2(deltaY ,deltaX) * 180 / PI
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top