1
votes

I have a magnitude of the vector pointing somewhere in 3D space from the origin (0x, 0y, 0z). I also have an angle that projection of the vector in X and Z axis makes between itself and the Y axis. In other words I have a joystick that reads X angle (from -35 to 35 degrees) for left-right movement and Z angle (from -35 to 35 degrees) for front-back movement. It returns 0 when joystick is is in its initial position. I get a reading of magnitude (how far the string is pulled out from the joystick). I need to find the coordinates (assuming 1 cm of magnitude is equal to a unit vector) of the point at the end of the string. Point will always locate above x-z axis plane. Magnitude is never 0.

I would appreciate an algorithm or a piece of code on Java, even though a link to extra materials will be good too. There are Q&A talking about rotational angles and matrix, but it looks like I have a different problem.

UPD: Angles are not between the vector and x,y,z axis. They are angles that projection of the vector onto axis makes with Y-axis.

UPD1: Joystick can be moved right-left and front-back:

    +z
     |            
-x -- -- +x       -x --'-- +x
     |
    -z
Top view          Side view (along z-axis)

As well as having an extendable string in the middle (s):

    +z                +s (+y)
     |                 |
-x -- -- +x       -x --'-- +x
     |
    -z
Top view          Side view (along z-axis)

When string is extended a point (P) in 3D is formed

    +z               +y                 +y
     | P              |  P               |  P
     |/               | /                | /
-x --/-- +x           |/                 |/
     |           -x --'-- +x        -z --'-- +z
    -z
Top view          Side view          Side view
               (along z-axis)      (along x-axis)

I receive coordinates in the following format:

- x-axis angle (call it alpha) [-1 1] in reality between [-35 and 35] degrees
- y-axis angle (call it theta) [-1 1] in reality between [-35 and 35] degrees
- magnitude of vector OP (call it magnitude) [-1 1] in reality between 0[ and 305] cm
3
Just curious, does the magnitude take values in the range of [1 sqrt(2)] inclusive?Suedocode
@Aggieboy Joystick returns coordinates from [-1 1] and I convert them to the distance from origin. I am trying to program for a Game Track controller.Xeos
It returns [-1 1]? I thought "Magnitude is never 0." The reason I ask is because it doesn't sound like the joystick is represented by a unit vector and hence has variable length.Suedocode
Well. It is how it was designed. Basically it is a joystick with extendable sting coming out of it. So if you pull the string out, it returns the distance the string was pulled. Extension is never negative, yet what joystick returns is negative, but nevertheless I convert [-1 1] reading into a real extension (length).Xeos

3 Answers

4
votes

It sounds like you have 2 angles and a magnitude, which is spherical coordinates. You're looking to convert spherical coordinates to cartesian coordinates:

Conversion

More information here.

EDIT:

Upon further inspection of the question, I see that the problem is much more odd. You have the projections of two component vectors, (0,y,z) and (x,y,0), on the y axis which describe pitch and roll. I'm sure the joystick gives another component for yaw, however it was not specified in the OP. The weird part is that it is not possible for these components to actually be vector components of an (x,y,z) vector because then the y projections would be the same. I think what the OP is looking for is the normal of the new plane created by these given component points and origin. For this to work, I must be given the magnitudes of the vectors that the projections originate from. Since it is not specified, I assume they were unit vectors.

Vector xPrime=Vector(sqrt(1-xProj^2),xProj,0);
Vector zPrime=Vector(0,y,sqrt(1-zProj^2));
Vector ans=cross(zPrime,xPrime);

Equation for cross product. The answer may need to have some components negated depending on the sign conventions in the OP.

0
votes

This does not seem to work as intended. I am trying to find the solution.

Let angle between Y axis and projection of vector in X axis be "alpha" and angle between Y axis and projection of vector in Z axis (theta). Line (projection) in x-axis has an equation:

y = (1/tan(alpha) * x) + (0 * z)

Line (projection in z-axis has an equation:

y = (0 * x) + (1/tan(theta) * z)

So we can rearange them to get the following equations:

x = (z * tan(alpha)) / tan(theta)
z = (x * tan(theta)) / tan(alpha)

If we replace all unknowns but one in the equation of magnitude of the vector:

|v| = sqrt(x^2 + y^2 + z^2)

We get an equation that can be rearanged in terms of x:

         /   magnitude^2 + tan^2(alpha)    \
x = sqrt |---------------------------------|
         \ tan^2(alpha) + tan^2(theta) + 1 /

Nice looking equation:

http://latex.codecogs.com/gif.latex?\sqrt{}\frac{\left%20|vector\right%20|^2%20+%20tan^2%28xy%29}{tan^2%28xy%29%20+%20tan^2%28zy%29%20+%201}

(copy - paste the link)

Then we can replace x in previous equations to get z and y.

0
votes

Here's a solution from my case (different axis, but the principle is the same)

enter image description here

Assuming:

OK = LT' = x [unknown]
OL = T'K = y [unknown]
OT = 1 [unit vector]
^TKT' = ^a
^TLT' = ^b

We figure out relation between x and y:

y = x * (tan(b) / tan(a))

With OT being a unit vector, x can be found by:

x = sqrt{ tan^2(a) * cos^2(b) / (tan^2(a) + sin^2(b)) }
y = 1 / sqrt{ tan^2(a) / sin^2(b) + 1 }

And z (TT') is:

z = x * tan(b)