Thread View: borland.public.delphi.graphics
1 messages
1 total messages
Started by Paul Nicholls
Fri, 08 Aug 2008 03:58
Piece-wise curve demo (with source code)
Author: Paul Nicholls
Date: Fri, 08 Aug 2008 03:58
Date: Fri, 08 Aug 2008 03:58
92 lines
3517 bytes
3517 bytes
Hi all,
I have put a post into the attachements group called "Piece-wise curve
demo (with source code)"
This is a program I coded that shows how you can create one of 3 piece-wise
curve types defined by 3d points in space.
The curve types are:
1. cubic bezier (see the 'TPieceWiseCurve_CubicBezier' and
'TCurve_CubicBezier' classes in 'cubic_bezier.pas')
2. Catmull-Rom (see the 'TPieceWiseCurve_CatmullRom' and
'TCurve_CatmullRom' classes in 'catmull_rom.pas')
3. Hermite (see the 'TPieceWise_Curve_Hermite' and
'TCurve_Hermite' classes in 'hermite.pas')
The piece-wise curve can be closed or open.
Each curve type is desended from the base TPieceWiseCurve and TCurve classes
(see 'piecewise_curves.pas')
How to use:
Step1:
Create the type of piece-wise class you want.
PieceWiseCurve := TPieceWiseCurve_CubicBezier.Create;
step 2:
Add points:
PieceWiseCurve.CurveIsClosed := CheckBox_CurveIsClosed.Checked;
PieceWiseCurve.ClearAll;
For i := 0 To High(Points) Do
PieceWiseCurve.AddPoint(Points[i].x,Points[i].y,Points[i].z);
PieceWiseCurve.UpdateFromPoints;
step 3:
call the Interpolate() method :
PieceWiseCurve.Interpolate(OnPointRoutine,OnLineRoutine,SpinEdit_MaxLineLength.Value);
This will interpolate the curves between each point defining the path and
recursively split them up into lines no longer than the MaxLineLength
parameter in the Interpolate() method.
In the OnPointRoutine and OnLineRoutines you can do whatever with the
points/lines - you could build a path by joning the curve segments together
for example.
Enjoy the code - use it for whatever you want.
PS. If anyone improves the curves code, can you please email me a better
copy?
Thanks to:
http://www.cubic.org/docs/hermite.htm
http://local.wasp.uwa.edu.au/~pbourke/other/interpolation/
http://local.wasp.uwa.edu.au/~pbourke/surfaces_curves/bezier/cubicbezier.html
PS: I fixed a bug in the TPieceWiseCurve class:
Replace the AddPoint() method with this one:
Procedure TPieceWiseCurve.AddPoint(Const x,y,z : Single);
Var
i : Integer;
Begin
i := Length(FPoints);
SetLength(FPoints ,i + 1);
FPoints[i].x := x;
FPoints[i].y := y;
FPoints[i].z := z;
End;
I was setting the z coordinate internally as 0 and ignoring the passed
value.
This was a throwback from when I was starting with only 2d curves.
Cheers,
Paul.
"The plastic veneer of civilization is easily melted in the heat of the
moment" - Paul Nicholls.
paulfnicholls@gmail.NOSPAM.com
Remove ".NOSPAM" to reply.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads