Jump to content

Image of the Day

Working on #steam achievements!
#screenshotsaturday #indiegame #pixelart #NadiaWasHere #RPG #indiedev https://t.co/IcDuJSWsGK
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.


Sign up now

translate point set distance towards quaternion

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1 Koga73   Members   

125
Like
0Likes
Like

Posted 10 December 2012 - 03:26 PM

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!

Edited by Koga73, 10 December 2012 - 03:28 PM.


#2 Paradigm Shifter   Members   

5832
Like
0Likes
Like

Posted 10 December 2012 - 04:18 PM

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

#3 Koga73   Members   

125
Like
0Likes
Like

Posted 10 December 2012 - 04:27 PM

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?

#4 Paradigm Shifter   Members   

5832
Like
0Likes
Like

Posted 10 December 2012 - 04:43 PM

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

#5 Álvaro   Members   

20685
Like
0Likes
Like

Posted 10 December 2012 - 04:49 PM

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).

#6 Koga73   Members   

125
Like
0Likes
Like

Posted 10 December 2012 - 04:59 PM

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?

Edited by Koga73, 10 December 2012 - 05:00 PM.


#7 Paradigm Shifter   Members   

5832
Like
0Likes
Like

Posted 10 December 2012 - 05:04 PM

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).

Edited by Paradigm Shifter, 10 December 2012 - 05:04 PM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.