translate point set distance towards quaternion

Started by
5 comments, last by Paradigm Shifter 11 years, 4 months ago
Hi,
I'm new to quaternions and want to use the resulting rotation matrix to translate a point a towards the quaternion given a set distance.


Without using quaternions or matrices I would do something like this:

public static function calcVector(angle:Number, distance:Number = 1):Vector2D {
var vec:Vector2D = new Vector2D();
vec.x = Math.sin(90 - angle) * distance;
vec.y = Math.sin(angle) * distance;

return vec;
}


How do I mimic this functionality using the quaternions resulting rotation matrix as my "angle" parameter?
Assuming the starting point is at (0, 0, 0) and I have a rotation matrix from a quaternion how do I translate the starting point towards the quaternion with a set distance of say 10 units?
I would like to keep everything in the form of vectors, quaternions, and matrices.

Thanks for the help!
Advertisement
If your starting point is at the origin, applying a quaternion won't do any good (the origin is a fixed point for rotations), I'm guessing you want to apply the quaternion to the forward facing axis of something... try (1, 0, 0) if your objects face in the +x direction...
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
In my case I have an XZ plane with the normal facing +Y.

I am using the following for my quaternion:
var quat:Quaternion = new Quaternion();
quat.fromAxisAngle(new Vector3D(0, 1, 0), rot * MathConsts.DEGREES_TO_RADIANS);
var mat:Matrix3D = quat.toMatrix3D();

So now I have a rotation matrix... I am wanting to make the plane orbit around the origin... so for instance if my distance is 10 units and my origin is (0, 0, 0) and my angle is 0° then I would expect the plane's resulting position to be (10, 0, 0).

I'm just not sure how to actually apply the distance and quaternion to get the planes resulting position?
You apply a quaternion by either turning it back into a matrix and doing matrix multiplication in the usual way, or you do

v' = q * v * conjugate(q)

where v = 0 + xi + yj + kz [x,y,z is the (x, y, z) position vector for the point.], and v' is the result of applying the quaternion rotation.

Note: rotating 0 degrees doesn't do anything... and by distance it sounds like you mean applying a scale?

You're being a bit unclear and I've had beers so I'll probably bow out of this for now ;)
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
I think PS's first post was correct. The OP needs to take the point (1,0,0), apply the rotation to it (either through a matrix or through the conjugation formula) and multiply by the distance. Equivalently, one could apply the rotation to (distance, 0, 0).
Yeah as for rotating zero in my example I know it doesn't do anything it was just easy math for me to show what I expect the resulting point to be. As you stated above applying the rotation to (distance, 0, 0) does work!


var quat:Quaternion = new Quaternion();
quat.fromAxisAngle(new Vector3D(0, 1, 0), rot * MathConsts.DEGREES_TO_RADIANS);

var mat:Matrix3D = new Matrix3D();
mat.position = new Vector3D(10, 0, 0);
mat.append(quat.toMatrix3D());

plane.position = mat.position;


This is good and all but now I want to abstract it out into a function that takes in an axis vector, an angle, and a distance. It doesn't seem like the same code above would work if the axis were not the Y due to the position being hard-coded to (distance, 0, 0). I guess at this point I'm just looking for what that vector should be? The magnitude should always be the distance but does it matter what value I start it at?
I'm guessing you want to start with the current facing of the object? If your plane is in XZ you should apply the rotation quaternion to the normal (which is the y axis).
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

This topic is closed to new replies.

Advertisement