3D Vector defined by 2 angles
Asked Answered
F

2

29

So basically I'm looking for a way to calculate the x, y and z component of a vector using 2 angles as shown: enter image description here Where alpha is the 2D angle and beta is the y angle. What I've been using uptill now for 2D vectors was:

x = Math.sin(alpha);
z = Math.cos(alpha);

After searching on stackexchange math I've found this forumula doesn't really work correctly:

 x = Math.sin(alpha)*Math.cos(beta);
 z = Math.sin(alpha)*Math.sin(beta);
 y = Math.cos(beta);

Note: when approaching 90 degrees with the beta angle the x and z components should approach zero. All help would be appreciated.

Fagaceous answered 3/5, 2015 at 8:28 Comment(0)
V
39

The proper formulas would be

x = Math.cos(alpha) * Math.cos(beta);
z = Math.sin(alpha) * Math.cos(beta);
y = Math.sin(beta);
Village answered 3/5, 2015 at 8:33 Comment(5)
Thanks, that works and makes a lot more sense. (i had to switch the x and z but that's just how my enviroment is set)Fagaceous
@MoffKalast Two angles on perpendicular planes are sufficient to define a vector in 3D space. You could calculate the angle of the projection on the third plane (in this example, XY) using the first two angles.Substitute
Any idea on how to compute it, if the used x,y,z directions were relative to a plane of a model, and not relative to the coordinate-system the model sits within?Limburger
I took a stab at doing this in 4D, I came up with: a = Math.cos(gamma); x = Math.cos(alpha)*Math.cos(beta)*a; z = Math.sin(alpha)*Math.cos(beta)*a; y = Math.sin(beta)*a; w = Math.sin(gamma); How close was I?Baelbeer
Given alpha and beta, what is the angle between red and green lines.Gottuard
H
-1

That formula just come from the transformation of Spherical coordinates (r, theta, phi) -> (x, y, z) to Cartesian coordinates.

Hitch answered 11/10, 2022 at 8:7 Comment(1)
The angle beta shown by OP is not the same as the polar angle in spherical coordinatesTedda

© 2022 - 2024 — McMap. All rights reserved.