HELP VEC Jocelyn Ireson-Paine November 1992
This module exports some routines for handling vectors. These are useful
in Eden when calculating how the bug has to turn, and so on. You load
them by doing
lib vec;
If you are using Eden, this is not necessary, as it will be loaded
automatically.
Introduction
------------
The module defines routines for building vectors, selecting their x and
y components, adding, subtracting, and scalar multiplying. It also
exports two routines, turn2 and turn3, which can be used if you know
successive points or forwardvectors along Bug's path, and you want to
calculate what action it must take.
Procedures exported
-------------------
PUBLIC consvec( x, y ):
Builds the vector (x,y).
PUBLIC vec_x( v ):
PUBLIC vec_y( v ):
Return v's x and y components.
PUBLIC vec_add( v1, v2 ):
PUBLIC vec_sub( v1, v2 ):
PUBLIC 5 v1 ++ v2:
PUBLIC 5 v1 -- v2:
Return vectors corresponding to v1+v2 and v1-v2. You can also use the
infix operators ++ and -- as synonyms.
PUBLIC vec_smult( s, v ):
PUBLIC 4 s *** v:
Returns the vector sv, where s is a scalar.
PUBLIC turn2( v1, v2 ):
Indicates how v1 must be rotated to get v2. It returns a word
which is
"forward" if v1 and v2 are colinear and point in the same
direction;
"back" if colinear and in opposite directions;
"right" if v2 is the result of rotating v1 to the right;
"left" if v2 is the result of rotating v1 to the left.
This routine is useful when calculating how a bug must turn, given
an existing bearing (forwardvector) v1 and a new one v2.
PUBLIC turn3( p0, p1, p2 ):
This is equivalent to
turn2( p1--p0, p2--p1 )
This routine is useful when calculating how a bug must turn, given
three successive points p0, p1, p2 on its path.
Note: vectors are represented as lists, [%x,y%]. However, you are
advised to use the selector procedures vec_x and vec_y, since it
makes for more readable code. The reason for using lists is that
it makes them easy to interface with Prolog.