What is the easiest way to calculate vector coordinates in 3D given 2 angles vector length?


  1. Angle between X and Y axis: $$\alpha \in [0, 360).$$
  2. Angle between Y and Z axis: $$\beta\in [0, 360).$$
  3. Scalar length.

Expected output:

X, Y, Z coordinates of the vector

  • $\begingroup$ Angels? I think you meant to say angles. :) $\endgroup$ – wltrup Aug 5 '15 at 8:45

You have presented a point in spherical coordinate system, which needs to be converted to Cartesian. The line joining the origin to the point will be the vector. Let the scalar length be $r$. If the $\beta$ angle is measured from $Y$ axis towards $Z$ axis and $\alpha$ from $X$ axis towards $Y$:

$$x = r \cos \beta sin \alpha$$ $$y = r \cos \beta cos \alpha$$ $$z = r \sin \beta$$

The vector is: $x \hat{i} + y\hat{j} + z\hat{k}$.

  • $\begingroup$ Thank you very much! It works! I just tested it with OpenJSCAD work perfectly for all angles. $\endgroup$ – mrh Aug 5 '15 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.