Game Development Community

Quick Math Question

by Griffin Milsap · in Technical Issues · 11/28/2005 (7:07 pm) · 2 replies

Hey. I have a small math problem.

I am looking to create a cylindrical mesh around a path in torque. I found out that the torque game engine uses catmull-rom splines for its paths. What I need, is a way to find the plane which is perpindicular to the spline at some point "P".

I know how to find a point on the spline, but I need the plane perpindicular to the spline at that point. From what I learned in calculus, I need a derivitive to find the slope of the tangent line, then I can calculate the plane perpindicular to that tangent. I have no idea how this works in catmull-rom splines though.

Once I find this plane, I can place the vertices in a circular way, and connect them to the previous set of vertices to create a cylinder.

How can I find this ilusive plane?

Am I going about this the right way?

-Griff

#1
11/29/2005 (8:41 am)
Just use the definition of the derivitive.

( f(x+h) - f(x) ) / h

Don't worry about solving the limit, unless you need to be really exact about it. Just pick a small value of h and run with it.
#2
11/29/2005 (3:31 pm)
Actually, I found a better way to do it. However, there is still a problem

Basically, I have to find the movement vector of a certian point on the spline. (Tangent vector). This is vector 1.

I can create the points on the xy axis at the world origin, then create a normal to that plane up the Z axis. This is vector 2.

Then I find the arccosine of the dot product between the movement vector of the point on the spline and the normal of the points on the XY, XZ, and YZ axis. I keep all these values, as they contain the rotation information I need.

Then I just rotate my set of points by each value as given by the above, and translate the set of points to that point on the spline.

so, basically...


//Find my rotations
rot.xy = arccos(dot(vector1.xy, vector2.xy));
rot.yz = arccos(dot(vector1.yz, vector2.yz));
rot.xz = arccos(dot(vector1.xz, vector2.xz));

//rotate my points
multMatrix(vertices, rotMatrix(rot.xy));
multMatrix(vertices, rotMatrix(rot.yz));
multMatrix(vertices, rotMatrix(rot.xz));

//translate my points
multMatrix(vertices, transMatrix(P.pos));

... Rendering code


I think it works, but heres where my problem comes in.

Does anybody know how to find the tangent vector to the spline at point p in the torque game engine? Once I have that, I'm all set

-Griff