|
Table
5 Custom VBA procedures written for the truck-turning
spreadsheet
| Procedure |
Description |
| Sub Rotate(XInput, YInput, XCentre, YCentre,
RotAngle, XNew, YNew) |
Subroutine to calculate the new coordinates
(XNew, YNew) of a point (XInput, YInput) that is rotated through
an angle in radians RotAngle about a centre point (XCentre, YCentre). |
| Function RotatedX(XOrd,
YOrd, XCentre, YCentre, AngleDeg)
[RotatedY is similar] |
Returns the rotated X-ordinate when a
point (XOrd, YOrd) is rotated about a centre point (XCentre, YCentre)
through an angle in degrees AngleDeg. |
| Sub Trailing(LinkLen,
HeadX, HeadY, HeadXPrev, HeadYPrev, TailXPrev, TailYPrev, TailX,
TailY, DirDeg) |
Subroutine to calculate the current coordinates
(TailX, TailY) of the tail end of a trailing link of length LinkLen
when the head of the trailing link has moved in a straight line
to its current position (HeadX, HeadY) from its previous position
(HeadXPrev, HeadYPrev) and the previous position of the tail end
of the trailing link is known (TailXPrev,TailYPrev). The subroutine
also calculates the current direction of the trailing link in degrees
DirDeg.
The curved path of the tail end of the trailing link is generated
by an iterative process for a succession of very small displacements
of the head of the link. An incremental distance of 0.01 metres
is used. |
| Sub RotationByRadius(Dist,
InvRadius, XInput, YInput, InputDirectionDeg, XCentre, YCentre,
XNew, YNew, OutputDirectionDeg) |
Subroutine to calculate the new coordinates
of a point (XNew, YNew) where the initial coordinates (XInput, YInput)
are given and where the point is rotated left or right through a
specified path-length distance Dist with a specified turning radius
(expressed as an inverse radius InvRadius) and where the initial
or input direction InputDirectionDeg of the path is specified in
degrees. The sign of the inverse radius InvRadius determines whether
the path will proceed to the left or to the right with respect to
the initial point and the initial direction. A positive input value
of InvRadius will give a left-hand turn while a negative value will
give a right-hand turn. The subroutine also calculates the final
or output direction of the path in degrees OutputDirectionDeg and
the coordinates of the centre of rotation (XCentre, YCentre). |
| Function RotationByRadiusX(Dist,
InvRadius, XInput, YInput, InputDirectionDeg)
[RotationByRadiusY, RotationByRadiusXCentre,
RotationByRadiusYCentre and RotationByRadiusOutDir are similar]
|
Returns the new X-ordinate of a point
where the initial coordinates (XInput, YInput) are given and where
the point is rotated as described for Sub RotationByRadius. |
| Sub Steer(Dist, InvRadius1,
InvRadius2, XInput, YInput, InputDirectionDeg, XNew, YNew, XCentre,
YCentre, OutputDirectionDeg) |
Subroutine to calculate the new coordinates
of a point (XNew, YNew) where the initial coordinates of the point
(XInput, YInput) are given and where the point is steered left or
right through a specified path-length distance Dist with a variable
turning radius (expressed as an inverse radius that varies linearly
with path distance from InvRadius1 to InvRadius2) and where the
initial or input direction InputDirectionDeg of the path is specified
in degrees. The sign of the inverse radius determines whether the
path will proceed to the left or to the right as for Sub RotationByRadius.
The subroutine also calculates the new coordinates of the centre
of rotation (XCentre, YCentre) and the output direction OutputDirectionDeg
(at the end of the path). |
| Function SteerX(Dist,
InvRadius1, InvRadius2, XInput, YInput, InputDirectionDeg)
[SteerY, SteerXCentre, SteerYCentre and SteerOutDir
are similar] |
Returns the new X-ordinate of a point
where the initial coordinates of the point (XInput, YInput) are
given and where the point is steered left or right as described
for Sub Steer. |
| Public Sub SteerAndTrail(Dist,
InvRadius1, InvRadius2, HeadXPrev, HeadYPrev, TailXPrev, TailYPrev,
InputDirectionDeg, LinkLen, HeadX, HeadY, TailX, TailY, XCentre,
YCentre, OutputDirectionDeg, TrailerDirectionDeg) |
Subroutine to calculate the new coordinates
of the head and tail endpoints (HeadX, HeadY) and (TailX, TailY)
of a trailing link of length LinkLen where the previous coordinates
of the head and tail endpoints (HeadXPrev, HeadYPrev) and (TailXPrev,
TailYPrev) are given and where the head of the trailing link is
steered as described for Sub Steer. The subroutine also calculates
the coordinates of the centre of rotation (XCentre, YCentre) at
the end of the path of the head, the final or output direction of
the path of the head in degrees OutputDirectionDeg and the direction
of the trailer at the end of the movement TrailerDirectionDeg. |
| Function TrailingX(Dist,
InvRadius1, InvRadius2, HeadXPrev, HeadYPrev, TailXPrev, TailYPrev,
InputDirectionDeg, LinkLen)
[TrailingY and TrailingDirDeg are similar] |
Returns the new X-ordinate of the tail
endpoint of a trailing link of length LinkLen where the previous
coordinates of the head and tail endpoints of the link (HeadXPrev,
HeadYPrev) and (TailXPrev, TailYPrev) are given and where the head
of the trailing link is steered as described for Sub Steer. |
| Public Sub TimeTick() |
This subroutine allows other procedures
to run until the step time has elapsed. The step time is set at
0.1 seconds. |
|