G3dCurve.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, October 21, 1992 4:59 pm PDT
DIRECTORY G3dBasic, G3dMatrix, G3dSpline, IO, Rope;
G3dCurve:
CEDAR
DEFINITIONS
~ BEGIN
Notes
A curve is a sequence of three-dimensional cubic splines such that the last point of one spline is the first point of the next spline. A curve returned by G3dSpline.Interpolate or InterpolateCyclic will feature C2 continuity at each of the spline endpoints. This interface features procedures for the evaluation of a curve given an arc-length or parametric value along the curve. Each curve segment is presumed to be defined parametrically on [0..1].
Errors
Error: SIGNAL [code: ATOM, reason: ROPE ¬ NIL]; -- able to resume this error
Imported Types
Triple: TYPE ~ G3dBasic.Triple;
RealSequence: TYPE ~ G3dBasic.RealSequence;
Matrix: TYPE ~ G3dMatrix.Matrix;
Spline: TYPE ~ G3dSpline.Spline;
SplineSequence: TYPE ~ G3dSpline.SplineSequence;
STREAM: TYPE ~ IO.STREAM;
ROPE: TYPE ~ Rope.ROPE;
Curve Definitions
Curve: TYPE ~ REF CurveRep;
CurveRep:
TYPE ~
RECORD [
length: CARDINAL ¬ 0,
totalLength: REAL ¬ 0.0,
element: SEQUENCE maxLength: CARDINAL OF Section
];
Section:
TYPE ~
RECORD [
spline: Spline ¬ NIL, -- cubic coefficients of this section
accumLength: REAL ¬ 0.0, -- total length of curve up to this section
length: REAL ¬ 0.0, -- approximate length of this section
fragments: Fragments ¬ NIL -- res number of pieces of this section
];
Fragment:
TYPE ~
RECORD [
t0: REAL ¬ 0.0, -- parametric start of this fragment
t1: REAL ¬ 0.0, -- parametric end of this fragment
dt: REAL ¬ 0.0, -- parametric difference
length: REAL ¬ 0.0, -- approximate length of this fragment
accumLength: REAL ¬ 0.0]; -- total length of curve up to this fragment
Fragments: TYPE ~ REF FragmentsRep;
FragmentsRep:
TYPE ~
RECORD [s:
SEQUENCE length:
CARDINAL
OF Fragment];
Spot:
TYPE ~
RECORD [
spline: Spline ¬ NIL, -- a cubic spline section
t: REAL ¬ 0.0 -- parametric position within spline
];
CurveSequence: TYPE ~ REF CurveSequenceRep;
CurveSequenceRep:
TYPE ~
RECORD [
length: CARDINAL ¬ 0,
element: SEQUENCE maxLength: CARDINAL OF Curve
];
Creation
CurveFromSplines:
PROC [splines: SplineSequence, res:
NAT ¬ 100]
RETURNS [Curve];
Allocate the curve and compute the lengths needed for subsequent arc-length evaluation.
The number of lengths is determined by res.
Tranformation
Transform:
PROC [curve: Curve, matrix: Matrix];
Transform the spline segments by matrix.
Conversion Between Parametric and Arc-length Values
SpotFromT:
PROC [c: Curve, t:
REAL]
RETURNS [Spot];
Return the section and parametric position at t of the curve.
SpotFromArcLength:
PROC [c: Curve, arcLength:
REAL]
RETURNS [Spot];
Return the section and parametric position at arcLength along the curve.
ArcLengthFromT:
PROC [c: Curve, t:
REAL]
RETURNS [
REAL];
Return the (approximate) arcLength along the curve from 0 to t.
ArcLengthFromTs:
PROC [c: Curve, t0, t1:
REAL]
RETURNS [
REAL];
Return the (approximate) arcLength along the curve from t0 to t1.
Evaluation Given Parameter t
These procedures are comparable to those in G3dSpline, except that t IN [0..1] corresponds to the first spline segment of the curve, t IN [1..2] corresponds to the second spline segment in the curve, etc.
t not IN [0..curve.length] raises ERROR[$BadT].
PositionT:
PROC [c: Curve, t:
REAL]
RETURNS [Triple];
Return the point of the curve at position t.
VelocityT:
PROC [c: Curve, t:
REAL]
RETURNS [Triple];
Return the unnormalized tangent of the curve at position t.
AccelerationT:
PROC [c: Curve, t:
REAL]
RETURNS [Triple];
Return the unnormalized acceleration of the curve at position t.
CurvatureT:
PROC [c: Curve, t:
REAL]
RETURNS [Triple];
Return the unnormalized curvature vector of the curve at position t.
CurvatureMagT:
PROC [c: Curve, t:
REAL]
RETURNS [
REAL];
Return the magnitude of the curvature vector at position t.
Evaluation Given Arc Length
These procedures are comparable to those in G3dSpline, except that arc length specifies location on the curve. Since no analytic measure for arc-length exists (except for the uncommon arc-length parameterized curve), the results of these procedures are necessarily approximate, and depend upon the res argument given to CurveFromSplines.
arcLength not IN [0..curve.length] raises ERROR[$BadArcLength].
PositionA:
PROC [c: Curve, arcLength:
REAL]
RETURNS [Triple];
Return the point of the curve at arc-length.
VelocityA:
PROC [c: Curve, arcLength:
REAL]
RETURNS [Triple];
Return the unnormalized tangent of the curve at arc-length.
AccelerationA:
PROC [c: Curve, arcLength:
REAL]
RETURNS [Triple];
Return the unnormalized acceleration of the curve at arc-length.
CurvatureA:
PROC [c: Curve, arcLength:
REAL]
RETURNS [Triple];
Return the unnormalized curvature vector of the curve at arc-length.
CurvatureMagA:
PROC [c: Curve, arcLength:
REAL]
RETURNS [
REAL];
Return the magnitude of the curvature vector at arc-length.
IO
Write:
PROC [out:
STREAM, c: Curve, name:
ROPE ¬
NIL];
Write the header "Curve: <n> splines:" to the output stream, followed by each spline in c.
If name # NIL then insert it in the header after "Curve"
Read:
PROC [in:
STREAM]
RETURNS [Curve];
Read the curve from the input stream.
The input stream should be positioned at the beginning of the curve header.
Can raise Error[$BadInputFormat].
Sequences
CopyCurveSequence:
PUBLIC
PROC [curves: CurveSequence]
RETURNS [CurveSequence];
Return a copy of the input sequence of curves.
AddToCurveSequence:
PUBLIC
PROC [curves: CurveSequence, curve: Curve]
RETURNS [CurveSequence];
Add curve to the sequence.
LengthenCurveSequence:
PUBLIC
PROC [curves: CurveSequence, amount:
REAL ¬ 1.3]
RETURNS [new: CurveSequence];
Return a copy of the input sequence whose maxLength is amount*input.maxLength.
END.