 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Paul Nicholls Guest
|
Posted: Fri Aug 08, 2008 8:58 am Post subject: Piece-wise curve demo (with source code) |
|
|
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 (AT) gmail (DOT) NOSPAM.com
Remove ".NOSPAM" to reply. |
|
| Back to top |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group .
|