Relative vector rotation in cartesian space

Jarvitä

New member
Joined
Aug 5, 2008
Messages
2,030
Reaction score
3
Points
0
Location
Serface, Earth
Okay, my vector magic is running low here, some help would be appreciated.

I'm trying to rotate a vector in the coordinate origin in Cartesian space with coordinates (x,y,z) by some angle about it's relative y-axis - that is, the axis that points at (0,1,0) when the vector is pointing straight at x, and maintains its relative position as the vector rotates. How the :censored: do I even begin to go about that?
 

Radu094

Donator
Donator
Beta Tester
Joined
Sep 5, 2008
Messages
36
Reaction score
0
Points
6
Just to make sure I understood:
you want to apply a rotation to a vector (V1) with an angle 'a' , around axis V2
And you want to have V2 be the Y-axis in V1's frame of reference.
Now the problem is that one vector does not a frame of reference make. ie you need at least 2 vectors to properly define your relative Y-axis. You could assume that Y-axis always points 'up' wrt to the origin frame of reference. Much as 'North' is usually considered as 'Up' regardless of the orbital plane.

So now you have:
Va = V1 x (0,1,0)
V2 = Va x V1

and that is your relative Y-axis vector that you want to rotate arround.Be carefully though as, because we assumed (0,1,0) to be the relative 'North', you are prone to gimbal problems when your V1 vector is approaching (0,1,0). Only way to avoid this is to keep a proper vector pair (eg. an up and a forward vector)
 
Last edited:

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
Well, you need either a second point or the vector's rotation matrix to describe the relative coordinate system. One vector in the global frame is not sufficient to define a relative system.

If you say that the vector could only "come there" by some special operations - let's say first yaw, then pitch, no roll - you'd have a rotation matrix already.

Without this information, you don't know where the y-axis is pointing to.

Or did I misunderstand something here?

regards,
Face

---------- Post added at 12:08 ---------- Previous post was at 12:07 ----------

Damn. :ninja:ed by Radu.
 

Jarvitä

New member
Joined
Aug 5, 2008
Messages
2,030
Reaction score
3
Points
0
Location
Serface, Earth
Okay, I've got the rotational matrices down. Next question: How do I define the relative axes given global axes and the vector I'm trying to rotate?
 

agentgonzo

Grounded since '09
Addon Developer
Joined
Feb 8, 2008
Messages
1,649
Reaction score
4
Points
38
Location
Hampshire, UK
Website
orbiter.quorg.org
Off the top of my head, you could take your original vector (a)and then add a value (any value) to its y component (let's call this new vector b). Then you could cross-product the two vectors a and b together. This would give you a vector (c) perpendicular to them both. You could then cross this new vector with your original vector which should give you a fourth vector (d) that should be the vector you are looking to rotate around. Vectors a, b and d should be co-planar if my maths works.

It seems a bit around-the-houses but should work. There is probably a shorter solution but I don't have the time to think hard about it.
 

Jarvitä

New member
Joined
Aug 5, 2008
Messages
2,030
Reaction score
3
Points
0
Location
Serface, Earth
Well, my solution involved numerous conversions between cartesian and spherical coordinates, so this should run far faster.

To clarify:

A = (Ax, Ay, Az)
B = (Ax, Ay+n, Az)
C = A cross B
D = C cross A

Correct?
 
Last edited:

agentgonzo

Grounded since '09
Addon Developer
Joined
Feb 8, 2008
Messages
1,649
Reaction score
4
Points
38
Location
Hampshire, UK
Website
orbiter.quorg.org
Well, my solution involved numerous conversions between cartesian and spherical coordinates, so this should run far faster.

To clarify:

A = (Ax, Ay, Az)
B = (Ax, Ay+n, Az)
C = A cross B
D = C cross A

Correct?
Yes, but I'm still hoping that someone else will post an even simpler method.

---------- Post added at 13:33 ---------- Previous post was at 13:30 ----------

Just had another thought:
A = (Ax, Ay, Az)
B = (Ax, 0, Az)
C = RB

where R is the rotation matrix about the Y axis by 90°:
[math] R = \begin{bmatrix} 0 & 0 & -1 \\ 0 & 1 & 0 \\ 1 & 0 & 0 \end{bmatrix} [/math]
So that should simplify down to:
C = (-Az, 0, Ax)
 
Last edited:

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
Instead of using B = [Ax, Ay+n, Az] you could directly use B_0 = [0, n, 0], since
[math] A \times B = A \times (A+B_0) = A \times A + A \times B_0 = A \times B_0 [/math]
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
not if A = [0, m, 0] you couldn't as then A x B_0 is not defined.

Not sure I understand. It's certainly true that if A is parallel to the y-axis, then projecting A onto the y-axis won't give you a new direction, and A x B_0 = 0. But the same is true for A x B, so the case A=[0,m,0] requires special treatment anyway.
 

agentgonzo

Grounded since '09
Addon Developer
Joined
Feb 8, 2008
Messages
1,649
Reaction score
4
Points
38
Location
Hampshire, UK
Website
orbiter.quorg.org
Not sure I understand. It's certainly true that if A is parallel to the y-axis, then projecting A onto the y-axis won't give you a new direction, and A x B_0 = 0. But the same is true for A x B, so the case A=[0,m,0] requires special treatment anyway.
Yes... good point. <whistles>
 
Top