Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw splines by using Direct2D

I have the data of a spline curve

  • Degree
  • Knots
  • Control points
  • Fit points

And I need to draw this curve by using Direct2D. At the moment I am using the ID2D1GeometrySink interface to draw geometries but it seems it does not implements a possible AddSpline method.

Is there a way to draw spline by means of Direct2D? Even a DirectX implementation that can be used in a Direct2D application will be fine.

like image 339
Nick Avatar asked Jul 07 '15 13:07

Nick


1 Answers

Direct2D, more clear ID2D1GeometrySink, doesn't support splines, but cubic bezier curves which can be put together to a spline. In the opposite, you can gain b-curves out of your spline data and just add them to your geometry.

The algorithm is simply explained by this picture: curve substitution.

An article for short and well explanation can be found here. You can split your spline until control points overlap and the degree can be lowered, even until all curves are flat enough to be lines. Last thing isn't a bad idea because your hardware doesn't know curves, so your passed curves get converted to lines later anyway. When you do this conversion, you can determine the tolerance for flatness and avoid ugly edges.

like image 71
Youka Avatar answered Oct 11 '22 08:10

Youka