简体   繁体   中英

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

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.

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."

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM