# Javascript Canvas Question - Confusing coordinates, velocity vectors and the unit circle.

This topic is 988 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have some confusion with how to handle rotations and angles in javascript when using canvas.  It's all because of how the Y axis is going in a positive direction as it goes down, negative Y to traverse upward on the screen.

I created a vector class, and for particles I give them a velocity vector.  That works out fine.  However, when it comes to determining rotations, and getting angles from Math.atan2(y,x), it becomes unclear how to handle this.  The standard unit circle from trig has that downward pointing Y axis as negative.

It seems to get hairy when I think about how to implement this.  Do I invert the Y coordinate on velocity before using it in math functions?  That has an issue when you're at the top and bottom of the circle.

What is the best approach here in dealing with a vector that plots into something of a half inverted unit circle?  Even the radians don't behave in the standard way.  The radian that would normally be PI/2 is -PI/2.

I suppose I could translate the canvas to put the origin in the bottom left corner, but I'm really curious how to do these rotations, and point objects in the direction of a vector's angle using the default coordinate system.  I'm a bit stumped at the moment, maybe it will come to me later, but any help or pointers would be much appreciated.  ^_^

##### Share on other sites

You're just looking at the space from the wrong direction.

[attachment=31337:unit-circle9_43217_lg.gif]

##### Share on other sites

You're just looking at the space from the wrong direction.

Wow thanks.  I see.  When you use something like context.arc() now I notice if you do PI/2 it draws the arc down to the bottom quadrant first.

So my rotation math and angles have to be inverted as well.

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
15
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013644
×