[Math] Calculate Cartesian coordinates based on the distance and the angle

coordinate systems

I'm trying to calculate the $x$ and $z$ coordinate of a coordinate based on the angle and the distance of the origin $(0,0,0)$. Even though I use a 3-dimensional system I watch from top down which basically means I ignore the $y$-axis. See the image reference below so you can see what I mean.

Assuming I have the correct distance in Meters and the angle in Degrees I could calculate the cartesian coordinates relative to the center.

For this I use the following formulas:

X coordinate: d * cos(a * π / 180)

Z coordinate: d * sin(a * π / 180)

The 'd' is the distance, the 'a' is the angle.

The formula's above are the only ones that I found online in terms of calculating cartesian coordinates based on angle and distance, so I figured they are correct. As you can see in the image below the $z$-axis (or the $y$-Axis) is reversed. But even when I multiply the $z$ value with $-1$ I get wrong values.

Example: If I were to have a distance of 5 and a angle of 45 degrees
I should basically have the (rounded) coordinate $(3,53, 0, -3,53)$. Again, if you take the referenced image it makes more sense. I just replaced the $y$ with the $z$ axis.

Are the formulas wrong or am I doing something wrong? If you need something clearer just ask me and I'll try to explain it 🙂

Thanks in advance.

Grid visualization image link (imgur)

Best Answer

The main problem is that your equations are not consistent with your coordinate system.

Your equations are consistent with this coordinates, which is much more commonly used in mathematics:

enter image description here

Unless otherwise specified, mathematical articles usually use this coordinate system when dealing with 2D problems.

There are two main characteristics:

  1. The vertical axis increases upward, and the horizontal axis increases rightward.

  2. The angles are consistent with the right-hand grip rule: angle increases in the anticlockwise direction.

For your coordinate system, you need to modify your equations, which are stated in one of the comments on your question.

Related Question