Created
October 23, 2024 05:09
-
-
Save bennobuilder/6781a3c5b21d2a24621fb3d9f64c2e8f to your computer and use it in GitHub Desktop.
Why Math.atan2(0, -1) Returns -90 Degrees Instead of 0 for a Falling Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The reason it's -90 degrees rather than 0 is because atan2 uses the standard mathematical coordinate system where: | |
The x-axis runs horizontally (right is positive) | |
The y-axis runs vertically (up is positive) | |
Angles are measured counterclockwise from the positive x-axis | |
In this system: | |
0 degrees points to the right (positive x-axis) | |
90 degrees points up (positive y-axis) | |
-90 degrees points down (negative y-axis) | |
180/-180 degrees points to the left (negative x-axis) | |
When an object is falling straight down: | |
velocityX = 0 (no horizontal movement) | |
velocityY = -1 (negative because it's moving down) | |
atan2(-1, 0) = -90 degrees | |
This is correct because the object is moving along the negative y-axis, which is indeed -90 degrees in this coordinate system. If you wanted 0 degrees to represent downward movement, you would need to either: | |
Add 90 degrees to the result | |
Or use a different coordinate system where 0 represents downward movement | |
Author
bennobuilder
commented
Oct 23, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment