Vector2.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, March 7, 1985 1:20:28 pm PST
Defines VEC, a two dimensional vector type, and several useful vector operations.
Vector2: CEDAR DEFINITIONS
~ BEGIN
VEC: TYPE ~ RECORD[x, y: REAL];
Add: PROC[v1, v2: VEC] RETURNS[VEC];
InlineAdd:
PROC[v1, v2:
VEC]
RETURNS[
VEC]
~ INLINE { RETURN[[v1.x+v2.x, v1.y+v2.y]] };
Sum, v1+v2.
Sub: PROC[v1, v2: VEC] RETURNS[VEC];
InlineSub:
PROC[v1, v2:
VEC]
RETURNS[
VEC]
~ INLINE { RETURN[[v1.x-v2.x, v1.y-v2.y]] };
Difference, v1-v2.
Neg: PROC[v: VEC] RETURNS[VEC];
InlineNeg:
PROC[v:
VEC]
RETURNS[
VEC]
~ INLINE { RETURN[[-v.x, -v.y]] };
Negative, -v.
Mul: PROC[v: VEC, s: REAL] RETURNS[VEC];
InlineMul:
PROC[v:
VEC, s:
REAL]
RETURNS[
VEC]
~ INLINE { RETURN[[v.x*s, v.y*s]] };
Multiplication by a scalar, sv.
Div: PROC[v: VEC, s: REAL] RETURNS[VEC];
InlineDiv:
PROC[v:
VEC, s:
REAL]
RETURNS[
VEC]
~ INLINE { RETURN[[v.x/s, v.y/s]] };
Division by a scalar, v/s.
MulC: PROC[v1, v2: VEC] RETURNS[VEC];
InlineMulC:
PROC[v1, v2:
VEC]
RETURNS[
VEC]
~ INLINE { RETURN[[v1.x*v2.x, v1.y*v2.y]] };
Componentwise multiplication.
DivC: PROC[v1, v2: VEC] RETURNS[VEC];
InlineDivC:
PROC[v1, v2:
VEC]
RETURNS[
VEC]
~ INLINE { RETURN[[v1.x/v2.x, v1.y/v2.y]] };
Componentwise division.
Dot: PROC[v1, v2: VEC] RETURNS[REAL];
InlineDot:
PROC[v1, v2:
VEC]
RETURNS[
REAL]
~ INLINE { RETURN[v1.x*v2.x+v1.y*v2.y] };
Dot (inner) product, v1"v2 = |v1| |v2| cos(theta).
Cross: PROC[v1, v2: VEC] RETURNS[REAL];
InlineCross:
PROC[v1, v2:
VEC]
RETURNS[
REAL]
~ INLINE { RETURN[v1.x*v2.y-v1.y*v2.x] };
Magnitude of cross (outer) product, |v1 v2| = |v1| |v2| sin(theta).
Square: PROC[v: VEC] RETURNS[REAL];
InlineSquare:
PROC[v:
VEC]
RETURNS[
REAL]
~ INLINE { RETURN[v.x*v.x+v.y*v.y] };
Square, v"v = |v||v|.
Length:
PROC[v:
VEC]
RETURNS[
REAL];
Length (magnitude), |v| = SqRt[v"v].
Unit:
PROC[v:
VEC]
RETURNS[
VEC];
Unit vector, v/|v|.
END.