Spacecraft Math. Stephen Leake

Similar documents
Solving Systems of Linear Equations Symbolically

PHYS 705: Classical Mechanics. Introduction and Derivative of Moment of Inertia Tensor

9. Diffraction. Lattice vectors A real-space (direct) lattice vector can be represented as

Lesson Rigid Body Dynamics

45. The Parallelogram Law states that. product of a and b is the vector a b a 2 b 3 a 3 b 2, a 3 b 1 a 1 b 3, a 1 b 2 a 2 b 1. a c. a 1. b 1.

CSE 167: Introduction to Computer Graphics Lecture #2: Linear Algebra Primer

58. The Triangle Inequality for vectors is. dot product.] 59. The Parallelogram Law states that

1 Systems of Differential Equations

11 a 12 a 13 a 21 a 22 a b 12 b 13 b 21 b 22 b b 11 a 12 + b 12 a 13 + b 13 a 21 + b 21 a 22 + b 22 a 23 + b 23

Module 9: Further Numbers and Equations. Numbers and Indices. The aim of this lesson is to enable you to: work with rational and irrational numbers

Course 2BA1: Hilary Term 2007 Section 8: Quaternions and Rotations

CSE 167: Introduction to Computer Graphics Lecture #2: Linear Algebra Primer

MCE/EEC 647/747: Robot Dynamics and Control. Lecture 2: Rigid Motions and Homogeneous Transformations

Flight Dynamics & Control Equations of Motion of 6 dof Rigid Aircraft-Kinematics

This appendix provides a very basic introduction to linear algebra concepts.

Vector Spaces. EXAMPLE: Let R n be the set of all n 1 matrices. x 1 x 2. x n

Sample Solutions from the Student Solution Manual

A DARK GREY P O N T, with a Switch Tail, and a small Star on the Forehead. Any

P = ρ{ g a } + µ 2 V II. FLUID STATICS

Research Article Relative Status Determination for Spacecraft Relative Motion Based on Dual Quaternion

Chapter 2 Canonical Correlation Analysis

Matrices and Vectors

1Number ONLINE PAGE PROOFS. systems: real and complex. 1.1 Kick off with CAS

Classical Mechanics. Luis Anchordoqui

Representation theory of SU(2), density operators, purification Michael Walter, University of Amsterdam

Dynamics. 1 Copyright c 2015 Roderic Grupen

(3.1) a 2nd-order vector differential equation, as the two 1st-order vector differential equations (3.3)

Chapter 2 Math Fundamentals

School of Business. Blank Page

Expansion formula using properties of dot product (analogous to FOIL in algebra): u v 2 u v u v u u 2u v v v u 2 2u v v 2

Vectors and Matrices

Matrices. Chapter What is a Matrix? We review the basic matrix operations. An array of numbers a a 1n A = a m1...

We are already familiar with the concept of a scalar and vector. are unit vectors in the x and y directions respectively with

Rotational Motion. Chapter 4. P. J. Grandinetti. Sep. 1, Chem P. J. Grandinetti (Chem. 4300) Rotational Motion Sep.

QUADRATIC EQUATIONS EXPECTED BACKGROUND KNOWLEDGE

Section 8.5. z(t) = be ix(t). (8.5.1) Figure A pendulum. ż = ibẋe ix (8.5.2) (8.5.3) = ( bẋ 2 cos(x) bẍ sin(x)) + i( bẋ 2 sin(x) + bẍ cos(x)).

Mathematics Background

SNAP Centre Workshop. Exponents and Radicals

Closed-Form Solution Of Absolute Orientation Using Unit Quaternions

Ridig Body Motion Homogeneous Transformations

Translational and Rotational Dynamics!

10 Lorentz Group and Special Relativity

Topic 2: The mathematical formalism and the standard way of thin

Introduction to quaternions

Artificial Intelligence & Neuro Cognitive Systems Fakultät für Informatik. Robot Dynamics. Dr.-Ing. John Nassour J.

Transformation Matrices; Geometric and Otherwise As examples, consider the transformation matrices of the C 3v

Vectors and Matrices Statistics with Vectors and Matrices

Three-Dimensional Coordinate Systems. Three-Dimensional Coordinate Systems. Three-Dimensional Coordinate Systems. Three-Dimensional Coordinate Systems

Rotational & Rigid-Body Mechanics. Lectures 3+4

The Mean Version One way to write the One True Regression Line is: Equation 1 - The One True Line

COMP 175 COMPUTER GRAPHICS. Lecture 04: Transform 1. COMP 175: Computer Graphics February 9, Erik Anderson 04 Transform 1

Vector calculus background

Differential Geometry of Surfaces

Contravariant and Covariant as Transforms

FeynCalc Tutorial 1 (Dated: September 8, 2015)

EXERCISES ON DETERMINANTS, EIGENVALUES AND EIGENVECTORS. 1. Determinants

Math 216 Second Midterm 28 March, 2013

MAE 323: Lecture 1. Review

Rigid Body Motion. Greg Hager Simon Leonard

PHYS 705: Classical Mechanics. Rigid Body Motion Introduction + Math Review

Section 2.1: Reduce Rational Expressions

03 - Basic Linear Algebra and 2D Transformations

GG303 Lecture 6 8/27/09 1 SCALARS, VECTORS, AND TENSORS

The Matrix Algebra of Sample Statistics

7. FORCE ANALYSIS. Fundamentals F C

The Jacobian. Jesse van den Kieboom

Why Transforms? Want to animate objects and camera Translations Rotations Shears And more.. Want to be able to use projection transforms

ENGINEERING COMPUTATION Second Year Lectures. Stephen Roberts Michaelmas Term

Polynomial Degree and Finite Differences

Lecture 1.2 Pose in 2D and 3D. Thomas Opsahl

Chapter 2 Math Fundamentals

Kinematics of a UR5. Rasmus Skovgaard Andersen Aalborg University

Getting Started with Communications Engineering. Rows first, columns second. Remember that. R then C. 1

Introduction and Vectors Lecture 1

Applications of Eigenvalues & Eigenvectors

MATH 583A REVIEW SESSION #1

Quaternions. R. J. Renka 11/09/2015. Department of Computer Science & Engineering University of North Texas. R. J.

Number Plane Graphs and Coordinate Geometry

8 Velocity Kinematics

Simplified Analytical Model of a Six-Degree-of-Freedom Large-Gap Magnetic Suspension System

Part 8: Rigid Body Dynamics

A VERY BRIEF LINEAR ALGEBRA REVIEW for MAP 5485 Introduction to Mathematical Biophysics Fall 2010

In this section of notes, we look at the calculation of forces and torques for a manipulator in two settings:

6. 3D Kinematics DE2-EA 2.1: M4DE. Dr Connor Myant

3.5 Solving Quadratic Equations by the

Linear Algebra & Geometry why is linear algebra useful in computer vision?

Rigid Body Rotation. Speaker: Xiaolei Chen Advisor: Prof. Xiaolin Li. Department of Applied Mathematics and Statistics Stony Brook University (SUNY)

Chapter 2. Vectors and Vector Spaces

AB-267 DYNAMICS & CONTROL OF FLEXIBLE AIRCRAFT

Essential Maths 1. Macquarie University MAFC_Essential_Maths Page 1 of These notes were prepared by Anne Cooper and Catriona March.

Singularity-Free Dynamic Equations of Spacecraft-Manipulator Systems

Course MA2C02, Hilary Term 2010 Section 4: Vectors and Quaternions

Lagrangian Dynamics of Open Multibody Systems with Generalized Holonomic and Nonholonomic Joints

Non-Linear Regression Samuel L. Baker

2.003J Spring 2011: Dynamics and Control I On Notation Massachusetts Institute of Technology Department of Mechanical Engineering Feb.

A Symbolic Vector/Dyadic Multibody Formalism For Tree- Topology Systems

Linear Algebra March 16, 2019

REFRESHER. William Stallings

Orthogonality. 6.1 Orthogonal Vectors and Subspaces. Chapter 6

STEP Support Programme. STEP 2 Matrices Topic Notes

Transcription:

Spacecraft Math Stephen Leake 27 Septemer 2008

2

Chapter 1 Introduction This document presents a thorough summary of vector, quaternion, and matrix math used in spacecraft applications, in oth flight and simulation. It presents a standard notation, shows recommended usage, and provides references to other treatments of these topics as appropriate. We start with a discussion of asic concepts; rotations, translations, poses, rates, wrenches, mass and inertia. Then we discuss various algorithms used in spacecraft software. Each section is composed of four susections; Reference, Coding, Examples, and Derivations. Reference gives the definitions and equations for the section. Coding points to the software source code implementing the section, and discusses any software design issues, in particular variale naming conventions. We present two naming conventions; the SAL naming convention, and the GN&C naming convention adopted y the Goddard Guidance, Navigation and Control ranch. Examples gives numerical examples to illustrate the equations; accompanying Ada code implements the examples. Derivations motivates the definitions in the Reference susection, discusses how they relate to similar equations in other works, and derives the equations from first principles. In many cases, Derivation refers to Macsyma code that provides the detailed algeraic manipulations. The SAL software lirary does not assume the SAL naming convention. This is ecause the lirary supports left and right multiply rotations, and active and passive rotations. It also allows using the lirary with other naming conventions (such as GN&C). The Coding sections of this document define the SAL naming convention for each choice of left/right, active/passive, and show how it relates to the SAL software lirary. All equations are presented in vector notation, with the coordinate frames 3

4 CHAPTER 1. INTRODUCTION clearly indicated.

Chapter 2 3 Degrees of Freedom The main math of interest in 3 degrees of freedom is rotating vectors. There are many representations of rotations. The two most important for computation are unit quaternions and orthonormal 3-y-3 matrices; these can e multiplied to comine rotations, and used to rotate vectors. On the other hand, the most intuitive representation is angle axis; it is usually easy for people to visualize a rotation as an angle aout an axis. In many situations, the actual representation of a rotation is not important; we can think of an astract rotation R. So we first present notation for astract rotations, then discuss angle axis, quaternions, rotation matrices, and other representations that have special purposes. In general, a position vector represents a displacement from a ase position (usually the origin of a frame) to an oject position, expressed in a coordinate frame. We use the notation ref ase r oj, where ref is the frame the vector is expressed in, ase is the origin of the vector, and oj is the position. Note that negating a vector reverses the direction: ref oj r ase = ref ase r oj (2.0.0-1) Typically, ase is the origin of ref, and we drop ref. 5

6 CHAPTER 2. 3 DOF 2.1 Astract rotations 2.1.1 Reference An astract rotation is denoted y R. The inverse rotation (same axis and magnitude, opposite direction) is denoted R 1. There are two different ut similar rotation operations that change the frame of a vector: r oj = R a a r oj r oj = a r oj a R We call R a a left-multiply operator, and a R a right-multiply operator. [4] uses left-multiply rotation matrices and right-multiply quaternions. [6] uses right-multiply quaternions and left-multiply rotation matrices. In this document, we present algorithms for oth left and right multiply operators. The derivations are usually done in full for left-multiply operators; the right-multiply can e otained simply y sustitution. The distinction etween left- and right-multiply only matters for quaternion and matrix representations, which have multiplication operators. We will see elow that R a = a R 1. Left-multiply Rotations can either change the reference frame of a vector, or rotate the vector into a new vector: aser 1 = a R a ase r 1 (2.1.1-1) a ase r 2 = a a R 1 2 ase r 1 (2.1.1-2) ase r 1 is the same physical vector as a ase r 1, ut expressed in a different reference frame. This is called a passive rotation. The two laels on the rotation are two frames: a R changes the frame of a vector from a to ; the rotation is also expressed in frame a. On the other hand, a ase r 2 is a different vector. It is not parallel to a ase r 1, ut it is expressed in the same frame; this is called an active rotation. On an active rotation, the pre-superscript laels the frame the rotation is expressed in, the post-suscript 1 2 identifies the start and end orientations; it rotates from orientation 1 to orientation 2. Often the orientations are also frames. We could use a different notation for the active rotation. For example, a R 2 1 a ase r 1 or a 2 R 1 a ase r 1 would make it slightly easier to match the start orientation lael

2.1. ABSTRACT ROTATIONS 7 to the vector position lael. However, the first option is confusing, since we normally read left-to-right. The second option is hard to correlate with code notations. The chosen notation works slightly etter for right-multiply rotations (see elow). Since a rotation does not move the ase position of a vector, we can usually drop the ase position from the notation. Note that the notation for a passive rotation gives two frames, while the notation for an active rotation gives one frame and two orientations, which may also e three frames. The notation helps get the frames and usage correct; when changing reference frames of vectors (passive rotation), the post-suscript must match the presuperscript for the equation to make sense. On the other hand, when physically rotating vectors (active rotation), all the pre-superscripts must e the same. This convention is especially useful when more than one rotation is present: c R a = c R R a (2.1.1-3) c r 1 = c R R a a r 1 (2.1.1-4) a R 1 3 = a R 1 2 a R 2 3 (2.1.1-5) a r 3 = a R 2 3 a R 1 2 a r 1 (2.1.1-6) Note that the inverse of a rotation is otained y swapping laels: Note that this holds for comined rotations: a R 1 = R a (2.1.1-7) a R2 1 1 = a R 1 2 (2.1.1-8) c R a = c R R a c R 1 a = R 1 a c R 1 = a R R c = a R c a R 1 3 = a R a 2 3 R 1 2 a R1 3 1 = a R 1 1 2 a R 1 2 3 = a R a 2 1 R 3 2 = a R 3 2 There are two passive rotations related to an active rotation: a R = a R a R a = a R 1 a (2.1.1-9)

8 CHAPTER 2. 3 DOF Note that for these equations to make sense, the reference frame of the active rotation must e either a or. We will see in 2.3 how to change the reference frame of an active rotation quaternion. Rotations are not commutative; R R a is not the same as R a R. However, rotations are associative; (R c R )R a = R c (R R a ). Right-multiply The notation for right-multiply astract rotations is: r 1 a r 2 = a r 1 a R = a r 1 1 2 R a ar c = a R R c c r 1 = a r 1 a R R c 1 3R a = 1 2 R a 2 3R a a r 3 = a r 1 1 2 R a 2 3R a (2.1.1-10) R a = a R a ar = a R a 1 (2.1.1-11) Note that the order of the two orientations (in the suscript) in active rotations is not changed etween left and right multiply notations. Note that we do not have a different notation for vectors in equations when using right-multiply rotations, even though we do in code. 2.1.2 Coding We summarize the coding conventions for translation vectors, quaternions, and matrices here, to have them all in one place. In the SAL coding naming convention, a variale representing the astract leftmultiply passive rotation a R is written A_Rot_B. The equivalent right-multiply passive rotation R a is writtenb_rot_a; the order of the laels reflects the order in the notation. The type SAL.Gen_Math.Gen_DOF_3.Cart_Vector_Type implements Cartesian vectors. When using left-multiply rotations, a vector a r 1 is written A_Tran_1; when using right multiply rotations, the vector is written 1_Tran_A. Thus (2.1.1-1) is written: B_Tran_1 := B_Rot_A * A_Tran_1

2.1. ABSTRACT ROTATIONS 9 and the right rotation equivalent is written: 1_Tran_B := 1_Tran_A * A_Rot_B However, Ada names cannot start with numers, so care must e taken to use position and orientation laels that start with letters. Since a single program should only use either the right-multiply or left-multiply convention, the notation should not ecome confusing. The left-multiply active rotation a R 1 2 is writtena_rot_1_to_2. Thus (2.1.1-2) is written: A_Tran_2 := A_Rot_1_To_2 * A_Tran_1 and the right multiply equivalent: 2_Tran_A := 1_Tran_A * 1_To_2_Rot_A In the SAL naming convention, the notation for quaternions is the same as for astract rotations, with Quat instead of Rot. Similarly, for matrices the SAL naming convention uses Rot_Mat instead of Rot. In the GN&C convention (which dictates more than just naming), rotation matrices are always passive left-multiply, and rotation quaternions are always passive right-multiply. The left multiply matrix M a is written Dcm_AToB; the right-multiply quaternion a Q is written Quat_AToB. A position vector for oj expressed in frame a is written Pos_A_Oj. Thus (2.1.1-1) is written: Pos_B_Oj := Dcm_AToB * Pos_A_Oj and the quaternion right multiply equivalent is written: Pos_B_Oj := Pos_A_Oj * Quat_AToB Thus for rotation matrices, the frame order in the names is swapped etween SAL and GN&C naming conventions - the left-multiply passive rotation matrix a M is : a M = A_Rot_Mat_B = Dcm_BToA (2.1.2-1) However, for rotation quaternions, the frame order in the names is the same etween SAL and GN&C naming conventions - the right-multiply passive rotation quaternion Q a is : Q a = B_Quat_A = Quat_BToA (2.1.2-2) When using the GN&C convention, left and right multiplies are mixed in the same program, which will e confusing. To reduce the chances for error, left multiply matrices should only e used as user inputs; they should e immediately converted to right multiply quaternions efore eing used. In addition, the matrices should e named using the GN&C naming convention, while the

10 CHAPTER 2. 3 DOF quaternions should use the SAL naming convention. The conversion is given y: Q a = (to unit quaternion( a M )) 1 (2.1.2-3) B_Quat_A := SAL.Math_Doule.Dof_3.Wertz.To_Unit_Quaternion (Dcm_BToA) where to unit quaternion is given y (2.4.1-5). Note that SAL.Math_Doule.Dof_3.Wertz.To_Unit_Quaternion comines the inverse with the conversion to quaternion, preserving the frame order in this pair of variale names. This is ecause of the implicit conversion from left to right multiply, and it helps avoid mistakes in user code. There is no Ada type corresponding to an astract rotation. However, similar operations for the concrete rotation types are coded in similar ways, to make it easy to change the rotation type in applications. It is tempting to define two different Ada types for quaternions (or matrices); left-multiply and right-multiply. Then the compiler would guarantee they never got mixed up. However, that would mean any higher-level types that had quaternion components would also need left and right versions. In addition, code for operations that do not depend on the choice of left or right-multiply must e duplicated. This is too heavy a urden. Instead, the SAL math lirary provides one package defining rotation quaternion and rotation matrix types, and all the operations on them that do not depend on the choice of left or right multiply. Then there are two child packages providing the operations that do depend on the choice. One provides left-multiply quaternion and matrix operations. The other, following [6] and [3], supports right-multiply quaternion and left-multiply matrix operations. For higher level packages that use rotations, a similar package structure is used. In any case, careful attention must e paid to whether rotations are active vs passive, to the signs of angles, and to the order of operands in multiplication. 2.2 Angle Axis rotation representation 2.2.1 Reference Every active rotation can e expressed as an angle aout an axis. If θ 1 2 is the angle from vector a r 1 to vector a r 2 aout axis aˆn (using the right-hand rule for the sign of θ 1 2 ), then a R 1 2 = (θ 1 2, aˆn) (2.2.1-1)

2.2. ANGLE AXIS ROTATION REPRESENTATION 11 Note that ˆn has magnitude 1: n 2 x + n2 y + n2 z = 1 (2.2.1-2) The right-hand rule is: hold the right hand with the thum extended and the fingers loosely curled. Then the right thum is aligned with the axis of rotation, and the fingers curl in the positive direction of the rotation. Note that the same rotation can e represented y negating oth θ 1 2 and aˆn: a R 1 2 = ( θ 1 2, aˆn) (2.2.1-3) So generally we can choose 0 <= θ 1 2 <= π. The Ada code does not enforce this in general, ut it does take advantage of it when converting from other rotation representations to angle axis. The inverse rotation is: a R 2 1 = ( θ 1 2, aˆn) (2.2.1-4) = (θ 2 1, aˆn) The active rotation is computed y: a r 2 = a r 1 cosθ 1 2 a r 1 aˆnsinθ 1 2 + aˆn a r 1 aˆn(1 cosθ 1 2 ) (2.2.1-5) Note that if we have two rotations (θ 1 2, ˆn 1 ) and (θ 2 3, ˆn 2 ), there is no simple way to find the equivalent total rotation. Rotation quaternions or matrices provide that operation. We now consider the passive rotations that are related to this active rotation. Since this involves changing frames, we use letters to lael the two orientations involved in the active rotation. Then the passive rotations that change the frame of vectors from to a and vice versa are: a R = (θ a, aˆn) R a = ( θ a, aˆn) (2.2.1-6) An important case is otaining the minimal rotation that takes one vector into another. Given two unit vectors aˆn 1 and aˆn 2 expressed in a common frame f, the active rotation that moves aˆn 1 to e parallel to aˆn 2 is: a v = aˆn 1 aˆn 2 s = a v c = aˆn 1 aˆn 2 θ 1 2 = atan2(s, c)

12 CHAPTER 2. 3 DOF if s = 0 then aˆn = (1.0, 0.0, 0.0) else aˆn = a v/s (2.2.1-7) end if 2.2.2 Coding The type SAL.Gen_Math.Gen_DOF_3.Mag_Axis_Type implements the angle axis rotation representation. Operations are provided for scaling and conversion to quaternions and rotation matrices. SAL.Gen_Math.Gen_DOF_3.Rotate implements (2.2.1-5). In the SAL naming convention, angle axis rotations are always active. See 2.3.2 and 2.4.2 for functions related to converting angle axis to quaternions and matrices. 2.2.3 Examples Some simple numerical examples. See spacecraft_math_examples.ad, Angle_Axis lock for Ada code implementing these. First, an active rotation of a vector in the x-z plane in a positive direction aout the y axis. ase r 1 = (2.0, 0.0, 1.0) ase R 1 2 = (θ 1 2, aseˆn) = (0.1, (0.0, 1.0, 0.0)) ase r 2 = (2.08984, 0.00000, 0.79534) Note that the x component increases, and the z component decreases; the end point of the vector is moved closer to the x axis. Now a spacecraft example; the direction of the z axis of the spacecraft. Assume the Sun is at the origin of the ase frame, and the spacecraft is positioned on the negative z axis of the ase frame. Initially, the z axis of the spacecraft frame is pointing at the sun. Then we rotate the spacecraft in a positive direction aout the y axis. Frame sc0 gives the initial orientation of the spacecraft; it is parallel to frame ase. Frame sc1 gives the final orientation of the spacecraft.

2.2. ANGLE AXIS ROTATION REPRESENTATION 13 Unit vector aseˆn scz0 gives the direction of the z axis of the spacecraft in the ase frame in the initial orientation; aseˆn scz1 in the final. aseˆn scz0 = (0.0, 0.0, 1.0) ase R sc0 sc1 = (0.1, (0.0, 1.0, 0.0)) aseˆn scz1 = ase R sc0 sc1 aseˆn scz0 = (0.09983, 0.00000, 0.99500) In the ase frame, the z axis of the spacecraft has moved towards the positive x axis. Now consider the direction from the spacecraft to the Sun; we know what it is in the ase frame, and we need to find it in the spacecraft frame. The unit vector ˆn sc sun gives the direction from the spacecraft to the sun, in a given frame. aseˆn sc sun = (0.0, 0.0, 1.0) sc0ˆn sc sun = (0.0, 0.0, 1.0) sc1 R sc0 = ase R 1 sc0 sc1 = ( 0.1, (0.0, 1.0, 0.0)) sc1ˆn sc sun = sc1 R sc0 sc0ˆn sc sun = ( 0.09983, 0.00000, 0.99500) In the spacecraft frame, the direction to the sun has moved towards the negative x axis. 2.2.4 Derivations First we show that (2.2.1-5) is correct. Let frame a e fixed to the non-rotated vector a r 1 ; frame is fixed to the rotated vector a r 2. We denote the axes of frame a y (ˆx a, ŷ a, ẑ a ). For simplicity, we use r x to denote the x component of vector r in either frame; similarly for y and z. By definition: a r 1 = r xaˆx a + r yaŷ a + r zaẑ a (2.2.4-1) Because a r 2 is a rotation of a r 1, it has the same values for its components in as a r 1 has in a, so we can write: a r 2 = r xaˆx + r yaŷ + r zaẑ (2.2.4-2) Without loss of generality, we can let the axis of rotation aˆn = a ẑ = ẑ (this just defines the two frames uniquely). Then the axes of the frames are related y: aˆx = cosθ 1 2aˆx a + sinθ 1 2aŷ a (2.2.4-3) aŷ = sinθ 1 2aˆx a + cosθ 1 2aŷ a (2.2.4-4) aẑ = a ẑ a (2.2.4-5)

14 CHAPTER 2. 3 DOF Note that when θ 1 2 = 0, = a. Sustituting (2.2.4-3), (2.2.4-4), (2.2.4-5) into (2.2.4-2): a r 2 = (r x cosθ 1 2 r y sinθ 1 2 ) aˆx a + (r x sinθ 1 2 + r y cosθ 1 2 ) a ŷ a + r zaẑ a (2.2.4-6) Expanding (2.2.1-5), we have a r rot = r x cosθ 1 2aˆx a + r y cosθ 1 2aŷ a + r z cosθ 1 2aẑ a (2.2.4-7) ( r xaŷ a + r yaˆx a )sinθ 1 2 + r z (1 cosθ 1 2 ) a ẑ a = (r x cosθ 1 2 r y sinθ 1 2 ) aˆx a + (r x sinθ 1 2 + r y cosθ 1 2 ) a ŷ + r zaẑ a (2.2.4-8) which is the same as (2.2.4-6). Repeating this analysis, picking aˆn = aˆx, a ŷ, shows that (2.2.1-5) is correct. 2.2.5 Comparison to Kane (2.2.1-5) corresponds to [4, eqn 1.1(1)]. The derivation here follows Kane s. 2.3 Quaternion rotation representation 2.3.1 Reference A rotation quaternion consists of four numers, where the sum of the squares is 1: Q = (Q x, Q y, Q z, Q s ) (2.3.1-1) 1 = Q 2 x + Q 2 y + Q 2 z + Q 2 s (2.3.1-2) This is a unit quaternion; in general, non-unit quaternions (magnitude not restricted to 1) are also useful, ut we do not consider them here. Given an active angle axis rotation, the active left-multiply unit quaternion

2.3. QUATERNION ROTATION REPRESENTATION 15 equivalent is given y: a R a = (θ a, aˆn) a R a = a Q a a Q a = (sin(θ a /2) aˆn, cos(θ a /2)) Q x Q y = sin(θ a /2)n x = sin(θ a /2)n y Q z = sin(θ a /2)n z Q s = cos(θ a /2) (2.3.1-3) Q x, Q y, Qz are called the vector components; Q s is called the scalar component. The related passive rotations are: a Q = (sin(θ a /2) aˆn, cos(θ a /2)) Q a = ( sin(θ a /2) aˆn, cos(θ a /2)) (2.3.1-4) Negating all elements of the quaternion represents the same rotation: a R a = ( Q x, Q y, Q z, Q s ) (2.3.1-5) The inverse of a quaternion is given y: Q a = a Q 1 = ( Q x, Q y, Q z, Q s ) (2.3.1-6) To otain the active angle and axis (θ a, aˆn) from a left-multiply active quaternion a Q a : if Q s < 0 then end if Q = ( Q x, Q y, Q z, Q s ) s = Q 2 x + Q2 y + Q2 z if s > 0 then θ a = 2 atan2(s, Q s ) aˆn = (Q x /s, Q y /s, Q z /s) (2.3.1-7) else θ a = 0 aˆn = (1, 0, 0)

16 CHAPTER 2. 3 DOF end if Note that the resulting θ is in the range [0.0, π]. Given an angle axis with θ in [ π, 0.0], conversion to quaternion and ack will negate the unit vector. To multiply a vector y a quaternion : r = Qr a = (Q y r z Q z r y, Q z r x Q x r z, Q x r y Q y r x ) r x = 2(Q s a x + Q y a z Q z a y ) + r x r y = 2(Q s a y + Q z a x Q x a z ) + r y r z = 2(Q s a z + Q x a y Q y a x ) + r z (2.3.1-8) If Q is an active quaternion (ie, it represents an active rotation), r is a rotated vector: r = a r 2 = a Q 1 2 a r 1 (2.3.1-9) If Q is a passive rotation, r is r expressed in a different frame: r = r 1 = Q a a r 1 (2.3.1-10) To multiply quaternions: Q 3 = Q 1 Q 2 Q 3x = Q 1y Q 2z Q 1z Q 2y + Q 1s Q 2x + Q 1x Q 2s Q 3y = Q 1x Q 2z + Q 1s Q 2y + Q 1z Q 2x + Q 1y Q 2s Q 3z = Q 1s Q 2z + Q 1x Q 2y Q 1y Q 2x + Q 1z Q 2s Q 3s = Q 1z Q 2z Q 1y Q 2y Q 1x Q 2x + Q 1s Q 2s (2.3.1-11) If the quaternions are active, this represents two successive physical rotations: a Q 1 3 = a Q a 2 3 Q 1 2 a r 3 = a Q a 2 3 Q a 1 2 r 1 (2.3.1-12) If the quaternions are passive, this represents two successive coordinate transforms: c Q a = c Q Q a c r 1 = c Q Q a a r 1 (2.3.1-13) The passive quaternions related to an active quaternion, when the reference frame of the active quaternion is either the start or end frame: a Q Q a = a Q a = a Q 1 a (2.3.1-14)

2.3. QUATERNION ROTATION REPRESENTATION 17 To change the reference frame of an active quaternion: Q c = Q a a Q c Q 1 a (2.3.1-15) To convert an active quaternion to a passive quaternion when the reference frame of the active quaternion is aritrary: c Q = Q a a Q 1 c Q 1 a (2.3.1-16) Successive passive quaternions related to successive active quaternions: a Q a c = a Q c a Q a a Q c = a Q Q c c Q a = c Q Q a (2.3.1-17) Given two unit vectors, find the minimal rotation that takes one into the other: a v = aˆn 1 aˆn 2 s = a v c = aˆn 1 aˆn 2 if s = 0 then a Q 1 2 = (0.0, 0.0, 0.0, 1.0) else 1 c s2 = 2 1 + c c2 = 2 a Q 1 2 = ( s2 a v, c2) (2.3.1-18) s end if (2.3.1-18) defines the function units to quat for left-multiply. Right-multiply For right-multiply quaternions, we have: R a = Q a Q a = a Q 1 (2.3.1-19)

18 CHAPTER 2. 3 DOF Active quaternion and active angle axis: 1 2Q a = ( sin(θ 1 2 /2) aˆn, cos(θ 1 2 /2)) (2.3.1-20) r = r Q a = ( Q yr z + Q zr y, Q zr x + Q xr z, Q xr y + Q yr x ) r x = 2(Q s a x Q y a z + Q z a y) + r x r y = 2(Q sa y Q za x + Q xa z ) + r y r z = 2(Q s a z Q x a y + Q y a x) + r z (2.3.1-21) 1 3Q a = 1 2 Q a 2 3Q a (2.3.1-22) a r 3 = a r 1 1 2 Q a 2 3Q a (2.3.1-23) Passive quaternions: Q a = a Q a aq = a Q a 1 aq c = a Q Q c c r 1 = a r 1 a Q Q c (2.3.1-24) To otain the active angle and axis (θ 1 2, aˆn) from a right-multiply active quaternion 1 2 Q a : if Q s < 0 then Q = ( Q x, Q y, Q z, Q s ) end if s = Q 2 x + Q2 y + Q2 z if s > 0 then θ 1 2 = 2 atan2(s, Q s ) aˆn = (Q x /s, Q y /s, Q z /s) (2.3.1-25) else θ 1 2 = 0 aˆn = (1, 0, 0) end if

2.3. QUATERNION ROTATION REPRESENTATION 19 Changing the frame of an active quaternion, and successive rotations: Function units to quat: aq = a Q a 1 (2.3.1-26) cq = a Q 1 cq a aq (2.3.1-27) Q c = a Q 1 cq a 1 aq (2.3.1-28) a cq a = a Q a cq a cq a = c Q Q a aq c = a Q Q c (2.3.1-29) a v = aˆn 1 aˆn 2 s = a v c = aˆn 1 aˆn 2 if s = 0 then a Q 1 2 = (0.0, 0.0, 0.0, 1.0) else 1 c s2 = 2 1 + c c2 = 2 a Q 1 2 = ( s2 a v, c2) (2.3.1-30) s end if 2.3.2 Coding The type SAL.Gen_Math.Gen_DOF_3.Unit_Quaternion_Type implements the quaternion rotation representation. The child package SAL.Gen_Math.Gen_DOF_3.Gen_Left provides left-multiply operations, the child package SAL.Gen_Math.Gen_DOF_3.Gen_Wertz provides right-multiply quaternion and left-multiply matrix operations. It is up to the user to decide whether the quaternions are passive or active, when using these packages. In particular, in the conversions etween quaternions and angle axis, the quaternion and angle axis are either oth active or oth passive. In the SAL convention, a variale representing the passive left-multiply quaternion a Q is written A_Quat_B; a right-multiply quaternion Q a is written

20 CHAPTER 2. 3 DOF B_Quat_A. An active left-multiply quaternion a Q 1 2 is written A_Quat_1_2; a right-multiply quaternion 1 2 Q a is written 1_2_Quat_A. Any single program should use only left or right multiply, so this convention should not e confusing. In the GN&C software naming convention a variale representing the passive right-multiply quaternion Q a is writtenquat_btoa. The GN&C software naming convention has no notation for left-multiply or active quaternions. 2.3.3 Examples See spacecraft_math_examples.ad, Quaternions_Left lock for Ada code implementing these. Some of these examples are the same as in 2.2.3, ut using left-multiply quaternions. We duplicate the descriptions here for convenience. The Ada code also shows the right-multiply equivalents. First, an active rotation of a vector in the x-z plane in a positive direction aout the y axis. ase Q 1 2 = to unit quaternion(θ 1 2, aseˆn) = to unit quaternion(0.1, (0.0, 1.0, 0.0)) = (0.00000, 0.04998, 0.00000, 0.99875) ase r 1 = (2.0, 0.0, 1.0) ase r 2 = (2.08984, 0.00000, 0.79534) Note that the y component of the quaternion has the same sign as the angle. Note that the x component of ase r 2 increases, and the z component decreases; the end point of the vector is moved closer to the x axis. Now we apply a second active rotation, and show that quaternion multiplication is associative: ase Q 2 3 = to unit quaternion(π/2, (1.0, 0.0, 0.0)) = (0.70711, 0.00000, 0.00000, 0.70711) ase Q 1 3 = ase Q 2 3 ase Q 1 2 = (0.70622, 0.03534, 0.03534, 0.70622) ase r 3 = ase Q 2 3 ase r 2 = (2.08984, 0.79534, 0.00000) ase r 3 = ase Q 1 3 ase r 1 = (2.08984, 0.79534, 0.00000) Now a spacecraft example; the direction of the z axis of the spacecraft. Assume the Sun is at the origin of the ase frame, and the spacecraft is positioned on the

2.3. QUATERNION ROTATION REPRESENTATION 21 negative z axis of the ase frame. Initially, the z axis of the spacecraft frame is pointing at the sun. First we rotate the spacecraft in a positive direction aout the ase y axis, then aout the ase x axis. Frame sc0 gives the initial orientation of the spacecraft; it is parallel to frame ase. Frame sc1 gives the orientation of the spacecraft after the first rotation, sc2 after the second. Unit vector aseˆn scz0 gives the direction of the z axis of the spacecraft in the ase frame in the initial orientation; aseˆn scz1 after the first rotation. aseˆn scz0 = (0.0, 0.0, 1.0) ase Q sc0 sc1 = to unit quaternion(0.1, (0.0, 1.0, 0.0)) = (0.00000, 0.04998, 0.00000, 0.99875) aseˆn scz1 = (0.09983, 0.00000, 0.99500) In the ase frame, the z axis of the spacecraft has moved towards the positive x axis. Now we apply a second rotation, aout the ase x axis. ase R sc1 sc2 = to unit quaternion(π/2, (0.0, 1.0, 0.0))) = (0.70711, 0.00000, 0.00000, 0.70711) aseˆn scz2 = (0.09983, 0.99500, 0.00000) Now consider the direction from the spacecraft to the Sun; we know what it is in the ase frame, and we need to find it in the spacecraft frame. The unit vector ˆn sc sun gives the direction from the spacecraft to the sun, in a given frame. We use the same two rotations as aove; we need passive quaternions for this, so the result of converting from active angle axis is inverted. aseˆn sc sun = (0.0, 0.0, 1.0) sc0ˆn sc sun = (0.0, 0.0, 1.0) sc1 Q ase = (to unit quaternion(0.1, (0.0, 1.0, 0.0))) 1 = (0.00000, 0.04998, 0.00000, 0.99875) sc1ˆn sc sun = ( 0.09983, 0.00000, 0.99500) In the spacecraft frame, the direction to the sun has moved towards the negative x axis. Now we apply a second rotation, aout the ase x axis. We show the angle axis equivalent to each quaternion, since that may e easier to visualize. The Ada

22 CHAPTER 2. 3 DOF code also shows that quaternion multiply is associative. sc1 Q sc1 sc2 = sc1 Q ase ase Q sc1 sc1 sc2 Q 1 ase = (0.70357, 0.00000, 0.07059, 0.70711) sc1 R sc1 sc2 = (1.57080, (0.99500, 0.00000, 0.09983)) sc2 Q sc1 = sc1 Q 1 sc1 sc2 = ( 0.70357, 0.00000, 0.07059, 0.70711) sc2 R sc1 = (1.57080, ( 0.99500, 0.00000, 0.09983)) sc2ˆn sc sun = (0.00000, 1.00000, 0.00000) 2.3.4 Vector Scalar formulation The equations for quaternion times quaternion and quaternion times vector can also e expressed in pure vector notation, without reference to any Cartesian frame. First, we denote the vector and scalar parts of a quaternion y: Q 1 = (q 1v, Q 1s ) (2.3.4-1) Then (2.3.1-11) ecomes Q 3 = Q 1 Q 2 = (q 2v Q 1s + q 1v Q 2s + q 1v q 2v, Q 1s Q 2s q 1v q 2v ) (2.3.4-2) This illustrates that there is a frame involved in a quaternion that is not shown in the quaternion notation; the reference frame of the vector part. However, the vector part is an eigenvector of the rotation (it is parallel to the axis of rotation), so it does not matter whether it is expressed in a or. To actively rotate a vector in this formulation, form a quaternion (not a unit quaternion) from the vector y setting the scalar part to zero. Then (2.3.1-9) ecomes a r 2 = a Q 1 2 a r 1 (2.3.4-3) = a Q 1 2 ( a r 1, 0) a Q 1 2 (2.3.4-4) where a Q 1 2 is the conjugate quaternion, and is the same as a Q 1 1 2. The multiplication operator in (2.3.4-3) is given y (2.3.1-8); in (2.3.4-4), it is given y (2.3.4-2). Expanding and applying vector and trig identities, this reduces to (2.2.1-5). See derive_vect_scalar_quat.maxima for details.

2.3. QUATERNION ROTATION REPRESENTATION 23 Similarly, for a passive rotation, (2.3.1-10) ecomes r 1 = Q a a r 1 = Q a ( a r 1, 0) Q a (2.3.4-5) When comining rotations, as in (2.1.1-4), this is: c Q a = c Q Q a c r 1 = c Q a ( a r 1, 0) c Q a c r 1 = c Q Q a ( a r 1, 0) Q a c Q (2.3.4-6) Right-multiply For right-multiply quaternions, the non-conjugate quaternion is on the right: a r 2 r 1 = a r 1 1 2 Q a = 1 2 Q a ( a r 1, 0) 1 2 Q a (2.3.4-7) = a r 1 a Q = a Q ( a r 1, 0) a Q (2.3.4-8) aq c = a Q Q c c r 1 = a Q c ( a r 1, 0) a Q c c r 1 = Q c aq ( a r 1, 0) a Q Q c (2.3.4-9) This is the motivation for the names left-multiply, right-multiply for quaternions. 2.3.5 Derivations (2.3.1-3) is simply the definition of an active left-multiply rotation quaternion. (2.3.1-4) is otained from (2.3.1-3) y sustituting θ 1 2 for θ 1 2. To see that (2.3.1-5) gives the same rotation, note that Q i always occurs in pairs in (2.3.1-8). Thus changing the sign of all Q i has no effect on the rotated vector. Also compare this to (2.2.1-3). Note that we could restrict Q s >= 0. However, enforcing that condition in every quaternion operation is inefficient; instead we only enforce it where it is useful, such as in conversion to angle axis. (2.3.1-6) is derived from (2.2.1-4) and (2.3.1-5). We negate the vector components of the quaternion rather than the scalar component, ecause then the

24 CHAPTER 2. 3 DOF inverse operation is the same as the conjugate operation, used in the vectorscalar formulation of quaternion times vector (see 2.3.4). (2.3.1-7) is derived from (2.3.1-3) using the trigonometric identity θ = atan2(sin(θ), cos(θ)). Q s is forced positive to ensure that θ is in the range [0, 2π); otherwise it would e in the range [0, 4π). Care is taken to ensure that conversion from angle to axis to quaternion and ack is identity for the angle in [0.0, π). (2.3.1-7) is singular when s is zero. To see how to handle the singularity, consider the quaternion (ǫ, 0, 0, 1), where ǫ is the largest numer such that 1 + ǫ = 1 to machine precision. Note that this satisfies (2.3.1-2), since 1 + ǫ 2 = 1. Note that s = ǫ, and (2.3.1-7) is well-ehaved. Thus there is only a prolem when s is identically zero. In that case, the magnitude of the rotation is zero, and the axis is undetermined, so we simply pick the x axis. To prove that (2.3.1-8) is the equation for rotating a vector, sustitute (2.3.1-3) into (2.3.1-8), and compare to (2.2.1-5). See derive_quat_times_vect.maxima for the details. Note that the temporary variale a provides a significant optimization; this was first pulished in [5]. To prove that (2.3.1-11) is the equation for comining rotations, we evaluate (Q a Q )r and Q a (Q r) using (2.3.1-11) and (2.3.1-8), and show they are the same. See derive_quat_times_quat.maxima for the details. To prove (2.3.1-15), start with a vector rotation, and change the frame of the vectors: a r 2 = a Q a c r 1 a r 1 = Q 1 a r 1 r 2 = Q a a r 2 Q c = Q a a Q a c r 1 = Q a a Q c Q 1 a r 1 = Q a a Q c Q 1 a (2.3.1-16) is derived from (2.3.1-15) and (2.3.1-14), simplifying the inverses: c Q = Q 1 c = ( Q a a Q c Q 1 a ) 1 = Q a a Q 1 c Q 1 a To prove (2.3.1-17), start y simply inverting the active quaternions: a Q a c a Q 1 a c c Q a = a Q a c Q a = a Q 1 a a Q 1 c = Q a a Q 1 c

2.3. QUATERNION ROTATION REPRESENTATION 25 To proceed from here, we need to get the second term into the form of (2.3.1-16). So we insert Q 1 a Q a, which is identity, and regroup: c Q a = Q a ( Q 1 a Q a ) a Q 1 c ( Q 1 a Q a ) = Q a Q 1 a ( Q a a Q 1 c Q 1 a ) Q a = c Q Q a Right-multiply The right-multiply equations (2.3.1-20) thru (2.3.1-29) are otained from the corresponding left multiply equations y consistently negating the vector components of the quaternions, and reversing the order of multiplied quaternions. 2.3.6 Comparison to Kane [4] calls quaternion components Euler parameters, with symol ǫ. Set Q x = ǫ 1, Q y = ǫ 2, Q z = ǫ 3, Q s = ǫ 4 to otain our notation. (2.3.1-3) is equivalent to [4, eqn 1.2(1)-(2)]; oth are active rotations. (2.3.1-9) is equivalent to [4, eqn 1.3(21)]. See derive_quat_times_vect_kane.maxima for details. (2.3.1-12) is the same as [4, eqn 1.6(12)]. 2.3.7 Comparison to Wertz For historical reasons, this section compares left-multiply quaternions to Wertz. It was in the process of doing this comparison that I recognized the existence of right-multiply quaternions, and finally understood the origin of the sign difference etween Kane and Wertz quaternions. (2.3.4-2) is the same as [6, eqn (D-8)], with q = Q 3 q = Q 1 q = Q 2 (2.3.4-5) is equivalent to [6, eqn (D-11)], with U = r 1,U = a r 1,q = Q 1 a.

26 CHAPTER 2. 3 DOF Thus (D-11) is equivalent to (2.3.1-10), if we set: Q x = q 1 Q y = q 2 Q z = q 3 Q s = q 4 (2.3.7-1) See derive_quat_times_vect_wertz.maxima for detailed proof. Now consider comining passive rotations, as in (2.3.4-6). In Wertz s notation, this is: q = qq U = q Uq U = q q Uqq Thus, in our notation, c Q is the second passive rotation, and is on the left, while in Wertz, q is the second passive rotation, and is on the right. This corresponds to whether the non-conjugate is on the left or the right in (2.3.4-5); Wertz uses the right-multiply convention. (2.3.1-3) is equivalent to [6, eqns (12-11a) - (12-11d)], with (2.3.7-1) and φ = θ. Note that Wertz does not carefully define the direction of φ. 2.4 Matrix rotation representation 2.4.1 Reference A rotation matrix is a 3 y 3 orthonormal matrix, with determinant +1. The inverse of a rotation matrix is given y the transpose: M 1 = M T (2.4.1-1) The active rotation matrix a M 1 2 equivalent to the active angle axis rotation defined in (2.2.1-1) is given y: a M 1 2 = (2.4.1-2) cosθ 1 2 + n 2 x versθ 1 2 n z sinθ 1 2 + n x n y versθ 1 2 n y sinθ 1 2 + n x n z versθ 1 2 n z sinθ 1 2 + n x n y versθ 1 2 cosθ 1 2 + n 2 y versθ 1 2 n x sinθ 1 2 + n y n z versθ 1 2 n y sinθ 1 2 + n x n z versθ 1 2 n x sinθ 1 2 + n y n z versθ 1 2 cosθ 1 2 + n 2 zversθ 1 2 where versθ 1 2 = 1 cosθ 1 2.

2.4. MATRIX ROTATION REPRESENTATION 27 To otain the angle axis from an active rotation matrix: if a > 0 then a = (Mxy M yx ) 2 + (M zx M xz ) 2 + (M yz M zy ) 2 = M xx + M yy + Mzz 1 2 θ 1 2 = atan2(a, ) 2 aˆn = (M yz M zy, M zx M xz, M xy M yx ) 2a (2.4.1-3) else aˆn = (1, 0, 0) end if To otain the active rotation matrix a M 1 2 equivalent to the active unit quaternion a Q 1 2 : a M 1 2 = 1 2Q 2 z 2Q2 y 2Q x Q y 2Q s Q z 2Q x Q z + 2Q s Q y 2Q s Q z + 2Q x Q y 1 2Q 2 z 2Q 2 x 2Q y Q z 2Q s Q x 2Q x Q z 2Q s Q y 2Q y Q z + 2Q s Q x 1 2Q 2 y 2Q2 x (2.4.1-4) To otain the active quaternion a Q 1 2 from the active rotation matrix a M 1 2 : a = M xx + M yy + M zz = M xx M yy M zz c = M xx + M yy M zz d = M xx M yy + M zz (2.4.1-5) if a > max(, max(c, d)) then e = 2 1 + a Q x = M zy M yz e Q y = M xz M zx e Q z = M yx M xy e Q s = e 4

28 CHAPTER 2. 3 DOF elsif > max(a, max(c, d)) then e = 2 1 + elsif c > max(a, max(, d)) then else end if Q x = e 4 Q y = M xy + M yx e Q z = M xz + M zx e Q s = M zy M yz e e = 2 1 + c Q x = M xy + M yx e Q y = e 4 Q z = M yz + M zy e Q s = M xz M zx e e = 2 1 + d Q x = M xz + M zx e Q y = M yz + M zy e Q z = e 4 Q s = M yx M xy e It may e desireale to normalize the quaternion after applying (2.4.1-5), to eliminate roundoff errors, or small orthogonality errors in the original matrix. To rotate a vector using a rotation matrix, use normal matrix multiply: r = Mr (2.4.1-6) If M is an active matrix (ie, it represents an active rotation), r is a rotated vector: r = a r 2 = a M 1 2 a r 1 (2.4.1-7)

2.4. MATRIX ROTATION REPRESENTATION 29 If M is a passive rotation, r is r expressed in a different frame: r = r 1 = M a a r 1 (2.4.1-8) To multiply rotation matrices, use normal matrix multiply: M c = M a M (2.4.1-9) If the matrices are active, this represents two successive physical rotations: a r 3 = a M a 2 3 M a 1 2 r 1 (2.4.1-10) If the matrices are passive, this represents two successive coordinate transforms: c r 1 = c M M a a r 1 (2.4.1-11) Right-multiply Since the SAL math lirary does not provide right-multiply matrices, we do not present them here. 2.4.2 Coding The type SAL.Gen_Math.Gen_DOF_3.Rot_Matrix_Type implements the orthonormal matrix rotation representation. The child packages SAL.Gen_Math.Gen_DOF_3.Gen_Left and SAL.Gen_Math.Gen_DOF_3.Gen_Wertz oth provide left-multiply rotation matrix operations. Right-multiply rotation matrix operations are not provided. A variale representing the passive left-multiply rotation matrix a M is written A_Rot_Mat_B. In the GN&C convention the passive left multiply matrix a M is writtendcm_btoa. SAL.Math_Doule.Dof_3.Left.To_Unit_Quaternion implements (2.4.1-5); SAL.Math_Doule.Dof_3.Wertz.To_Unit_Quaternion implements (2.4.1-5) with an additional inverse, so that the result represents the same rotation (the left multiply quaternion is the numerical inverse of the right multiply quaternion). 2.4.3 Examples See spacecraft_math_examples.ad, Rot_Matrix lock for Ada code implementing these. This example is the same as the first one in 2.3.3, ut using left-multiply rotation matrices. Since the primary use of rotation matrices is to convert them to quaternions, the other examples are not relevant.

30 CHAPTER 2. 3 DOF An active rotation of a vector in the x-z plane in a positive direction aout the y axis. ase M 1 2 = to rot matrix(θ 1 2, aseˆn) = to rot matrix(0.1, (0.0, 1.0, 0.0)) 0.99500 0.00000 0.09983 = 0.00000 1.00000 0.00000 0.09983 0.00000 0.99500 ase Q 1 2 = to unit quaternion( ase M 1 2 ) = (0.00000, 0.04998, 0.00000, 0.99875) ase r 1 = (2.0, 0.0, 1.0) ase r 2 = ase M ase 1 2 r 1 = (2.08984, 0.00000, 0.79534) 2.4.4 Derivations (2.4.1-6) is simply the definition of matrix multiplication. (2.4.1-9) is the correct way to comine rotations, ecause of the associativity of matrix multiply. (2.4.1-3) is derived from (2.2.1-5) y finding the coefficient matrix for a r 1 ; see derive_angle_axis_to_rot_matrix.maxima for details. To derive (2.4.1-3), start with (2.4.1-3), take various cominations of M ij, and use n 2 x + n2 y + n2 z = 1. M xy M yx = 2n z sin(θ) (2.4.4-1) M zx M xz = 2n y sin(θ) (2.4.4-2) M yz M zy = 2n x sin(θ) (2.4.4-3) M xx + M yy + Mzz = 3cos(θ) + (n 2 x + n 2 y + n 2 z)vers(θ) = 1 + 2cos(θ) (2.4.4-4) Now we can find θ from (2.4.4-1), (2.4.4-2), (2.4.4-3), and (2.4.4-4): (Mxy M yx ) sin(θ) = 2 + (M zx M xz ) 2 + (M yz M zy ) 2 2 cos(θ) = M xx + M yy + Mzz 1 2 θ = atan2(sin(θ), cos(θ)) (2.4.4-5) Note we have chosen sin(θ) >= 0, so we have 0 <= θ < π. The axis n is found y: ˆn = (M yz M zy, M zx M xz, M xy M yx ) 2sin(θ) (2.4.4-6)

2.4. MATRIX ROTATION REPRESENTATION 31 This is singular when sin(θ) = 0. Consider θ = ǫ; then cos(theta) = 1, sin(theta) = ǫ, and (2.4.4-6) ecomes: ˆn = (2n xǫ, 2n y ǫ, 2n z ǫ) 2ǫ (2.4.4-7) This is well ehaved unless sin(θ) is exactly zero. In that case, the axis is indeterminate, so we simply choose the x axis. See derive_rot_matrix_to_angle_axis.maxima for details of the aove derivation. To derive (2.4.1-4), start with (2.3.1-8), and find the coefficients of each vector component; see derive_quat_to_rot_matrix.maxima. To derive (2.4.1-5), start with the diagonal elements of (2.4.1-4), and (2.3.1-2); this gives us four equations in the four unknowns Q 2 i. We solve for one of them (call it Q j ); then we can take various cominations of M ij and divide y Q j to find the remaining Q i. We want the largest magnitude divisor, to avoid singularities. So first we need to decide which divisor is the largest. 1 = Q 2 s + Q2 x + Q2 y + Q2 z M xx = 1 2Q 2 z 2Q2 y M yy = 1 2Q 2 z 2Q 2 x M zz = 1 2Q 2 y 2Q2 x (2.4.4-8) To solve for Q s : M xx + M yy + M zz = 1 2Q 2 z 2Q2 y + 1 2Q 2 z 2Q 2 x + 1 2Q 2 y 2Q2 x = 3 4(Q 2 x + Q2 y + Q2 z ) = 3 4(1 Q 2 s) = 1 + 4Q 2 s Q s = 1 + Mxx + M yy + M zz 4 (2.4.4-9) To solve for Q x : M xx M yy M zz = 1 2Q 2 z 2Q 2 y 1 + 2Q 2 z + 2Q2 x 1 + 2Q 2 y + 2Q 2 x = 1 + 4Q 2 x Q x = 1 + Mxx M yy M zz 4 (2.4.4-10)

32 CHAPTER 2. 3 DOF Q y and Q z are similar. Thus to pick the largest magnitude divisor, we find the maximum of the four cominations of M ii : a = M xx + M yy + M zz = M xx M yy M zz c = M xx + M yy M zz d = M xx M yy + M zz (2.4.4-11) Now we can take various cominations of M ij and divide y Q j. For example, to find Q x when we have Q s : M zy M yz = 2Q y Q z + 2Q s Q x (2Q y Q z 2Q s Q x ) = 4Q s Q x Q x = M zy M yz 4Q s (2.4.4-12) Similarly for the other Q i. Note we can save some computations y first computing 4Q j instead of Q j. See derive_rot_matrix_to_quat.maxima for full details. 2.4.5 Comparison to Kane (2.4.1-8) corresponds to [4, eqn 1.2(9)]: B v = A v A C B However, Kane uses the right-multiply convention for matrices. Thus A C B is related to our notation y M a = A C B. (2.4.1-3) corresponds to [4, eqn 1.2(23)-(31)]. However, Kane s C is a passive matrix corresponding to an active angle axis rotation, using the right-multiply convention, while a M is an active matrix using the left-multiply convention. These two differences cancel, and we have a M = C. (2.4.1-4) is similar to [4, eqn 1.3(6)-(14)]. However, Kane s C is a right-multiplying passive matrix, while our a M is a left-multiply active matrix. The quaternions are the same. Thus we have C = a M. (2.4.1-5) is similar to [4, 1.3(6)-(14)]. In addition to the differences in the matrix convention, Kane does not consider the singularity. Similarly, (2.4.1-11) is similar to [4, eqn 1.6(4)].

2.5. ROTATION VECTOR REPRESENTATION 33 2.4.6 Comparison to Wertz (2.4.1-8) is the same as [6, eqn (12-4)]. Note that Wertz s notation does not include frames. (2.4.1-3) corresponds to [6, eqn (12-7a)], with φ = θ 1 2, except that Wertz s A is an active left-multiply matrix (see figure 12-2), so the matrix is inverted (transposed). (2.4.1-3) is similar to [6, eqn (12-9) - (12-10c)], ut Wertz does not consider the singularity. (2.4.1-4) is equivalent to [6, eqn (12-13a)], with (2.3.7-1). Note that Wertz s q is right-multiply, while our a Q is left-multiply; the matrices are oth leftmultiply. (2.4.1-5) is equivalent to [6, eqns (12-14a) - 12-14d)], with (2.3.7-1), and we have slightly optimized the handling of the singularity. 2.5 Rotation vector representation 2.5.1 Reference A rotation vector comines the magnitude and axis information into one vector: θ = θˆn (2.5.1-1) where θ is the magnitude of the rotation, and ˆn is the rotation axis. This is useful mainly for differential rotations, since then the rotation vectors can simply e added. To find the rotation vector from a quaternion or rotation matrix: (θ, ˆn) = to angle axis(r) where to angle axis is either (2.3.1-7) or (2.4.1-3). θ = θ ˆn (2.5.1-2) To find a quaternion or rotation matrix from a rotation vector: θ = θ ˆn = θ/θ Q = to unit quaternion(θ, ˆn) (2.5.1-3) M = to rot matrix(θ, ˆn) (2.5.1-4)

34 CHAPTER 2. 3 DOF where to unit quaternion is given y (2.3.1-3), and to rot matrix is given y (2.4.1-3). (2.5.1-3) defines the function rotvect to quat. An important case is otaining the rotation due to a rotational velocity acting over a finite time; see section 2.6.1. 2.5.2 Coding The type SAL.Gen_Math.DOF_3.Cart_Vector_Type is used for the rotation vector representation; there are functions to convert etween rotation vectors and quaternions. A variale representing the active rotation vector a θ 1 2 is writtena_rot_vect_1_2 when using the left-multiply convention, 1_2_Rot_Vect_A when using the rightmultiply convention. 2.6 Rate 2.6.1 Reference The time rate of change of the position of an oject is called the translation rate or velocity of an oject. It is defined y the time rate of change of the position of a point fixed in the oject (normally the origin of the oject s coordinate frame). The translation rate is measured relative to a ase frame, and is expressed in a coordinate frame. To indicate all these frames, we use the notation coord ase v oj. Often we need to deal with velocities measured in frames that are moving with respect to each other. Assume frame is moving with velocity a a v with respect to frame a; framesaand are parallel. The velocity a av oj with respect to frame a given the velocity with respect to frame is computed y: a a v oj = a v oj + a a v (2.6.1-1) However, if the velocities involved are a significant fraction of the speed of light,

2.6. RATE 35 this must e replaced y the Lorentz transform: a v oj = a a v oj aa v a a v 2 a a v v oj = a v oj a v oj γ = 1 a av 2 c 2 a a v oj = see section 4.1.1 for one use of this. a a v + a v oj + γ a v oj 1 + a v oj aa v (2.6.1-2) c 2 The time rate of change of orientation of an oject is called the rotation rate of an oject. It is defined y the time rate of change of an oject frame (rigidly attached to the oject). An oject rate is measured relative to a ase frame, and is expressed in a coordinate frame. To indicate all these frames, we use the notation ref ase ω oj. ω is called a rotation velocity vector. Usually, the ase frame is an inertial frame, and is not specified. In order to integrate the rotation position of a ody over time, or to compute the rotation rate from a sequence of rotation positions, we need to show how to relate ω to the time derivative of the orientation of an oject. In the SAL convention the orientation of an oject is represented y a passive quaternion that transforms vectors in the oject frame to the ase frame: ase r a = ase Q oj oj r a (2.6.1-3) In the GNC (right-multiply) convention, the orientation of an oject is represented y ase Q oj. If the rotation rate of the oject oj ω oj is constant over a finite time, the resultant active rotation of the oject from time t 1 to time t 2 is: oj θ t1 t 2 = oj ω oj (t 2 t 1 ) (2.6.1-4) Left-multiply A passive left-multiply quaternion equivalent to the active rotation oj θ t1 t 2 is (see (2.5.1-3)): t 1 Q t2 = rotvect to quat( oj θ t1 t 2 ) (2.6.1-5) Note that the reference frame of the rotation vector must e the oject frame at time t1 or t2 for this operation to e valid; see (2.3.1-15).

36 CHAPTER 2. 3 DOF A series of finite passive rotations can e comined to give a sequence of oject orientations: ase Q t2 = ase Q t1 t 1 Q t2 (2.6.1-6) ase Q t3 = ase Q t2 t 2 Q t3 (2.6.1-7) Then we can compute the rate oj ω oj from the sequence: oj ω oj = quat to rotvect( ase Q 1 t 1 ase Q t2 )/(t 2 t 1 ) (2.6.1-8) ω ehaves like a vector under coordinate transforms: ω = a Q 1 a ω a (2.6.1-9) Note that since frames a and oj are oth rigidly attached to the same oject at the same point, we can simply change the lael on a ω oj. The translational velocity of a point on the rotating ody is given y: oj v 1 = oj ω oj oj r 1 (2.6.1-10) This can e expressed as a left-multiply matrix operator: a v 1 = a r a 1 ω a a r 1 = 0 r z r y r z 0 r x r y r x 0 (2.6.1-11) Right-multiply SAL convention: GNC convention: t 2 Q t1 = rotvect to quat( oj θ t1 t 2 ) (2.6.1-12) t 2 Q ase = t2 Q t1 t 1 Q ase (2.6.1-13) oj ω oj = quat to rotvect( t2 Q ase t 1 Q ase 1 )/(t 2 t 1 ) (2.6.1-14) t 1 Q t2 = rotvect to quat( oj θ t1 t 2 ) (2.6.1-15) aseq t2 = ase Q t1 t 1 Q t2 (2.6.1-16) oj ω oj = quat to rotvect( ase Q t1 1 aseq t2 )/(t 2 t 1 ) (2.6.1-17) Since a r 1 is a left-multiply matrix, and the SAL lirary does not provide rightmultiply matrices, there is no right-multiply version of a r 1.

2.6. RATE 37 2.6.2 Coding A variale representing frame ω oj is written Frame_Rot_Rate_Oj in the leftmultiply convention, Oj_Rot_Rate_Frame in right-multiply. A variale representing coord ase v oj is writtencoord_vel_oj_wrt_base in the left multiply convention, Oj_Wrt_Base_Vel_Coord in right-multiply. wrt means with respect to. The function SAL.Gen_Math.Gen_DOF_3.Lorentz_Transform implements (2.6.1-2). 2.6.3 Examples See spacecraft_math_examples.ad, Rotation_Rate_Left lock for Ada code implementing these. To clarify the difference etween active and passive rotations, we relate all rotations to the oresight of a star tracker mounted on a spacecraft. First we present the example using SAL convention left-multiply quaternions, then SAL and GNC orientation conventions for right-multiply quaternions. Note that the oresight vector, and the spacecraft rate vector, are the same for all three representations, ut the quaternions are different. We use the International Celestial Reference Frame (ICRF) as the ase frame for this example. In the star tracker frame st, the oresight stˆn ore is a constant. Assume the initial star tracker orientation is ICRF Q st,t1 ; a passive quaternion. Then rotate it y 0.1 radians aout the X axis in 0.5 seconds (an active rotation), to orientation ICRF Q st,t2, and compute the oresight in ICRF in oth

38 CHAPTER 2. 3 DOF orientations: stˆn ore = (0.0, 0.0, 1.0) ICRF Q st,t1 = (0.04998, 0.00000, 0.00000, 0.99875) ICRF ˆn ore,t1 = ICRF Q st,t1 stˆn ore = (0.00000, 0.09983, 0.99500) θ = 0.1 (t 2 t 1 ) = 0.5 st ω st = ( θ/(t 2 t 1 ), 0.0, 0.0) = (0.20000, 0.00000, 0.00000) ICRF Q st,t1 t 2 = rotvect to quat( st ω st (t 2 t 1 )) = (0.04998, 0.00000, 0.00000, 0.99875) = st,t1 Q st,t2 ICRF Q st,t2 ICRF ˆn ore,t2 = ICRF Q st,t1 st,t 1 Q st,t2 = (0.09983, 0.00000, 0.00000, 0.99500) = ICRF Q st,t2 stˆn ore = (0.00000, 0.19867, 0.98007) Now we have two ways to compute the rate; from the two oresight unit vectors, and from the two orientation quaternions: st,t 1 Q st,t2,a = ICRF Q st,t1 t 2 = units to quat( ICRF ˆn ore,t1, ICRF ˆn ore,t2 ) = (0.04998, 0.00000, 0.00000, 0.99875) st,t 1 Q st,t2, = ICRF Q 1 st,t ICRF 1 Q st,t2 = (0.04998, 0.00000, 0.00000, 0.99875) st ω st = quat to rotvect( st,t1 Q st,t2 )/(t 2 t 1 ) = (0.20000, 0.00000, 0.00000)