Polygons3d.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, February 26, 1987 7:27:19 pm PST
DIRECTORY Matrix3d, ThreeDBasics, Vector3d;
Polygons3d: CEDAR DEFINITIONS
~ BEGIN
Type Declarations
origin:     Triple ~ Vector3d.origin;
xAxis:      Triple ~ Vector3d.xAxis;
yAxis:     Triple ~ Vector3d.yAxis;
zAxis:      Triple ~ Vector3d.zAxis;
Pair:      TYPE ~ Vector3d.Pair;
PairSequence:   TYPE ~ Vector3d.PairSequence;
PairSequenceRep:  TYPE ~ Vector3d.PairSequenceRep;
Triple:     TYPE ~ Vector3d.Triple;
TripleSequence:   TYPE ~ Vector3d.TripleSequence;
TripleSequenceRep:  TYPE ~ Vector3d.TripleSequenceRep;
Matrix:     TYPE ~ Matrix3d.Matrix;
NatTable:     TYPE ~ ThreeDBasics.NatTable;
NatSequence:    TYPE ~ ThreeDBasics.NatSequence;
Triangle:     TYPE ~ RECORD [i0, i1, i2: INTEGER ← -1];
TriangleSequence:  TYPE ~ REF TriangleSequenceRep;
TriangleSequenceRep: TYPE ~ RECORD [
         length: NAT ← 0,
         element: SEQUENCE maxLength: NAT OF Triangle
         ];
MinMaxPairs:   TYPE ~ RECORD [min, max: Pair];
MinMaxTriples:   TYPE ~ RECORD [min, max: Triple];
Normal Procedures
TriangleNormal: PUBLIC PROC [p0, p1, p2: Triple] RETURNS [Triple];
Return the unit-length normal for three vertices, p0, p1, and p2.
The normal will face the viewer if the vertices appear in clockwise order.
PolygonNormal: PUBLIC PROC [vertices: TripleSequence] RETURNS [Triple];
Return the normal for these vertices using Newell's technique (A Characterization of Ten
Hidden-Surface Algorithms, ACM Computing Surveys, March, 1974) to minimize non-
planarity distortion. The normal will face the viewer if the vertices appear in clockwise
order. The normal's length is proportional to the area of the polygon.
PolygonNormals: PUBLIC PROC [
polygons: REF NatTable,
vertices: TripleSequence,
normals: TripleSequence ← NIL]
RETURNS [TripleSequence];
Return a sequence of polygon normals (one per polygon); store in normals if non-nil.
ApplyToFrontFacingPolygons: PUBLIC PROC [
proc: PROC[nPoly: NAT],
polygons: REF NatTable,
pairs: PairSequence,
view: Matrix,
normals: TripleSequence];
Apply the given proc to all front-facing polygons.
Miscellaneous Procedures
CopyPolygon: PUBLIC PROC [poly: REF NatSequence] RETURNS [copy: REF NatSequence];
Return a copy of the input sequence.
ReversePolygon: PUBLIC PROC [poly: REF NatSequence] RETURNS [REF NatSequence];
Reverse the order of the sequence elements.
CenterOfPolygon: PUBLIC PROC [poly: REF NatSequence, points: TripleSequence]
RETURNS [Triple];
Return the simple average (center) of the polygon vertices.
CentersOfPolygons: PUBLIC PROC [
polygons: REF NatTable,
points: TripleSequence,
centers: TripleSequence ← NIL]
RETURNS [TripleSequence];
Return the simple centers of the polygons, using centers if non-NIL.
ProjectToXYPlane: PUBLIC PROC [
poly: REF NatSequence, points: TripleSequence, o, x, y: Triple]
RETURNS [pairs: PairSequence];
Return a sequence of pairs projected onto the xy plane.
The origin of the plane is o, its x-axis is x and its y-axis is y.
GetMinMaxPairs: PUBLIC PROC [pairs: PairSequence] RETURNS [mm: MinMaxPairs];
Return the minmax bounding box for this sequence of pairs.
GetMinMaxTriples: PUBLIC PROC [triples: TripleSequence] RETURNS [mm: MinMaxTriples];
Return the minmax bounding box for this sequence of triples.
SquarePairDistance: PUBLIC PROC [p0, p1: Pair] RETURNS [REAL];
Return the square of the distance between two pairs.
SquareTripleDistance: PUBLIC PROC [p0, p1: Triple] RETURNS [REAL];
Return the square of the distance between two triples.
Triangle Procedures
LengthenTriangleSequence: PUBLIC PROC [t: TriangleSequence]
RETURNS [TriangleSequence];
Return a copy of the input sequence but with greater maxLength.
Triangulate2Polygons: PUBLIC PROC [
poly0, poly1: REF NatSequence, points: TripleSequence]
RETURNS [TriangleSequence];
Triangulate between two presumably planar polygons; the technique is similar to that of
Christiansen and Sederberg (Conversion of Complex Contour Line Definitions into Polygonal
Element Mosaics, Siggraph, 1978) in which each polygon is mapped to a unit square to
facilitate the vertex matching.
END.