home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-05 | 11.3 KB | 177 lines | [TEXT/PJMM] |
- {****************************************************}
- {}
- { Vector3.p }
- {}
- { This unit contains the necessary math and data structures to perform a }
- { variety of operations on vectors with 3 entries and 3x3 matrices. }
- { Vectors are considered to be column vectors. }
- {}
- { Ease of use dictated that we be able to perform operations like -- }
- {}
- { theSum := V3Sum(theVector1, theVector2); }
- {}
- { without danger of side effects, or having to worry about memory allocation. }
- { Hence we declare our vectors and matrices to be records, with their only }
- { field being the array containing the entries. In THINK Pascal (and Turbo Pascal, }
- { or any other "real" Pascal compiler ie not Standard Pascal), we are able to }
- { return arrays, however we use records to to ease the transition to a possible }
- { C version. Note that we don't go as far as to have our arrays indexed from 0, }
- { since this detracts from standard notation (also note M3Element). }
- {}
- { Copyright © 1995 by Patrick Hew. All rights reserved. }
- { Permission is granted for unrestricted non-commercial use. }
- { Standard disclaimers apply. }
- {}
- { Version: 1.0 by Patrick Hew (email:phew@ucc.gu.uwa.edu.au) }
- {}
- {****************************************************}
-
-
- unit Vector3;
-
-
- interface
-
- type
- V3IndexType = 1..3;
-
- type
- V3Type = record
- row: array[V3IndexType] of Real;
- end;
-
- type
- M3Type = record
- col: array[V3IndexType] of V3Type;
- end;
-
-
- { V3FromScalars }
- {}
- { Returns: A vector with the given x, y, z components. }
-
- function V3FromScalars (x, y, z: Real): V3Type;
-
-
- { V3Sum }
- {}
- { Returns: aVector1 + aVector2. }
-
- function V3Sum (aVector1, aVector2: V3Type): V3Type;
-
-
- { V3Scale }
- {}
- { Returns: aScalar * aVector1. }
-
- function V3Scale (aScalar: Real; aVector: V3Type): V3Type;
-
-
- { V3Diff }
- {}
- { Returns: aVector1 - aVector2. }
-
- function V3Diff (aVector1, aVector2: V3Type): V3Type;
-
-
- { V3DotProduct }
- {}
- { Returns: aVector1 • aVector2. }
-
- function V3DotProduct (aVector1, aVector2: V3Type): Real;
-
-
- { V3EucNorm }
- {}
- { Returns: || aVector || . }
-
- function V3EucNorm (aVector: V3Type): Real;
-
-
- { V3Normalized }
- {}
- { Returns: The unit vector pointing in the same direction as aVector. }
-
- function V3Normalized (aVector: V3Type): V3Type;
-
-
- { V3CrossProduct }
- {}
- { Returns: aVector1 x aVector2. }
-
- function V3CrossProduct (aVector1, aVector2: V3Type): V3Type;
-
-
- { M3FromScalars }
- {}
- { Returns: A vector with the given entries. }
-
- function M3FromScalars (a11, a12, a13, a21, a22, a23, a31, a32, a33: Real): M3Type;
-
-
- { M3FromV3 }
- {}
- { Returns: A vector with the given columns. }
-
- function M3FromV3 (col1, col2, col3: V3Type): M3Type;
-
-
- { M3Element }
- {}
- { Returns: The element of aMatrix at aRow and aCol. }
-
- function M3Element (aMatrix: M3Type; aRow, aCol: V3IndexType): Real;
-
-
- { M3Row }
- {}
- { Returns: aRow of aMatrix as a V3Type vector. }
-
- function M3Row (aMatrix: M3Type; aRow: V3IndexType): V3Type;
-
-
- { M3TimesV3 }
- {}
- { Returns: aMatrix * aVector }
-
- function M3TimesV3 (aMatrix: M3Type; aVector: V3Type): V3Type;
-
-
- { M3TimesM3 }
- {}
- { Returns: aMatrix1 * aMatrix2 }
-
- function M3TimesM3 (aMatrix1, aMatrix2: M3Type): M3Type;
-
-
- { RotX }
- {}
- { Returns: The coordinate transformation from a rotated frame }
- { to the universal frame, where the rotated frame is anAngle }
- { about the x-axis. }
-
- function RotX (anAngle: Real): M3Type;
-
-
- { RotY }
- {}
- { Returns: The coordinate transformation from a rotated frame }
- { to the universal frame, where the rotated frame is anAngle }
- { about the y-axis. }
-
-
- function RotY (anAngle: Real): M3Type;
-
-
- { RotZ }
- {}
- { Returns: The coordinate transformation from a rotated frame }
- { to the universal frame, where the rotated frame is anAngle }
- { about the z-axis. }
-
- function RotZ (anAngle: Real): M3Type;
-
-
- { FreeRotationMatrix }
- {}
- { Re