views:

1493

answers:

3

Hi,

I am a beginner, started learning openGL from the Red book since last week. i have a question regarding Hermite curves, how can I draw Hermite curves using OpenGL, are there any built in functions? I saw some examples on line that show how to use evaluators to draw bezier curves but could not find any information for Hermite curves.

Any help is greatly appreciated.

+1  A: 

You can convert any Hermite curve into a Bezier curve and then draw that. They are simply defined using two different bases in C3. Google wasn't very useful, and it seems like this would be a common question, so we should try to make the StackOverflow answer definitive, maybe with some sample code. I'll come back tomorrow with more.

Steven Canfield
+3  A: 

As Steven mentioned, you can convert a cubic Hermite curve to a cubic Bezier curve. It's actually quite simple.

A typical cubic Hermite curve is defined with two points and two vectors:

  • P0 -- start point
  • V0 -- derivative at P0
  • P1 -- end point
  • V1 -- derivative at P1

The conversion to a cubic Bezier is simply:

B0 = P0
B1 = P0 + V0/3
B2 = P1 - V1/3
B3 = P1

You can then draw your Bezier curve using and evaluator or any other way you wish.

Naaff
+4  A: 

Let the vector of control points for your Bezier be [b0 b1 b2 b3] and those for your Hermite be [h0 h1 v0 v1] (v0 and v1 being the derivative / tangent at points h0 and h1). Then we can use a matrix form to show the conversions:

Hermite to Bezier

[b0] = 1 [ 3  0  0  0] [h0]
[b1]   - [ 3  0  1  0] [h1]
[b2]   3 [ 0  3  0 -1] [v0]
[b3]     [ 0  3  0  0] [v1]

(this is exactly as in Naaff's response, above).

Bezier to Hermite

[h0] = [ 1  0  0  0] [b0]
[h1]   [ 0  0  0  1] [b1]
[v0]   [-3  3  0  0] [b2]
[v1]   [ 0  0 -3  3] [b3]

So in matrix form these are perhaps slightly more complex than needed (after all Naaff's code was short and to the point). It is useful, because we can go beyond Hermites very easily now.

In particular we can bring in the other classic cardinal cubic parametric curve: the Catmull-Rom curve. It has control points [c_1 c0 c1 c2] (unlike Bezier curves, the curve runs from the second to the third control point, hence the customary numbering from -1). The conversions to Bezier are then:

Catmull-Rom to Bezier

[b0] = 1 [ 0  6  0  0] [c_1]
[b1]   - [-1  6  1  0] [c0]
[b2]   6 [ 0  1  6 -1] [c1]
[b3]     [ 0  0  6  0] [c2]

Bezier to Catmull-Rom

[c_1] = [ 6 -6  0  1] [b0]
[c0]    [ 1  0  0  0] [b1]
[c1]    [ 0  0  0  1] [b2]
[c2]    [ 1  0 -6  6] [b3]

I can do the Hermite to Catmull-Rom pair too, but they're rarely used, since Bezier is normally the primary representation.

Ian