Quaternion type: Difference between revisions
Content added Content deleted
m (changed order of two words (to read better).) |
(useg a bigger font as CODE doesn't show subscripts very clearly, use a true "not equal" symbol instead of !=, elided some pronouns, split some long sentences (which contain WHERE), added other whitespace and highlighting to the task's preamble.) |
||
Line 3: | Line 3: | ||
[[wp:Quaternion|Quaternions]] are an extension of the idea of [[Arithmetic/Complex|complex numbers]]. |
[[wp:Quaternion|Quaternions]] are an extension of the idea of [[Arithmetic/Complex|complex numbers]]. |
||
A complex number has a real and complex part, sometimes written as <code>a + bi</code> |
A complex number has a real and complex part, sometimes written as <big> <code> a + bi, </code> </big> |
||
<br>where <big> <code> a </code> </big> and <big> <code> b </code> </big> stand for real numbers, and <big> <code> i </code> </big> stands for <big> <math> \sqrt{-1}</math>. </big> |
|||
An example of a complex number might be <code>-3 + 2i</code> |
An example of a complex number might be <big> <code> -3 + 2i, </code> </big> |
||
<br>where the real part, <big> <code> a </code> </big> is <big> <code> '''-3.0''' </code> </big> and the complex part, <big> <code> b </code> </big> is <big> <code> '''+2.0'''. </code> </big> |
|||
A quaternion has one real part and ''three'' imaginary parts, i, j, and k. |
A quaternion has one real part and ''three'' imaginary parts, <big> <code> i, </code> </big> <big> <code> j, </code> </big> and <big> <code> k. </code> </big> |
||
A quaternion might be written as <code>a + bi + cj + dk</code> |
A quaternion might be written as <big> <code> a + bi + cj + dk. </code> </big> |
||
In this numbering system |
In this numbering system: |
||
:::* <big> <code> i∙i = j∙j = k∙k = i∙j∙k = -1, </code> </big> or more simply, |
|||
:::* <big> <code> ii = jj = kk = ijk = -1. </code> </big> |
|||
The order of multiplication is important, as, in general, for two quaternions |
The order of multiplication is important, as, in general, for two quaternions: |
||
:::: <big> <code> q<sub>1</sub> </code> </big> and <big> <code> q<sub>2</sub>: </code> </big> <big> <code> q<sub>1</sub>q<sub>2</sub> ≠ q<sub>2</sub>q<sub>1</sub>. </code> </big> |
|||
An example of a quaternion might be <code>1 +2i +3j +4k</code> |
An example of a quaternion might be <big> <code> 1 +2i +3j +4k </code> </big> |
||
There is a list form of notation where just the numbers are shown and the imaginary multipliers i, j, and k are assumed by position. |
There is a list form of notation where just the numbers are shown and the imaginary multipliers <big> <code>i, </code> </big> <big> <code> j, </code> </big> and <big> <code> k </code> </big> are assumed by position. |
||
So the example above would be written as (1, 2, 3, 4) |
So the example above would be written as <big> <code> (1, 2, 3, 4) </code> </big> |
||
;Task: |
;Task: |
||
Given the three quaternions and their components: |
Given the three quaternions and their components: <big> |
||
q = (1, 2, 3, 4) = (a,<sub> </sub> b,<sub> </sub> c,<sub> </sub> d |
q = (1, 2, 3, 4) = (a,<sub> </sub> b,<sub> </sub> c,<sub> </sub> d) |
||
q<sub>1</sub> = (2, 3, 4, 5) = (a<sub>1</sub>, b<sub>1</sub>, c<sub>1</sub>, d<sub>1</sub>) |
q<sub>1</sub> = (2, 3, 4, 5) = (a<sub>1</sub>, b<sub>1</sub>, c<sub>1</sub>, d<sub>1</sub>) |
||
q<sub>2</sub> = (3, 4, 5, 6) = (a<sub>2</sub>, b<sub>2</sub>, c<sub>2</sub>, d<sub>2</sub>) |
q<sub>2</sub> = (3, 4, 5, 6) = (a<sub>2</sub>, b<sub>2</sub>, c<sub>2</sub>, d<sub>2</sub>) </big> |
||
And a wholly real number <code>r = 7</code> |
And a wholly real number <big> <code> r = 7. </code> </big> |
||
Create functions (or classes) to perform simple maths with quaternions including computing: |
|||
# The norm of a quaternion:<br><math>= \sqrt{a^2 + b^2 + c^2 + d^2}</math> |
# The norm of a quaternion: <br> <big> <code> <math> = \sqrt{ a^2 + b^2 + c^2 + d^2 } </math> </code> </big> |
||
# The negative of a quaternion:<br><code>=(-a, -b, -c, -d)</code> |
# The negative of a quaternion: <br> <big> <code> = (-a, -b, -c, -d)</code> </big> |
||
# The conjugate of a quaternion:<br><code>=( a, -b, -c, -d)</code> |
# The conjugate of a quaternion: <br> <big> <code> = ( a, -b, -c, -d)</code> </big> |
||
# Addition of a real number r and a quaternion q:<br><code>r + q = q + r = (a+r, b, c, d)</code> |
# Addition of a real number <big> <code> r </code> </big> and <big> <code> a </code> </big> quaternion <big> <code> q: </code> </big> <br> <big> <code> r + q = q + r = (a+r, b, c, d) </code> </big> |
||
# Addition of two quaternions:<br><code>q<sub>1</sub> + q<sub>2</sub> = (a<sub>1</sub>+a<sub>2</sub>, b<sub>1</sub>+b<sub>2</sub>, c<sub>1</sub>+c<sub>2</sub>, d<sub>1</sub>+d<sub>2</sub>)</code> |
# Addition of two quaternions: <br> <big> <code> q<sub>1</sub> + q<sub>2</sub> = (a<sub>1</sub>+a<sub>2</sub>, b<sub>1</sub>+b<sub>2</sub>, c<sub>1</sub>+c<sub>2</sub>, d<sub>1</sub>+d<sub>2</sub>) </code> </big> |
||
# Multiplication of a real number and a quaternion:<br><code>qr = rq = (ar, br, cr, dr)</code> |
# Multiplication of a real number and a quaternion: <br> <big> <code> qr = rq = (ar, br, cr, dr) </code> </big> |
||
# Multiplication of two quaternions q<sub>1</sub> and q<sub>2</sub> is given by:<br><code>( a<sub>1</sub>a<sub>2</sub> − b<sub>1</sub>b<sub>2</sub> − c<sub>1</sub>c<sub>2</sub> − d<sub>1</sub>d<sub>2</sub>,</code><br><code> a<sub>1</sub>b<sub>2</sub> + b<sub>1</sub>a<sub>2</sub> + c<sub>1</sub>d<sub>2</sub> − d<sub>1</sub>c<sub>2</sub>,</code><br><code> a<sub>1</sub>c<sub>2</sub> − b<sub>1</sub>d<sub>2</sub> + c<sub>1</sub>a<sub>2</sub> + d<sub>1</sub>b<sub>2</sub>,</code><br><code> a<sub>1</sub>d<sub>2</sub> + b<sub>1</sub>c<sub>2</sub> − c<sub>1</sub>b<sub>2</sub> + d<sub>1</sub>a<sub>2</sub> )</code> |
# Multiplication of two quaternions <big> <code> q<sub>1</sub> </code> </big> and <big><code>q<sub>2</sub> </code> </big> is given by: <br> <big> <code> ( a<sub>1</sub>a<sub>2</sub> − b<sub>1</sub>b<sub>2</sub> − c<sub>1</sub>c<sub>2</sub> − d<sub>1</sub>d<sub>2</sub>, </code> <br> <code> a<sub>1</sub>b<sub>2</sub> + b<sub>1</sub>a<sub>2</sub> + c<sub>1</sub>d<sub>2</sub> − d<sub>1</sub>c<sub>2</sub>, </code> <br> <code> a<sub>1</sub>c<sub>2</sub> − b<sub>1</sub>d<sub>2</sub> + c<sub>1</sub>a<sub>2</sub> + d<sub>1</sub>b<sub>2</sub>, </code> <br> <code> a<sub>1</sub>d<sub>2</sub> + b<sub>1</sub>c<sub>2</sub> − c<sub>1</sub>b<sub>2</sub> + d<sub>1</sub>a<sub>2</sub> ) </code> </big> |
||
# Show that, for the two quaternions q<sub>1</sub> and q<sub>2</sub>:<br> |
# Show that, for the two quaternions <big> <code> q<sub>1</sub> </code> </big> and <big> <code> q<sub>2</sub>: <br> q<sub>1</sub>q<sub>2</sub> ≠ q<sub>2</sub>q<sub>1</sub> </code> </big> |
||
<br> |
<br> |
||
If |
If a language has built-in support for quaternions, then use it. |
||