DIRECTORY G3dBasic, G3dMatrix; G3dVector: CEDAR DEFINITIONS ~ BEGIN Box: TYPE ~ G3dBasic.Box; Pair: TYPE ~ G3dBasic.Pair; Triple: TYPE ~ G3dBasic.Triple; Quad: TYPE ~ G3dBasic.Quad; Ray: TYPE ~ G3dBasic.Ray; TripleSequence: TYPE ~ G3dBasic.TripleSequence; Matrix: TYPE ~ G3dMatrix.Matrix; NearSegment: TYPE ~ RECORD [ point: Triple ¬ [], -- point on 3d segment inside: BOOL ¬ FALSE, -- true iff point inside segment w0, w1: REAL ¬ 0.0 -- point = w0*p0+w1*p1 ]; origin: Triple ~ G3dBasic.origin; Null: PROC [v: Triple] RETURNS [BOOL]; Negate: PROC [v: Triple] RETURNS [Triple]; Unit: PROC [v: Triple] RETURNS [Triple]; Mul: PROC [v: Triple, s: REAL] RETURNS [Triple]; Div: PROC [v: Triple, s: REAL] RETURNS [Triple]; Abs: PROC [v: Triple] RETURNS [Triple]; Add: PROC [v1, v2: Triple] RETURNS [Triple]; Sub: PROC [v1, v2: Triple] RETURNS [Triple]; Equal: PROC [v1, v2: Triple, epsilon: REAL ¬ 0.001] RETURNS [BOOL]; Dot: PROC [v1, v2: Triple] RETURNS [REAL]; Cross: PROC [v1, v2: Triple] RETURNS [Triple]; Midpoint: PROC [v1, v2: Triple] RETURNS [Triple]; Interp: PROC [t: REAL, v1, v2: Triple] RETURNS [Triple]; InterpQuad: PROC [t: REAL, v1, v2: Quad] RETURNS [Quad]; Combine: PROC [v1: Triple, s1: REAL, v2: Triple, s2: REAL] RETURNS [Triple]; ScaleRay: PROC [ray: Ray, d: REAL] RETURNS [Triple]; MulVectors: PROC [v1, v2: Triple] RETURNS [Triple]; DivVectors: PROC [v1, v2: Triple] RETURNS [Triple]; UnitizeSequence: PROC [triples: TripleSequence]; NegateSequence: PROC [triples: TripleSequence]; MinMaxSequence: PROC [triples: TripleSequence] RETURNS [Box]; Length: PROC [v: Triple] RETURNS [REAL]; Square: PROC [v: Triple] RETURNS [REAL]; Distance: PROC [p1, p2: Triple] RETURNS [REAL]; SquareDistance: PROC [p1, p2: Triple] RETURNS [REAL]; SameLength: PROC [v1, v2: Triple] RETURNS [Triple]; SetVectorLength: PROC [v: Triple, length: REAL] RETURNS [Triple]; Collinear: PROC [p1, p2, p3: Triple, epsilon: REAL ¬ 0.01] RETURNS [BOOL]; VecsCoplanar: PROC [v1, v2, v3: Triple, epsilon: REAL ¬ 0.005] RETURNS [BOOL]; PointsCoplanar: PROC [p1, p2, p3, p4: Triple, epsilon: REAL ¬ 0.005] RETURNS [BOOL]; Parallel: PROC [v1, v2: Triple, epsilon: REAL ¬ 0.005] RETURNS [BOOL]; Perpendicular: PROC [v1, v2: Triple, epsilon: REAL ¬ 0.005] RETURNS [BOOL]; FrontFacing: PROC [vector, base: Triple, view: Matrix] RETURNS [BOOL]; FrontFacingNoPerspective: PROC [vector: Triple, view: Matrix] RETURNS [BOOL]; FrontFacingWithPerspective: PROC [vector, base: Triple, invView: Matrix] RETURNS [BOOL]; NearnessAccelerator: PROC [p0, p1: Triple] RETURNS [Quad]; NearestToSegment: PROC [p0, p1, q: Triple, acc: Quad ¬ [0, 0, 0, 0]] RETURNS [NearSegment]; NearestToLine: PROC [line: Ray, q: Triple] RETURNS [Triple]; PointOnLine: PROC [p: Triple, line: Ray, epsilon: REAL ¬ 0.005] RETURNS [BOOL]; NearestToSequence: PROC [p: Triple, points: TripleSequence] RETURNS [index: NAT]; DistanceBetween2Lines: PUBLIC PROC [line1, line2: Ray] RETURNS [REAL]; ClosestApproach2Lines: PROC [line1, line2: Ray] RETURNS [p1, p2: Triple]; V90: PROC [v0, v1: Triple, unitize: BOOL ¬ TRUE] RETURNS [Triple]; Ortho: PROC [v: Triple, crosser: Triple ¬ [0.0, 0.0, 1.0]] RETURNS [Triple]; RotateAbout: PROC [v, axis: Triple, a: REAL, degrees: BOOL ¬ TRUE] RETURNS [Triple]; PolarFromCartesian: PROC [cartesian: Triple] RETURNS [Triple]; CartesianFromPolar: PROC [polar: Triple] RETURNS [Triple]; Clip: PROC [p: Triple, box: Box] RETURNS [Triple]; Average: PUBLIC PROC [triples: TripleSequence] RETURNS [Triple]; Project: PROC [v1, v2: Triple] RETURNS [Triple]; CosineBetween: PROC [v0, v1: Triple, unitize: BOOL ¬ FALSE] RETURNS [REAL]; AngleBetween: PROC [v0, v1: Triple, degrees: BOOL ¬ TRUE, unitize: BOOL ¬ FALSE] RETURNS [REAL]; END. d G3dVector.mesa Copyright Σ 1984, 1992 by Xerox Corporation. All rights reserved. Bloomenthal, July 15, 1992 6:26 pm PDT Andrew Glassner February 14, 1991 9:02 am PST Type Declarations Basic Operations on a Single Vector Returns TRUE iff v is the origin. Vector negation: return -v. Vector normalization: return v/|v|. Vector scalar multiplication: return s*v. Vector scalar division: return v/s; division not performed if s = 0. Return the absolute values of v's components. Basic Operations on Two Vectors Vector additon: return v1+v2. Vector subtraction: return v1-v2. Returns TRUE iff v1 = v2, to within epsilon. Vector dot product: return v1.v2. Right handed vector cross product: v1Xv2. Return 0.5*(v1+v2). Return v1+t(v2-v1). Return v1+t(v2-v1). Return s1*v1+s2*v2. Return l.base+d*l.axis. Return v1*v2. Return v1/v2; component division not performed if v2 component = 0. Basic Operations on Sequence of Vectors Unitize the sequence of vectors. Negate the sequence of vectors. Return the bounding triples of the sequence. Length and Distance Operations Vector length: return SqRt[v.v] = |v|. Vector length squared: return |v||v| (same as Dot[v, v]). Distance between two points. Distance squared between two points. Return v2 adjusted to be same magnitude as v1. Return v adjusted to be of magnitude length. Directional Tests Return TRUE iff the three points are colinear, to within epsilon. Return TRUE iff the three vectors are coplanar. Return TRUE iff the four points are coplanar, ie., all within epsilon distance of a plane. Return TRUE iff the two vectors are parallel, to within epsilon. Return TRUE iff the two vectors are perpendicular, to within epsilon. Return TRUE iff the transformed vector is front-facing (the z component < 0). This is useful for culling back-facing polygons; view may or may not contain perspective. Return TRUE iff the transformed vector is front-facing (the z component < 0). This is useful for culling back-facing polygons if the view does not contain perspective. Transform world space plane to view space and test z component of normal: invView is the INVERSE of the actual world-to-view matrix. Return TRUE iff the transformed vector is front-facing (the z component < 0). This is useful for culling back-facing polygons if the view does contain perspective. Nearness Operations Return the 3d accelerator for computing nearest point on the p0-p1 segment. Return the triple on line segment p0p1 nearest to q. If acc # [0, 0, 0, 0], the calculation of NearSegment is accelerated. Return point closest to q on line. Return TRUE iff p is within epsilon of the line. Return index such that points[index] is nearest to p. Return the distance of the closest approach of two lines. Return a point on line1 and a point on line2 that are the closest approaches of the two lines. Presumes line1.axis and line2.axis are unitized. Results are undefined if line1 and line2 are parallel. Simple Geometric Operations Return vector orthogonal to v0 and in plane of v0 and v1; v0 and v1 presumed unitized. Return a vector orthonormal to both v and crosser and of the same magnitude as v; if v = crosser, an arbitrary crosser is chosen. Return v rotated around axis by a. Polar/Cartesian Coordinates Return the polar equivalent of the input cartesian vector. The returned triple's x, y, and z fields correspond to longitude, lattitude, and magnitude. The input triple's x, y, and z fields correspond to longitude, lattitude, and magnitude. Return the cartesian equivalent of the input polar vector. Longitude and lattitude are in degrees. Miscellany Return a point clipped to box. Return the average of the TripleSequence. Return the vector projection of v1 onto v2. Return the cosine of the angle between the two vectors. Iff unitize, do so to v0 and v1. Return the angle (in degrees if degrees TRUE, else in radians) between the two vectors. Iff unitize, do so to v0 and v1. Κ²–"cedarcode" style•NewlineDelimiter ™™Jšœ Οeœ6™BJ™&J™-J˜JšΟk œ˜J˜—JšΠbl œžœž ˜Jšœž˜headšΟl™Jšœžœ˜Jšœ žœ˜Jšœ žœ˜!Jšœ žœ˜Jšœžœ˜Jšœžœ˜/šœ žœ˜"J˜—šœžœžœ˜JšœΟc˜4Jšœžœžœ‘ ˜>Jšœžœ ‘˜2J˜J˜—J˜#—š #™#šΟnœžœ žœžœ˜&Jšœžœ™!J˜—š’œžœ žœ ˜*J™J˜—š’œžœ ž œ ˜(J™#J˜—š’œžœžœžœ ˜0J™)J™—š’œžœžœžœ ˜0J™DJ™—š’œžœ žœ ˜'J™-——š ™š’œžœžœ ˜,J™J˜—š’œžœžœ ˜,J™!J˜—š ’œžœžœ žœžœ˜CJšœžœ ™,J˜—š’œžœžœžœ˜*JšœΟuœ™!J˜—š’œžœžœ ˜.Jšœ%Οmœ™)J˜—šΠbnœžœž œ ˜1J™J™—š’œžœžœžœ ˜8J™J™—š’ œžœžœžœ˜8J™J™—š ₯œžœžœžœž œ ˜LJ™J™—š₯œžœžœžœ ˜4J™J™—š’ œžœžœ ˜3J™ J™—š’ œžœžœ ˜3J™C——š '™'š’œžœ˜0J™ J˜—š’œžœ˜/J™J™—š’œžœžœ˜=J™,——š ™š’œžœ žœžœ˜(Jšœ£œ ™&J˜—š’œžœ žœžœ˜(J™9J˜—š’œžœžœžœ˜/J™J˜—š’œžœžœžœ˜5J™$J™—š’ œžœžœ ˜3J™.J™—š’œžœžœžœ ˜AJ™,——š ™š ’ œžœžœ žœžœ˜JJšœžœ6™AJ˜—š ’ œžœžœ žœžœ˜NJšœžœ$™/J˜—š ’œžœ#žœ žœžœ˜TJšœžœO™ZJ™—š ’œžœžœ žœžœ˜Fšœžœ5™@J˜——š ’ œžœžœ žœžœ˜KJšœžœ:™EJ™—š’ œžœ&žœžœ˜FJšœΟsœB™MJ™YJ™—š’œžœ žœžœ˜MJšœ¦œB™MJ™YJ™—š’œžœ)žœžœ˜XJ™IJšœΟbœ$™:Jšœ¦œB™MJ™U——š ™š’œžœžœ˜:J™KJ™—š’œžœ.žœ˜[J™4J™EJ™—š’ œžœžœ ˜J™:J™[J™—š’œžœžœ ˜:J™XJ™:J™'——š  ™ š’œžœžœ ˜2J™J™—š’œžœžœžœ ˜@J™)J™—š’œžœžœ ˜1J™+J™—š ’ œžœžœžœžœžœ˜KJšœY™YJ™—š ’ œžœžœžœ žœžœ˜PJšžœžœ˜Jšœ(¦œ+™WJšœ ™ —J™—Jšžœ˜—…—Ί%Π