home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Pascal / Applications / Flight Stability / Other Source / Vector3.p < prev   
Encoding:
Text File  |  1995-07-05  |  11.3 KB  |  177 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {  Vector3.p                                                                                                                               }
  4. {}
  5. {        This unit contains the necessary math and data structures to perform a                         }
  6. {        variety of operations on vectors with 3 entries and 3x3 matrices.                                      }
  7. {        Vectors are considered to be column vectors.                                                                                                     }
  8. {}
  9. {        Ease of use dictated that we be able to perform operations like --                                         }
  10. {}
  11. {                theSum := V3Sum(theVector1, theVector2);                                                                                                 }
  12. {}
  13. {        without danger of side effects, or having to worry about memory allocation.         }
  14. {        Hence we declare our vectors and matrices to be records, with their only               }
  15. {        field being the array containing the entries. In THINK Pascal (and Turbo Pascal, }
  16. {        or any other "real" Pascal compiler ie not Standard Pascal), we are able to             }
  17. {        return arrays, however we use records to to ease the transition to a possible  }
  18. {        C version. Note that we don't go as far as to have our arrays indexed from 0,     }
  19. {        since this detracts from standard notation (also note M3Element).                                          }
  20. {}
  21. {        Copyright © 1995 by Patrick Hew. All rights reserved.                                                    }
  22. {        Permission is granted for unrestricted non-commercial use.                                                         }
  23. {        Standard disclaimers apply.                                                                                                                                                             }
  24. {}
  25. {        Version: 1.0 by Patrick Hew  (email:phew@ucc.gu.uwa.edu.au)                         }
  26. {}
  27. {****************************************************}
  28.  
  29.  
  30. unit Vector3;
  31.  
  32.  
  33. interface
  34.  
  35.     type
  36.         V3IndexType = 1..3;
  37.  
  38.     type
  39.         V3Type = record
  40.                 row: array[V3IndexType] of Real;
  41.             end;
  42.  
  43.     type
  44.         M3Type = record
  45.                 col: array[V3IndexType] of V3Type;
  46.             end;
  47.  
  48.  
  49. { V3FromScalars }
  50. {}
  51. { Returns: A vector with the given x, y, z components. }
  52.  
  53.     function V3FromScalars (x, y, z: Real): V3Type;
  54.  
  55.  
  56. { V3Sum }
  57. {}
  58. { Returns: aVector1 + aVector2. }
  59.  
  60.     function V3Sum (aVector1, aVector2: V3Type): V3Type;
  61.  
  62.  
  63. { V3Scale }
  64. {}
  65. { Returns: aScalar *  aVector1. }
  66.  
  67.     function V3Scale (aScalar: Real; aVector: V3Type): V3Type;
  68.  
  69.  
  70. { V3Diff }
  71. {}
  72. { Returns: aVector1 - aVector2. }
  73.  
  74.     function V3Diff (aVector1, aVector2: V3Type): V3Type;
  75.  
  76.  
  77. { V3DotProduct }
  78. {}
  79. { Returns: aVector1 • aVector2. }
  80.  
  81.     function V3DotProduct (aVector1, aVector2: V3Type): Real;
  82.  
  83.  
  84. { V3EucNorm }
  85. {}
  86. { Returns: || aVector || . }
  87.  
  88.     function V3EucNorm (aVector: V3Type): Real;
  89.  
  90.  
  91. { V3Normalized }
  92. {}
  93. { Returns: The unit vector pointing in the same direction as aVector. }
  94.  
  95.     function V3Normalized (aVector: V3Type): V3Type;
  96.  
  97.  
  98. { V3CrossProduct }
  99. {}
  100. { Returns: aVector1 x aVector2. }
  101.  
  102.     function V3CrossProduct (aVector1, aVector2: V3Type): V3Type;
  103.  
  104.  
  105. { M3FromScalars }
  106. {}
  107. { Returns: A vector with the given entries. }
  108.  
  109.     function M3FromScalars (a11, a12, a13, a21, a22, a23, a31, a32, a33: Real): M3Type;
  110.  
  111.  
  112. { M3FromV3 }
  113. {}
  114. { Returns: A vector with the given columns. }
  115.  
  116.     function M3FromV3 (col1, col2, col3: V3Type): M3Type;
  117.  
  118.  
  119. { M3Element }
  120. {}
  121. { Returns: The element of aMatrix at aRow and aCol. }
  122.  
  123.     function M3Element (aMatrix: M3Type; aRow, aCol: V3IndexType): Real;
  124.  
  125.  
  126. { M3Row }
  127. {}
  128. { Returns: aRow of aMatrix as a V3Type vector. }
  129.  
  130.     function M3Row (aMatrix: M3Type; aRow: V3IndexType): V3Type;
  131.  
  132.  
  133. { M3TimesV3 }
  134. {}
  135. { Returns: aMatrix * aVector }
  136.  
  137.     function M3TimesV3 (aMatrix: M3Type; aVector: V3Type): V3Type;
  138.  
  139.  
  140. { M3TimesM3 }
  141. {}
  142. { Returns: aMatrix1 * aMatrix2 }
  143.  
  144.     function M3TimesM3 (aMatrix1, aMatrix2: M3Type): M3Type;
  145.  
  146.  
  147. { RotX }
  148. {}
  149. { Returns: The coordinate transformation from a rotated frame }
  150. {        to the universal frame, where the rotated frame is anAngle }
  151. {        about the x-axis. }
  152.  
  153.     function RotX (anAngle: Real): M3Type;
  154.  
  155.  
  156. { RotY }
  157. {}
  158. { Returns: The coordinate transformation from a rotated frame }
  159. {        to the universal frame, where the rotated frame is anAngle }
  160. {        about the y-axis. }
  161.  
  162.  
  163.     function RotY (anAngle: Real): M3Type;
  164.  
  165.  
  166. { RotZ }
  167. {}
  168. { Returns: The coordinate transformation from a rotated frame }
  169. {        to the universal frame, where the rotated frame is anAngle }
  170. {        about the z-axis. }
  171.  
  172.     function RotZ (anAngle: Real): M3Type;
  173.  
  174.  
  175. { FreeRotationMatrix }
  176. {}
  177. { Re