Displacement Class
A Displacement represents a geometric position along a line
segment, expressed in terms of two quantities: a relative
position called a
, and an absolute offset called b
. The
length of the line segment is not known in advance --- the idea
is that the Displacement object encapsulates a rule for
determining a location along ANY line segment. The Displacement
has methods which take the line segment length as an argument
and return the computed final position.
There are two different position-calcuating methods,
corresponding to two different interpretations of the relative
value a
:
relative length:
a
is a number between 0 and 1, representing a fraction of
the total length of the line segment; the relative
position determined by a
is the fraction a
of the
total length of the segment.
In this case, the position-calculating method
calculateLength(L)
returns the number a * L + b
, which
corresponds to moving a
of the way along the length L,
then adding b
:
[--------------------------------X------------]
|<---- a * L --->|<---- b ------>|
|<------------------ L -------------------->|
relative coordinate:
a
is a number between -1 and 1, representing a coordinate
value in a [-1,1] coordinate system along the line
segment.
In this case, the position-calculating method
calculateCoordinate(L)
returns the number (a+1) * L/2 +
b
. which corresponds to moving to the position
determined by the a
coordinate, then adding b
:
[------------------------------------X--------]
|<--- (a+1) * L/2 --->|<---- b ----->|
|<------------------ L -------------------->|
Constructor
Displacement
-
a
-
b
Parameters:
-
a
Number -
b
Integer(OPTIONAL)