MGVectorExample.html (MotionGenesis input/output).
(1) % MotionGenesis file: MGVectorExample.txt
(2) %---------------------------------------------------
(3) % Create sets of right-handed orthogonal unit vectors.
(4) RigidFrame A % Creates Ax>, Ay>, Az>
(5) RigidBody B % Creates Bx>, By>, Bz>
(6) %---------------------------------------------------
(7) % Define other vectors in terms of these unit vectors.
(8) v> = 2*Ax> + 3*Ay> + 4*Az>
-> (9) v> = 2*Ax> + 3*Ay> + 4*Az>
(10) w> = Vector( A, 6, 7, 8 )
-> (11) w> = 6*Ax> + 7*Ay> + 8*Az>
(12) F> = Vector( B, [3, 5, 7] )
-> (13) F> = 3*Bx> + 5*By> + 7*Bz>
(14) % Multiply the vector v> by 5.
(15) vFive> = 5 * v>
-> (16) vFive> = 10*Ax> + 15*Ay> + 20*Az>
(17) % Add vectors v> and w>.
(18) addVW> = v> + w>
-> (19) addVW> = 8*Ax> + 10*Ay> + 12*Az>
(20) % Dot-multiply v> with w>.
(21) dotVW = Dot( v>, w> )
-> (22) dotVW = 65
(23) % Cross-multiply v> with w> and form w> x (w> x v>).
(24) crossVW> = Cross( w>, v> )
-> (25) crossVW> = 4*Ax> - 8*Ay> + 4*Az>
(26) crossWWV> = Cross( w>, Cross(w>,v>) )
-> (27) crossWWV> = 92*Ax> + 8*Ay> - 76*Az>
(28) % Find the magnitude and magnitude-squared of v>.
(29) magV = GetMagnitude( v> )
-> (30) magV = 5.385165
(31) magVSquared = GetMagnitudeSquared( v> )
-> (32) magVSquared = 29
(33) % Form the unit vector in the direction of v>.
(34) unitV> = GetUnitVector( v> )
-> (35) unitV> = 0.3713907*Ax> + 0.557086*Ay> + 0.7427814*Az>
(36) % Find the radian-measure of the angle between v> and w>.
(37) angleBetweenVW = GetAngleBetweenVectors( v>, w> )
-> (38) angleBetweenVW = 0.1496115
(39) % Form the ordinary time-derivative of the vector t*v> + sin(t)*w> in reference frame A.
(40) vectorDerivative> = Dt( t*v> + sin(t)*w>, A )
-> (41) vectorDerivative> = (2+6*cos(t))*Ax> + (3+7*cos(t))*Ay> + (4+8*cos(t))*Az>
(42) % Form a rotation matrix relating Bx>, By>, Bz> to Ax>, Ay>, Az> in terms of time t.
(43) B.SetRotationMatrixZ( A, t )
-> (44) B_A = [cos(t), sin(t), 0; -sin(t), cos(t), 0; 0, 0, 1]
(45) % Express vector v> in terms of Bx>, By>, Bz>.
(46) Express( v>, B )
-> (47) v> = (2*cos(t)+3*sin(t))*Bx> + (3*cos(t)-2*sin(t))*By> + 4*Bz>
(48) % To express vector v> + F> in terms of Ax>, Ay>, Az>, type
(49) sumInTermsOfAxyz> = Express( v> + F>, A )
-> (50) sumInTermsOfAxyz> = (2*sin(t)*(-2.5+sin(t))+2*cos(t)*(1.5+cos(t)))*Ax>
+ (3*sin(t)*(1+sin(t))+3*cos(t)*(1.666667+cos(t)))*Ay> + 11*Az>
(51) % Form the Bx>, By>, Bz> measures of w>.
(52) wMatrix = Vector( B, w> )
-> (53) wMatrix = [6*cos(t) + 7*sin(t); 7*cos(t) - 6*sin(t); 8]
(54) % Save input and output responses.
Saved by Motion Genesis LLC. MotionGenesis 6.4 Professional. Command names and syntax: Copyright (c) 2024 Motion Genesis LLC. All rights reserved.