Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert from an 'hermite' curve into bezier curve?

Tags:

c#

math

wpf

xna

bezier

As the topic states: How to convert from an Hermite curve into Bezier curve? Specifically I'm looking for a way to convert the Curve class, that uses Hermite interpolation, of the Microsoft XNA Framework to be drawn with StreamGeometry or PathGeometry of Windows Presentation Foundation.

I've come across a similar question ([Drawing Hermite curves in OpenGL) where the answer is the following.

[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]

Which simplifies to:

b0 = h0
b1 = h0 + v0/3
b2 = h1 - v1/3
b3 = h1

Even with this information I'm in essence stuck on computing the control points. The Problem is that Curve class exposes a TangentIn and TangentOut as a scalar. Given that drawing of the polynomial occurs in 2-dimensional space (time, value) this scalar needs to be converted into a 2-dimensional vector in order to apply it to that formula. However I'm unsure what the steps are involved of this conversion process but I suspect I need to apply the Hermite differentiation equation.

If it helps this is the code used to evaluate the curve at a given moment as found with Reflector.

private static float Hermite(CurveKey k0, CurveKey k1, float t)
{
     if (k0.Continuity == CurveContinuity.Step)
     { 
         if (t >= 1f)
         {
             return k1.internalValue;
         }
         return k0.internalValue;
     }

     float num = t * t;
     float num2 = num * t;
     float internalValue = k0.internalValue;
     float num5 = k1.internalValue;
     float tangentOut = k0.tangentOut;
     float tangentIn = k1.tangentIn;
     return ((((internalValue * (((2f * num2) - (3f * num)) + 1f)) + (num5 * ((-2f * num2) + (3f * num)))) + (tangentOut * ((num2 - (2f * num)) + t))) + (tangentIn * (num2 -  num)));
}

Any information is much appreciated.

like image 960
Lawrence Kok Avatar asked Oct 24 '11 19:10

Lawrence Kok


People also ask

What is the difference between Hermite and Bezier curves?

A Bezier curve is specified by four control points; a Hermite curve is specified by two control points and two tangents. Actually, both of these curves are cubic polynomials. The only difference is that they are expressed with respect to different bases.

What are the limitation of Hermite curves?

Drawbacks: – Enumerating points on the curve is hard. – Extra constraints needed – half a circle? – Difficult to express and test tangents.

What is the curve degree of a Hermite curve?

A Hermite curve is a spline where every piece is a third degree polynomial defined in Hermite form: that is, by its values and initial derivatives at the end points of the equivalent domain interval.


1 Answers

I've never used XNA, but having glanced at the documentation it seems that the Curve class corresponds to a one-dimensional Bezier curve. The conversion formula you quote should work fine: the "coordinates" in a one dimensional Bezier curve are all scalars.

Hence it doesn't really make sense to try to plot a single XNA Curve as a two-dimensional Bezier curve. The Curve time value corresponds to the Bezier parameter t, not one of the spatial axes.

As it says in the Curve class documentation: "To represent a time path in two or three dimensions, you can define two or three Curve objects, each of which corresponds to a different spatial axis."

i.e. you need two Curve objects, one to provide the x value and one to provide the y value at a particular time.

like image 190
arx Avatar answered Nov 02 '22 23:11

arx