graphicsvector

Convert quadratic curve to cubic curve


Looking at Convert a quadratic bezier to a cubic?, I can finally understand why programming teachers always told me that math was so important. Sadly, I didn't listen.

Can anyone provide a more concrete - e.g., computer-language-y - formula for converting a quadratic curve to a cubic? Understanding that there's some rounding errors possible, which is fine.

Given a quad curve represented by variables:

StartX, StartY
ControlX, ControlY
EndX, EndY

And desiring StartX, StartY and EndX, EndY to remain the same, but to now have Control1X, Control1Y and Control2X, Control2Y of a cubic curve.

Is it...

Control1X = StartX + (.66 * (ControlX - StartX))
Control2X = EndX + (.66 * (ControlX - EndX))

With the same essential functions used to calculate Control1Y and Control2Y?


Solution

  • Your code is right except that you should use 2.0/3.0 instead of 0.66.