Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Axiverse

Hermite

This topic is 5179 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
A Hermite spline makes use of 2 end-points, and 2 vectors representing tangents to the curve at those endpoints:

Vector Start, End;
Vector TanStart, TanEnd;


There are 4 functions you need to use, called basis functions:

b1(t) = 2t^3 - 3t^2 + 1
b2(t) = -2t^3 + 3t^2
b3(t) = t^3 - 2t^2 + t
b4(t) = t^3 - t^2


t ranges in value from 0 to 1. At 0, the curve is evaluated as the Start point, and at 1 the curve is evaluated at the End point. The basis functions are used to, in effect, weight the values of the control points to obtain the final curve evaluation for t. The first step in evaluating the curve at t is to plug t into the basis functions, and obtain the results. For instance, at t=0.5 you would get the following values for the basis functions:

b1(t)=2*t*t*t - 3*t*t + 1 = 2*(0.5)*(0.5)*(0.5) - 3*(0.5)*(0.5) +1 = 0.5

b2(t)=-2*t*t*t + 3*t*t = 0.5

b3(t)=t*t*t - 2*t*t + t = (0.5)*(0.5)*(0.5) - 2*(0.5)*(0.5) + 0.5 = 0.125

b4(t)=t*t*t - t*t = (0.5)*(0.5)*(0.5) - (0.5)*(0.5) = -0.125


Now, b1() applies to the Start point, b2() applies to the End point, b3() applies to TanStart and b4() applies to TanEnd():

P(t)=Point on curve at t

P(t)=Start*b1 + End*b2 + TanStart*b3 + TanEnd*b4


You simply apply that formula to every component of the curve control point vectors to get the corresponding component in the P(t) vector. For instance, if the curve control points are 3D vectors (x,y,z):

P.x = Start.x*b1 + End.x*b2 + TanStart.x*b3 + TanEnd.x*b4
P.y = Start.y*b1 + End.y*b2 + TanStart.y*b3 + TanEnd.y*b4
P.z = Start.z*b1 + End.z*b2 + TanStart.z*b3 + TanEnd.z*b4


It should be simple enough to extend the idea for however many dimensions your curve points represent.

For a more technical explanation, see the this Siggraph paper, or this page.


Golem
Blender--The Gimp--Python--Lua--SDL
Nethack--Crawl--ADOM--Angband--Dungeondweller

Share this post


Link to post
Share on other sites
Thanks alot...

When I looked at each web page I found It was always filled with matricies. So the matricies are just for finding the base equasion right? I won''t need them in my program, right?

Thanks again.

Share this post


Link to post
Share on other sites
The matrices aren''t necessary, they''re just a notational shorthand that can be convenient if you understand them. If you have a good matrix math library, it is easy to set up the operations as matrix transforms. If not, then don''t worry about it.

The way it works with matrices is you build a couple different ones. One matrix has the coefficients of the basis equations (all the -2, -3 type values), one has the t factors (t^3, t^2, etc...) and one has the points of the curve. When the matrix multiplications are performed, it does exactly what I outlined in my earlier post, calculating the values of the basis functions at t and multiplying them by the points, adding the results together. The cool thing about matrices is that simply by changing the coefficients, you can use different basis functions, such as Bezier.

So, the matrix math for hermite splines begins with these 2 matrices:

| s^3 | | 2 -2 1 1 |
S = | s^2 | h = | -3 3 -2 -1 |
| s^1 | | 0 0 1 0 |
| 1 | | 1 0 0 0 |

When these matrices are multiplied together, you get a matrix filled with the values of the basis functions (b1(), b2(), b3(), b4()) just as were calculated by hand in my earlier post. When this new matrix is used to transform the points, you get the P(t)=Start*b1 + End*b2 + TanStart*b3 + TanEnd*b4 construction.

By changing the coefficient (h, above) matrix to:

| -1 3 -3 1 |
h = | 3 -6 3 0 |
| -3 3 0 0 |
| 1 0 0 0 |

you automagically have the basis functions for a Bezier curve rather than a Hermite curve. Aren''t matrices fun?

Seriously, though, the notational shorthand of matrix operations when dealing with things like this can be very, very handy. Using them can simplify things and possibly allow for some optimizations down the road. But if you don''t understand them, don''t worry too much, as you can always perform the operations by hand just as I demonstrated earlier.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!