How to convert from a germite curve to a Bezier curve?

As stated in this section: How to convert from a Hermite curve to a Bezier curve? In particular, I'm looking for a way to convert the Curve class that uses Hermite interpolation, the Microsoft XNA Framework, which will be drawn using StreamGeometry or PathGeometry for the Windows Presentation Foundation.

I came 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] 

This simplifies:

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

Even with this information, I'm mostly fixated on calculating breakpoints. The problem is that the Curve class provides TangentIn and TangentOut as a scalar. Given that the polynomial is drawn in two-dimensional space (time, value), this scalar must be converted to a two-dimensional vector in order to apply it to this formula. However, I’m not sure what steps are involved with this conversion process, but I suspect that I need to apply the Hermite differentiation equation.

If this helps, this is the code used to evaluate the curve at the moment, found using 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 greatly appreciated.

+6
source share
1 answer

I have never used XNA, but looking at the documentation, it seems that the Curve class corresponds to a one-dimensional Bezier curve. The transformation formula that you are quoting should work fine: the "coordinates" in the one-dimensional Bezier curve are all scalars.

Therefore, there really is no point in trying to construct one XNA curve as a two-dimensional Bezier curve. The value of the curve time corresponds to the Bezier parameter t, and not to one of the spatial axes.

As the Curve class documentation says: "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 value of x and one to provide the value of y at a specific time.

+3
source

Source: https://habr.com/ru/post/899988/


All Articles