gradientspace / geometry3Sharp

C# library for 2D/3D geometric computation, mesh algorithms, and so on. Boost license.
http://www.gradientspace.com
Boost Software License 1.0
1.68k stars 378 forks source link

Quadratic Bezier Curves #203

Open MaxDeVos opened 2 months ago

MaxDeVos commented 2 months ago

Disclaimer: I feel as though I am missing something fundamental here, that some existing component already serves this purpose and I don't know it.

Is there a reason that quadratic Bezier curves are not explicitly supported by this library? The BezierCurve2 class explicitly excludes them, likely due to not having a valid result for GetThirdDerivative(double t). I see three potential solutions to this:

1) BezierCurve2 is modified to automatically convert quadratic bezier curves to cubic ones by calculating control point 1, which can be done as follows:

\begin{align*}
C_0 &= Q_0 \\
C_1 &= Q_0 + \frac{2}{3}(Q_1-Q_0) \\
C_2 &= Q_2 + \frac{2}{3}(Q_1-Q_2) \\
C_3 &= Q_2
\end{align*}

2) QuadraticBezierCurve2 is added and its implementation of GetThirdDerivative(t) always returns double.NaN. 3) BezierCurve2 is modified to natively support quadratic bezier curves, but the boolean property isQuadratic is added, and GetThirdDerivative(t) returns double.NaN when the curve is quadratic.

rms80 commented 2 months ago

The curve classes were added to support various projects I was working on at different times, and I guess I didn't have a need for quadratic Bezier curves. So that's why it's not supported. Your solutions seem plausible but I am not going to implement them, feel free to submit a PR.