INTERFACE PZGeo; (* Miscellaneous geometry tools *) (* Last edited on 1999-08-06 22:03:36 by hcgl *) IMPORT LR3, LR4x4; FROM PZTypes IMPORT LONG; TYPE Point = LR3.T; PROCEDURE LinearInterpolate( t: LONG; a: LONG; READONLY pa: Point; b: LONG; READONLY pb: Point; ): Point; (* Interpolates linearly the position at time "t" between points "pa" and "b", assuming they have times "a" and "b". *) PROCEDURE HermiteInterpolate( t: LONG; a: LONG; READONLY pa: Point; READONLY va: Point; b: LONG; READONLY pb: Point; READONLY vb: Point; VAR p: Point; VAR v: Point; ); (* Performs cubic Hermite interpolation for argument "t" given positions "pa" and "pb" and velocities "va" and "vb" at times "a" and "b". Best used for "t" between "a" and "b". *) PROCEDURE EstimateVelocityQ( a: LONG; READONLY pa: Point; b: LONG; READONLY pb: Point; c: LONG; READONLY pc: Point; ): Point; PROCEDURE EstimateVelocityL( a: LONG; READONLY pa: Point; b: LONG; READONLY pb: Point; c: LONG; READONLY pc: Point; ): Point; PROCEDURE EstimateVelocityC( a: LONG; READONLY pa: Point; b: LONG; READONLY pb: Point; c: LONG; READONLY pc: Point; ): Point; (* These procedures return estimates of a curve's velocity at time "b", given its positions "pa", "pb", "pc" at three successive times "a", "b", "c". EstimateVelocityQ uses quadratic interpolation. It is precise for quadratic functions but is unstable when "b" is near "a" or "c". EstimateVelocityL uses linear interpolation between "(a,pa)" and "(c,pc)". It ignores "b" and "pb". It is therefore robust for uneven intervals, but is not precise for quadratics. EstimateVelocityC uses a formula that degenerates to linear interpolation between "(a,pa)" and "(b,pb)" when "b" is close to "c", and to linear interpolation between "(b,pb)" and "(c,pc)" when "b" is close to "a". It thus gives an "unconstrained derivative" effect at double nodes, which is useful for modeling. It is more robust than EstimateVelocityQ, but is not precise for quadratics. *) PROCEDURE HermiteCurveLength( a: LONG; READONLY pa: Point; READONLY va: Point; b: LONG; READONLY pb: Point; READONLY vb: Point; ): LONG; (* Computes the approximate length between "pa" and "pb" of the cubic curve that interpolates "(a,pa)" and "(b,pb)", with velocities "va", "vb" at those points. *) PROCEDURE BSplineApproximation( t: LONG; a: LONG; b: LONG; READONLY Pabc: Point; c: LONG; READONLY Pbcd: Point; d: LONG; READONLY Pcde: Point; e: LONG; READONLY Pdef: Point; f: LONG; ): Point; (* Computes the position at time "t" of a cubic B-Spline curve with control points "Pabc", "Pbcd", "Pcde", "Pdef", and knot sequence "a",... "f". Assumes "t" lies between "c" and "d". *) PROCEDURE AvgSegDist(READONLY a1, a2, b1, b2: Point): LONG; (* A segment distance function. The result is the root mean square distance between "a(t)" and "b(t)", which travel along the segments "a1--a2" and "b1--b2" at constant speed. *) PROCEDURE AvgSegDistSqr(READONLY a1, a2, b1, b2: Point): LONG; (* The square of "AvgSegDist", only faster. *) PROCEDURE Translation(READONLY p: Point): LR4x4.T; (* Builds a translation matrix that takes the origin of R^3 to point "p" (in Cartesian coordinates). *) PROCEDURE Rotation(READONLY u, v: Point): LR4x4.T; (* Builds a rotation matrix that takes the vector "u" to the vector "v" by the shortest route. *) PROCEDURE SegDir(READONLY p, q : Point): Point; (* Direction from "p" to "q". *) PROCEDURE SegMid(READONLY p, q: Point): Point; (* Midpoint of segment from "p" to "q". *) END PZGeo. (* Copyright © 2001 Universidade Estadual de Campinas (UNICAMP). Authors: Helena C. G. Leitão and Jorge Stolfi. This file can be freely distributed, used, and modified, provided that this copyright and authorship notice is preserved, and that any modified versions are clearly marked as such. This software has NO WARRANTY of correctness or applicability for any purpose. Neither the authors nor their employers chall be held responsible for any losses or damages that may result from its use. *)