Drawing Hermite curves in OpenGL

后端 未结 3 820
半阙折子戏
半阙折子戏 2021-02-14 17:40

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 fin

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-14 18:18

    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.

提交回复
热议问题