File: GGAngle.mesa
Last edited by Bier on June 4, 1985 6:14:56 pm PDT
Author: Eric Bier on January 5, 1987 4:31:09 pm PST
Contents: Gargoyle requires a precise set of angle operations defined with angle "theta" in the range -180 < theta <= 180. "theta" is an absolute angle (ie a position around the circle measured from the positive x axis). Given two positions angles T1 and T2 we can find the incremental clockwise angle CT between them or the incremental counter-clockwise angle CCT where -360 < CT <= 0 and 0 <= CCT < 360. When we add two angles, we are adding an incremental angle to a position angle to get a new position angle. We subtract two position angles to get an incremental angle. All angles are in degrees.
Pier, December 6, 1985 10:01:09 am PST
GGAngle: CEDAR DEFINITIONS =
BEGIN
Normalize:
PROC [anyRange:
REAL]
RETURNS [range180:
REAL];
Takes an angle in degrees and puts it in -180 < theta <= 180 form.
Add:
PROC [position, increment:
REAL]
RETURNS [finalPosition:
REAL];
All angles in degrees
ClockwiseAngle:
PROC [fromPosition, toPosition:
REAL]
RETURNS [increment:
REAL];
All angles in degrees. -360 < increment <= 0
CounterClockwiseAngle:
PROC [fromPosition, toPosition:
REAL]
RETURNS [increment:
REAL];
All angles in degrees. 0 <= increment < 360.
For example, if the clockwise angle is -90, the counter-clockwise angle will be 270.
ShortestDifference:
PROC [position1, position2:
REAL]
RETURNS [pos1MinusPos2:
REAL];
All angles in degrees. RETURNS ClockwiseAngle or CounterClockwiseAngle. Whichever is smaller. -180< pos1MinusPos2 <= 180.
Scale:
PROC [angle:
REAL, scalar:
REAL]
RETURNS [angleTimesScalar:
REAL];
All angles in degrees. Think of angle as the increment from 0 degrees to angle degrees. Scale this and normalize.
ArcTan:
PROC [numerator, denominator:
REAL]
RETURNS [degrees:
REAL];
Has the effect of calling RealFns.ArcTanDegrees and normalizing the result.
IsInCCWInterval: PROC [testPosition: REAL, fromPosition, toPosition: REAL] RETURNS [BOOL];
IsInCCWInterval2:
PROC [testPosition:
REAL, fromPosition, increment:
REAL]
RETURNS [
BOOL];
Consider the set of angles encountered when traveling counterclockwise from angle "fromPosition" to angle "toPosition" around a circle. Is testPosition one of the angles encountered?
AlmostParallel:
PROC [pos1, pos2:
REAL, epsilon:
REAL]
RETURNS [
BOOL];
pos1 and pos2 are assumed to be in -180 < theta <= 180. Return TRUE if they are the same angle +- epsilon or if they differ by 180+- epsilon.
END.