A Point3.T
is a point in 3-space. It is represented as a record
with three components, x
, y
, and z
, all holding real values.
INTERFACEPoint3 ; TYPE T = RECORD x,y,z : REAL; END; CONST Origin = T {0.0, 0.0, 0.0}; Min = T {FIRST(REAL), FIRST(REAL), FIRST(REAL)}; Max = T {LAST (REAL), LAST (REAL), LAST (REAL)};
Origin
is the origin of the coordinate system.Min
andMax
are used in bounding box calculations to represent imaginary smallest and largest points.
PROCEDURE Plus (a, b : T) : T;
Plus(a,b)
returns the sum of the pointsa
andb
.
PROCEDURE Minus (a, b : T) : T;
Minus(a,b)
returns the difference betweena
andb
.
PROCEDURE TimesScalar (a : T; x : REAL) : T;
TimesScalar(a,s)
returnsa
with each component multiplied with the scalar values
.
PROCEDURE MidPoint (a, b : T) : T;
MidPoint(a,b)
returns the point in the middle betweena
andb
.
PROCEDURE Distance (a, b : T) : REAL;
Distance(a,b)
returns the distance betweena
andb
.
PROCEDURE ToText (a : T) : TEXT;
ToText(a)
returns a textual representation ofa
; for example,ToText(T{2.0,3.0,5.0})
returns the text(2.0,3.0,5.0)
.
The remaining operations interpret their arguments as vectors, not as points. The vector
a
is the vector going from the origin to point a
.
PROCEDURE Length (a : T) : REAL;
Length(a)
returns the length of the vectora
.
PROCEDURE DotProduct (a, b : T) : REAL;
Returns the dot product ofa
andb
. See [Foley] p. 1094ff for an explanation of the geometric significance of dot products.
PROCEDURE CrossProduct (a, b : T) : T;
Returns the cross product ofa
andb
. See [Foley] p. 1104ff for an explanation of the geometric significance of cross products. One important property is that $a \times b$ is orthogonal to the plane described by the vectorsa
andb
.
PROCEDURE OrthoVector (a : T) : T;
Returns a unit vector which is orthogonal ton
. There are infinitely many such vectors,OrthoVector
will return one of them.
PROCEDURE ScaleToLen (a : T; len : REAL) : T;
Returns a vector parallel toa
with lengthlen
.
END Point3.