A
A
Alexander Antonov2015-09-17 01:48:13
JavaScript
Alexander Antonov, 2015-09-17 01:48:13

How to find the angle between points on the "almost unit circle"?

9e7994276be94c53b7cc3fea23bc3198.png
There is a space 500x500, with the center O(250, 250)
There is a point А(112,392)
Length AO = 198
How to find the angle a ?
This formula always returns an angle between 0 and 90:

class Vector
{
    dX()
    {
        return Math.abs( this.points[1].x - this.points[0].x );
    }
    dY()
    {
        return Math.abs( this.points[1].y - this.points[0].y );
    }
    getAngle()
    {
         var Anlge = Math.atan2( this.dY(), this.dX() ) / Math.PI * 180;

         return (Anlge < 0) ? Anlge + 360 : Anlge;
     }
}

It is necessary that the function return an angle from 0 to 360 in whatever quarter point A is.
Trigonometry was skipped at school, alas ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Antonov, 2015-09-17
@undermuz

Found the problem. If anyone needs:

class Vector
{
    dX()
    {
        return this.points[1].x - this.points[0].x;
    }
    dY()
    {
        return this.points[1].y - this.points[0].y;
    }
    getAngle()
    {
         var Anlge = Math.atan2( this.dY(), this.dX() ) / Math.PI * 180;

         return (Anlge < 0) ? Anlge + 360 : Anlge;
     }
}

K
keslo, 2015-09-17
@keslo

It's like this:
Angle a = 360 - 90 - atan(|(250-112)/(250-392)|)
From here you can already throw the script :-) Sorry
, I'm writing from the phone. If it’s relevant, I’ll write the code by lunchtime

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question