tags:

views:

181

answers:

3

I am trying to implement a Point3.Slerp method, so was looking for some samples but the ones I found seems like it's a whole brand new class to host all the code.

Is there a simple, straightforward way to implement it? Basically the ones I have seen was using Matrix types. Can I implement Slerp without matrices, or would that be a disadvantage (performance, etc)?

Pseudo codes are fine too.

A: 

To Slerp you need quaternions, which is why there is a whole new class.

Dolphin
+2  A: 

Spherical linear interpolation typically used with Quaternions, not Points. It's only really meaningful when you are trying to interpolate between two specific rotations.

The only place where I can see this being directly related to Point3 would be if you had 2 points on the surface of a sphere, and you wanted to "slerp" between them around the geodesic path. In that case, your points aren't really points being interpolated - they're being used to compute two axes and angles (which define quaternions) and interpolating between those.

If you're interpolating between two point3 values, direct linear interpolation is probably what you would want to do.

As for using matrices - if you get your points into quaternion form, you can use quaternion math directly - no matrices required.

Reed Copsey
+2  A: 

A point slerp is meaningful if you're working with a spherical space (such as a planet's surface or likewise).

Off the top of my head I would take the cross product of your start and end points (as vectors) to get a rotation axis then you can calculate a rotation for the X, Y, and Z (to avoid having to create your own matrix class, as you seem to want to).

http://en.wikipedia.org/wiki/Rotation_matrix#Dimension_three

That link shows a rotation matrix for an axis/angle pair. Just write out the multiplication for each component and simplify to get a matrix-less tranformation.

edit:

Heres a simple decomposed rotation about an axis (x, y, z):

X' = (x^2 + (1 - x^2) * cos(theta) + (x * y * (1 - cos(theta)) - x * sin(theta)) + (x * z * (1 - cos(theta)) + y * sin(theta))
Y' = (x * y * (1 - cos(theta)) + z * sin(theta)) + (y^2 + (1 - y^2) * cos(theta)) + (y * z * (1 - cos(theta)) - x * sin(theta))
Z' = (x * z * (1 - cos(theta)) - y * sin(theta)) + (y * z * (1 - cos(theta)) + x * sin(theta)) + (z^2 + (1 - z^2) * cos(theta))

Since you want a parameterized rotation as well, make sure you calculate the angle between your vectors (the inverse cosine of the scalar product of the two points) and set your theta as a value between 0 and that angle based on your interpolation parameter.

Ron Warholic