cart: empty [ Login ]

Cardinal Spline

1 
joe
10/19/2006 2:49 PM
I want to export a CARDINAL spline (same as used by gdi - drawcurve method) to dxf. A bezier spline wouldn't be the right thing for me, because I have a given set of (control-) points which should be exactly located on the spline to export - and not been approximated... How to do that? grateful for any help...
Wout
10/19/2006 5:21 PM
Hi Joe, You'll have to do some math to turn them into cubic splines (use DxfSpline). Each piece of curve between 2 points of a cardinal spline is defined by those 2 points, and the tangets are defined by the neighbouring 2 points (the tension defines how far away the tangent points are put). So you can construct cubics of 4 points each and let them connect to eachother. You can merge those separate cubic splines into a single cubic spline by specifying the knots in the appropriate way (00003333 for a single cubic, 000033336666 for 2 connected cubics etc. Note that for a 2 piece cubic spline the second point is repeated, see the example I wrote below). Thanks! Wout Here's an example of a cardinal spline going through points p0, p1 and p2:
C# Code:
DxfSpline spline1 = new DxfSpline(); spline1.Degree = 3; spline1.Closed = false; spline1.Color = Color.Yellow; Point3D p0 = new Point3D(0, 0, 0); Point3D p1 = new Point3D(0, 1d, 0); Point3D p2 = new Point3D(1d, 1d, 0); double tension = 0d; double t = 0.5d * (1d - tension); spline1.ControlPoints.AddRange(   new Point3D[] {     p0,     p0 + t * (p1 - p0),     p1 - t * (p2 - p0),     p1,     p1,     p1 + t * (p2 - p0),     p2 - t * (p2 - p1),     p2   } ); spline1.Knots.AddRange(new double[] { 0d, 0d, 0d, 0, 3d, 3d, 3d, 3d, 6d, 6d, 6d, 6d });
joe
10/19/2006 8:46 PM
first of all thank you very much for your fast reply, wout! may I ask you some things that are not yet clear for me by commenting your code snippets?
C# Code:
spline1.ControlPoints.AddRange(   new Point3D[] {     p0,     p0 + t * (p1 - p0),     p1 - t * (p2 - p0),     p1,     p1,     p1 + t * (p2 - p0),     p2 - t * (p2 - p1),     p2   } );
when I calculate these control points by hand and draw the calculated points it isn't comprehensible for me how you come to this solution because the control points are not resulting in a curve... I understand that you want to add two 'virtual' points between each two points of my 'outline-curve-points' to get a four point cubic spline. afterwards we want to merge these 4 point cubic splines. am I right? the (p1 - p0) vector of the second control point is the direction of the first tangente as well the (p2 - p0) vector is the direction of the second tangente. correct? the first 4 control points are my first 4 point cubic spline.
C# Code:
spline1.Knots.AddRange(new double[] { 0d, 0d, 0d, 0, 3d, 3d, 3d, 3d, 6d, 6d, 6d, 6d });
what I actually do not understand at all is how you calculate the values of the knot array. how would it look like if there are 4 'outline-curve-points'? could you describe very shortly what is meant by these values?
Wout
10/19/2006 9:17 PM
Hi, It goes a bit too far to explain all of spline theory, it's goes pretty deep, but point 0, 3/4 and 7 are the points where the spline will go through. Hmm, on second thought it seems I made a mistake: I don't think the 2 splines can be merged the way I did. In stead just create 2 splines in this case, each of 4 points. And the knot vector will just be 00003333 for each. Sorry for the confusion! Wout
1