Types
Box: TYPE ~ G2dBasic.Box;
NatPair: TYPE ~ G2dBasic.NatPair;
NearSegment: TYPE ~ G2dBasic.NearSegment;
Pair: TYPE ~ G2dBasic.Pair;
PairSequence: TYPE ~ G2dBasic.PairSequence;
Triple: TYPE ~ G2dBasic.Triple;
Basic Operations on a Single Vector
Null:
PROC [v: Pair]
RETURNS [
BOOL];
Returns TRUE iff v is the origin.
Negate:
PROC [p: Pair]
RETURNS [Pair];
Return the negation of p.
Unit:
PROC [p: Pair]
RETURNS [Pair];
Return the unit length vector p.
Mul:
PROC [p: Pair, s:
REAL]
RETURNS [Pair];
Return the multiplication: p*s.
Div:
PROC [p: Pair, s:
REAL]
RETURNS [Pair];
Return the division: p/s.
Basic Operations on Two Vectors
Add:
PROC [p1, p2: Pair]
RETURNS [Pair];
Return the addition: p1+p2.
Sub:
PROC [p1, p2: Pair]
RETURNS [Pair];
Return the subtraction: p1-p2.
Equal:
PROC [v1, v2: Pair, epsilon:
REAL ¬ 0.001]
RETURNS [
BOOL];
Returns TRUE iff v1 = v2, to within epsilon.
Dot:
PROC [p1, p2: Pair]
RETURNS [
REAL];
Return the inner product: p1.p2.
Cross:
PROC [p1, p2: Pair]
RETURNS [
REAL];
Return the cross product: p1Xp2.
Midpoint:
PROC [v1, v2: Pair]
RETURNS [Pair];
Return 0.5*(v1+v2).
Interp:
PROC [t:
REAL, v1, v2: Pair]
RETURNS [Pair];
Return v1+t(v2-v1).
Combine:
PROC [v1: Pair, s1:
REAL, v2: Pair, s2:
REAL]
RETURNS [Pair];
Return s1*v1+s2*v2.
MulVectors:
PROC [v1, v2: Pair]
RETURNS [Pair];
Return p1*p2, component-wise multiplication.
DivVectors:
PROC [v1, v2: Pair]
RETURNS [Pair];
Return p1/p2; component division not performed if v2 component = 0.
Basic Operations on Sequence of Vectors
UnitizeSequence:
PROC [pairs: PairSequence];
Make each pair in the sequence unit length.
AverageSequence:
PROC [pairs: PairSequence]
RETURNS [Pair];
Return the average of the PairSequence.
MinMaxSequence:
PROC [pairs: PairSequence]
RETURNS [Box];
Return the bounding pairs of the sequence.
NegateSequence:
PROC [pairs: PairSequence];
Negate the sequence of vectors.
ReverseSequence:
PROC [src: PairSequence, dst: PairSequence ¬
NIL]
RETURNS [PairSequence];
Reverse the order of src; use dst if # NIL and long enough; if dst = src, in-place reversal.
Length and Distance Operations
Length:
PROC [p: Pair]
RETURNS [
REAL];
Return the length of p: |p|.
Square:
PROC [p: Pair]
RETURNS [
REAL];
Return the square of the length of p.
Distance:
PROC [p1, p2: Pair]
RETURNS [
REAL];
Distance between two pairs.
SquareDistance:
PROC [p1, p2: Pair]
RETURNS [
REAL];
Return the square of the distance between two pairs.
SameLength:
PROC [v1, v2: Pair]
RETURNS [Pair];
Return v2 adjusted to be same magnitude as v1.
SetVectorLength:
PROC [v: Pair, length:
REAL]
RETURNS [Pair];
Return v adjusted to be of magnitude length.
Nearness Operations
GetNear2dAccelerator:
PROC [p0, p1: Pair]
RETURNS [Triple];
Return the 2d accelerator for computing nearest point on the p0-p1 segment.
NearestToSegment:
PROC [p0, p1, q: Pair, acc: Triple ¬ [0, 0, 0]]
RETURNS [NearSegment];
Return the pair on line segment p0p1 nearest to q.
If acc # origin, the calculation of NearSegment is accelerated.
NearestToSequence:
PROC [p: Pair, points: PairSequence]
RETURNS [index:
NAT];
Return index such that points[index] is nearest to p.
Line and Triangle Operations
Line:
PROC [p0, p1: Pair]
RETURNS [Triple];
Return the equation for a 2d line through p0 and p1 of the form ax+by+c = 0;
a, b, and c are the components of the returned Triple.
DistanceToLine:
PROC [p: Pair, line2d: Triple]
RETURNS [
REAL];
Return the distance from the point p to the line.
IntersectTwoLines:
PROC [line0, line1: Triple]
RETURNS [Pair];
Return the intersection of the two lines.
TriangleArea:
PROC [p0, p1, p2: Pair]
RETURNS [
REAL];
Return the area of the triangle.
Miscellaneous Operations
AnglesAgree:
PROC [a0, a1:
REAL]
RETURNS [
REAL];
a0, a1 in radians. Return 1 if angles fully agree, 0 if they are antipodal.
AngleFromVector:
PROC [v: Pair, degrees:
BOOL ¬
FALSE]
RETURNS [
REAL];
Return angle between vector v and xAxis. (xAxis: 0, yAxis: P/2, -xAxis: P, -yAxis: 3*P/2)