Routines whose names end in
3
operate on vectors or ordinary points in affine 3-space, represented by their Euclidean
(x,y,z)
coordinates.
(They assume
w=1
in their arguments, and set
w=1
in their results.)
Name
Description
add3
Add the coordinates of two points.
sub3
Subtract coordinates of two points.
mul3
Multiply coordinates by a scalar.
div3
Divide coordinates by a scalar.
eqpt3
Test two points for exact equality.
closept3
Is the distance between two points smaller than
eps?
dot3
Dot product.
cross3
Cross product.
len3
Distance to the origin.
dist3
Distance between two points.
unit3
A unit vector parallel to
p.
midpt3
The midpoint of line segment
pq.
lerp3
Linear interpolation between
p
and
q.
reflect3
The reflection of point
p
in the segment joining
p0
and
p1.
nearseg3
The closest point to
testp
on segment
p0 p1.
pldist3
The distance from
p
to segment
p0 p1.
vdiv3
Vector divide the length of the component of
a
parallel to
b,
in units of the length of
b.
vrem3
Vector remainder the component of
a
perpendicular to
b.
Ignoring roundoff, we have
eqpt3(add3(mul3(b, vdiv3(a, b)), vrem3(a, b)), a).
The following routines convert amongst various representations of points
and planes. Planes are represented identically to points, by duality;
a point
p
is on a plane
q
whenever
p.x*q.x+p.y*q.y+p.z*q.z+p.w*q.w=0.
Although when dealing with affine points we assume
p.w=1,
we can't make the same assumption for planes.
The names of these routines are extra-cryptic. They contain an
f
(for `face') to indicate a plane,
p
for a point and
n
for a normal vector.
The number
2
abbreviates the word `to.'
The number
3
reminds us, as before, that we're dealing with affine points.
Thus
pn2f3
takes a point and a normal vector and returns the corresponding plane.
Name
Description
pn2f3
Compute the plane passing through
p
with normal
n.
ppp2f3
Compute the plane passing through three points.
fff2p3
Compute the intersection point of three planes.
The names of the following routines end in
4
because they operate on points in projective 4-space,
represented by their homogeneous coordinates.
pdiv4
Perspective division. Divide
p.w
into
p's
coordinates, converting to affine coordinates.
If
p.w
is zero, the result is the same as the argument.