Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript angle direction [closed]

Simple javascript angle question:

Which direction do angles go in in javascript?

Is it:

   90
180    0
   270

or

   270
180    0
   90

or something else?

I'm aware that javascript uses radians, I used degrees for illustraion.

like image 580
Testic Avatar asked Oct 21 '22 13:10

Testic


1 Answers

On a regular unit circle, the y axis points up, so the angles increase counter-clockwise:

enter image description here

But in an HTML document, or the canvas element, the y axis points down, so if you increase the angle t and plot points on x, y with cos(t), sin(t), the result will be clockwise:

       270
 180          0
       90

(Live example)

As the other answers say, that's not because of how angles work in JavaScript, but because of how the coordinate space is oriented.

like image 139
bfavaretto Avatar answered Nov 02 '22 05:11

bfavaretto