Table of Contents


About this page.

Yet another attempt and getting better at computery mathematics.

The source code can be found in https://codeberg.org/kakafarm/learning/src/branch/master/learning-gamemath.com/README.org.

This time working on https://gamemath.com/.

Practical demos.

Chapter 2.

Problem 21.

Problem 22.

Chapter 1.

3.

'((r (-x -y -z)) -
  (l (+x -y -z)) +
  (l (-x +y -z)) +
  (r (+x +y -z)) -
  (l (-x -y +z)) +
  (r (+x -y +z)) -
  (r (-x +y +z)) -
  (l (+x +y +z)) +

  (l (-x -z -y)) -
  (r (+x -z -y)) +
  (r (-x +z -y)) +
  (l (+x +z -y)) -
  (r (-x -z +y)) +
  (l (+x -z +y)) -
  (l (-x +z +y)) -
  (r (+x +z +y)) +

  (l (-y -x -z))
  (r (+y -x -z))
  (r (-y +x -z))
  (l (+y +x -z))
  (r (-y -x +z))
  (l (+y -x +z))
  (l (-y +x +z))
  (r (+y +x +z))

  (r (-y -z -x))
  (l (+y -z -x))
  (l (-y +z -x))
  (r (+y +z -x))
  (l (-y -z +x))
  (r (+y -z +x))
  (r (-y +z +x))
  (l (+y +z +x))

  (r (-z -x -y))
  (l (+z -x -y))
  (l (-z +x -y))
  (r (+z +x -y))
  (l (-z -x +y))
  (r (+z -x +y))
  (r (-z +x +y))
  (l (+z +x +y))

  (l (-z -y -x))
  (r (+z -y -x))
  (r (-z +y -x))
  (l (+z +y -x))
  (r (-z -y +x))
  (l (+z -y +x))
  (l (-z +y +x))
  (r (+z +y +x)))

4.

  1. X as the right-left axis pointing right, Z as the forward-backward axis pointing forward, and Y as the up-down axis pointing up is (+x +z +y). Right hand.
  2. Swap Z and Y, keeping their direction.
  3. Swap Y and Z, keeping their direction. What…?

5.

  1. (+y -z +x) is right-handed.
  2. Swap X and Y, keeping their direction. Flip Z's direction. Swap Z and Y. I don't know if you want me to use rotations, and even with rotations, we still need to mirror the space against the plane of the other two axes.
  3. Same but from the last step of b backwards.

6.

  1. CW.
  2. CCW.
  3. CCW.
  4. CW.

7.

  1. \(15\).
  2. with distributive property we can take out the \(2\):

    \(\sum_{i=1}^{5}(2i) = 2 (\sum_{i=1}^{5} i) = 30.\)

  3. \( \prod_{i=1}^{5}(2i) = 2^5 (2 * 3 * 4 * 5) = 2^5 * 2^3 * 3 * 5 = 2^8 * 15 = 256 * 15 = 1000 + 250 + 30 + 2000 + 500 + 60 = 3000 + 750 + 90 = 3840 \)
  4. \(\prod_{i=0}^{4}(7 (i + 1)) = 7^5 (1 * 2 * 3 * 4 * 5) = 2^3 * 3^1 * 5^1 * 7^5 = blah. \)
  5. I've seen this trick before. It's a square-ish divided by two as in: \( 100 + 101 / 2 = 5050 \).

8.

  1. \( 30 \tau / 360 = 3 \tau / 36 = \tau / 12 \)
  2. There are 8 slices of \(45^{\circ}\) in a circle, therefore \(-45^{\circ} = -(\tau / 8) rad\).
  3. There are 6 slices of \(60^{\circ}\) in a circle, therefore \(60^{\circ} = (\tau / 6) rad\).
  4. There are four slices of \(90^{\circ}\) in a circle, therefore \(90^{\circ} = (\tau / 4) rad\).
  5. There are two slices of \(180^{\circ}\) in a circle, therefore \(-180^{\circ} = -(\tau / 2) rad\).
  6. \( 225\tau/360 = (40 + 5)\tau/(60 + 12) = 45\tau/72 = (10 + 5)\tau/(20 + 4) = 15\tau/24 = 5\tau/8 \)

… blah.

9.

blah!

10.

The square of the length of the hippopotamus, in a right-angled triangle, is equal to the sum of the squares of the lengths of the other two sides.

11.

  1. Show that:

    \( ( \sin(\alpha) / \csc(\alpha) ) + ( \cos(\alpha) / \sec(\alpha) ) = 1 \)

    We use the identities \( \sec(\alpha) = 1 / \cos(\alpha) \) and \( \csc(\alpha) = 1 / \sin(\alpha) \) to rewrite:

    \( ( \sin(\alpha) / (1 / \sin(\alpha)) ) + ( \cos(\alpha) / (1 / \cos(\alpha)) ) = 1 \)

    Algebraisting:

    \( \sin(\alpha)^2 + \cos(\alpha)^2 = 1 \)

    Which is one of the Pythagorean identities.

  2. Show that:

    \( ( \sec^2(\theta) - 1 ) / ( \sec^2(\theta) ) = \sin^2(\theta) \)

    Multiply both sides by \( \sec^2(\theta) \):

    \( \sec^2(\theta) - 1 = \sin^2(\theta) * \sec^2(\theta) \)

    Replace \( \sec(\theta) = 1 / \cos(\theta) \), that is, \( \sec^2(\theta) = 1 / \cos^2(\theta) \):

    \( \sec^2(\theta) -1 = \sin^2(\theta) / \cos^2(\theta) \)

    Replace \( \sin(\theta) / \cos(\theta) = \tan(\theta) \):

    \( \sec^2(\theta) - 1 = \tan^2(\theta) \)

    Add \( 1 \) to both sides:

    \( 1 + \tan^2(\theta) = \sec^2(\theta) \)

    We got one of the Pythagorean identities.

  3. Show that \( 1 + \cot^2(t) = csc^2(t) \).

    ?! It is already one of the known identities.

    In the unit circle, this is rewriten as \( 1 + (x/y)^2 = (r/y)^2 \).

    Power distribution law of \((a / b)2 = a2 / b2):

    \( 1 + x^2/y^2 = r^2 / y^2 \)

    It's the unit circle, so replace \(r = 1\):

    \( 1 + x^2/y^2 = 1 / y^2 \)

    Substract \(x^2/y^2\) on both side:

    \( 1 = 1 / y^2 - x^2/y^2 \)

    Division manipulation:

    \( 1 = (1 - x^2) / y^2 \)

    Pythagoras said \(r^2 = x^2 + y^2\) and we are on a unit circle, therefore \(1 = x^2 + y^2\), and after subtracting \(x^2\) from both sides we get \(1 - x^2 = y^2\). Replace \(1-x^2\) with \(y^2\):

    \( 1 = y^2 / y^2 \)

    Same divided with same equals \( 1 \):

    \( 1 = 1 \)

  4. Show that \( \cos(\phi) ( \tan(\phi) + \cot(\phi) ) = \csc(\phi) \).

    Distribute \(\cos(\phi)\) onto \(\tan(\phi) + \cot(\phi)\) and replace \(\tan = \sin / \cos\) and \(\cot = \cos / \sin\).

    \( \cos(\phi)\sin(\phi)/\cos(\phi) + \cos(\phi)\cos(\phi)/\sin(\phi) = 1/\sin(\phi) \)

    Same divided with same equals one and some multiplying same with same is same with the power of two.

    \( \sin(\phi) + \cos^2(\phi)/\sin(\phi) = 1/\sin(\phi) \)

    Multiply both sides by \(\sin(\phi)\).

    \( \sin^2(\phi) + \cos^2(\phi) = 1 \)

    Which is a Pythagorean identity.

Chapter 2.

1.

Let \( a = [-3 \ 8], b = \begin{bmatrix} 4 \\ 0 \\ 5 \end{bmatrix}, c = \begin{bmatrix} 16 \\ -1 \\ 4 \\ 6 \end{bmatrix}. \)

    • \(a\) is a row vector of dimension 2.
    • \(b\) is a column vector of dimension 3.
    • \(c\) is a column vector of dimension 4.
  1. \(b_y + c_w + a_x + b_z = 8 + 6 + (-3) + 5 = 16\).

2.

  1. Weight is scalar.
  2. Speed is scalar.
  3. Two blocks north is a vector. Two blocks magnitude north is the direction.
  4. 600 mph is the magnitude and Los Angeles to New York is the direction. 33k feet is a 33k feet magnitude vector directed at the zenith.

3.

  1. \(

a = [0 \ 2], b = -a, c = [0.5 \ 2], d = c, e = [0.5 \ -3], f = [-2 \ 0], g = [-2 \ 1], h = [2.5 \ 2], i = [6 \ 1]. \)

4.

  1. False. Vectors are defined by magnitude and direction. They have no location.
  2. True. \([a_1 \ a_2 \ ... \ a_n] = [a_1 \ 0 \ ... \ 0] + [0 \ a_2 \ ... \ 0] + ... + [0 \ 0 \ ... \ a_n]\).
  3. False, due to the commutativity of vector addition.
  4. False, it gives the displacement from the origin to the point. Multiply the vector by the scalar \(-1\) to get the vector from the point to the origin.

5.

  1. \(-[3 \ 7] = [-3 \ -7]\).
  2. \(\|[-12 \ 5]\| = \sqrt((-12) * (-12) + 5 * 5) = \sqrt(144 + 25) = \sqrt(169 \textnormal{nice}) = 13\).
  3. \(\|[8 \ -3 \ 1/2]\| = \sqrt(8 * 8 + (-3) * (-3) + (1/2) * (1/2)) = \sqrt(64 + 9 + 1/4) = \sqrt(73.25)\).
  4. \(3[4 \ -7 \ 0] = [12 \ -21 \ 0]\).
  5. \([4 \ 5]/2 = [2 \ 2.5]\).

6.

  1. \([12 \ 5] / \|[12 \ 5]\| = [12 / 13 \ 5 / 13]\).
  2. \([0 \ 743.632] / \|[0 \ 743.632]\| = [0 \ 1]\).
  3. \([8 \ -3 \ 1/2] / \|[8 \ -3 \ 1/2]\| = [8 \ -3 \ 1/2] / \sqrt(73.25)\).
  4. \([-12 \ 3 \ -4] / \|[-12 \ 3 \ -4]\| = [-12 \ 3 \ -4] / 13 = \).
  5. \([1 \ 1 \ 1 \ 1] / \|[1 \ 1 \ 1 \ 1]\| = [1 \ 1 \ 1 \ 1] / sqrt(4) = [0.5 \ 0.5 \ 0.5 \ 0.5]\).

7.

  1. \( [7 \ -2 \ -3] + [6 \ 6 \ -4] = [7 + 6 \ (-2) + 6 \ (-3) + (-4)] = [13 \ 4 \ -7] \).
  2. \( [2 \ 9 \ -1] + [-2 \ -9 \ 1] = [2 + (-2) \ 9 + (-9) \ (-1) + 1] = [0 \ 0 \ 0] \).
  3. …

8.

Call the left vector \(a\) and the right vector \(b\).

  1. \( \left\|\begin{bmatrix} 10 - (-14) \\ 6 - 30 \\ \end{bmatrix}\right\| = \sqrt(24 * 24 + 24 * 24) = \sqrt(1152) \).
  2. \(\sqrt(12 * 12 + 25) = 13\).
  3. \( \sqrt((3 - 8)^2 + (10 - (-7))^2 + (7 - 4)^2) = \sqrt(25 + 289 + 9) = \sqrt(323) \).
  4. \(\sqrt((-2 - 6)^2 + ((-4) - (-7))^2 + (9 - 9.5)^2)\)…

9.

  1. \(\begin{bmatrix} 2 \\ 6 \end{bmatrix} \cdot \begin{bmatrix} -3 \\ 8 \end{bmatrix} = 2*(-3) + 6*8 = -6 + 48 = 42\).
  2. \(-7[1 \ 2] \cdot [11 \ -4] = (-7)*1*11 + (-7)*11*(-4) = -77 + 28*11 = -77 + 8 + 80 + 20 + 200 = 11 + 220 = 231\)
  3. \( 10 + (-5) * 4 + 1 * (-13) + 3 * 9 = 10 + (-20) + (-13) + 27 = 4 \)
  4. \(3 \begin{bmatrix} -2 \\ 0 \\ 4 \end{bmatrix} \cdot \left ( \begin{bmatrix} 8 \\ -2 \\ 3/2 \end{bmatrix} + \begin{bmatrix} 0 \\ 9 \\ 7 \end{bmatrix} \right ) = 3 \begin{bmatrix} -2 \\ 0 \\ 4 \end{bmatrix} \cdot \left ( \begin{bmatrix} 8 \\ 7 \\ 8.5 \end{bmatrix} \right ) = 3 * (-2) * 8 + 3 * 0 * 7 + 3 * 4 * 8.5 = -48 + 0 + 12 * 8.5 = -48 + 6 + 16 + 80 = -48 + 22 + 80 = -26 + 80 = 54 \)

10.

\(v = \begin{bmatrix} 4 \\ 3 \\ -1 \end{bmatrix}, \hat{n} = \begin{bmatrix} \sqrt(2)/2 \\ \sqrt(2)/2 \\ 0 \end{bmatrix}\).

Parallel to \(\hat{n}\):

\(\hat{n} (\hat{n} \cdot v) = \hat{n} (4 * \sqrt(2)/2 + 3 * \sqrt(2)/2) = \hat{n} \sqrt(2) (2 + 3/2) = \hat{n} \sqrt(2) 7/2 = \begin{bmatrix} 7 \sqrt(2)^2 / 4 \\ 7 \sqrt(2)^2 / 4 \\ 0 \end{bmatrix}\)

Perpendicular to \(\hat{n}\):

\(\hat{n} \times v = \begin{bmatrix} 3*0 - (-1)*(\sqrt(2)/2) \\ (-1)*(\sqrt(2)/2) - 4*0 \\ 4*(\sqrt(2)/2) - 3*(\sqrt(2)/2) \end{bmatrix} = \begin{bmatrix} \sqrt(2)/2 \\ -\sqrt(2)/2) \\ \sqrt(2)/2 \end{bmatrix}\)

11.

Show the law of cosines using \(a \cdot b = \|a\| \|b\| \cos(\theta)\).

Law of cosines:

For triangle sides \(a, b, c\), and their opposite angles \(\alpha, \beta, \gamma\) (of corners \(A, B, C\)).

\(a^2 = b^2 + c^2 - 2bc\cos(\alpha)\)

\(b^2 = a^2 + c^2 - 2ac\cos(\beta)\)

\(c^2 = a^2 + b^2 - 2ab\cos(\gamma)\)

\(\vec{a}\) is the vector pointing from \(B\) to \(C\) or \(C\) to \(B\), \(\vec{b}\) from \(C\) to \(A\) or \(A\) to \(C\), and \(vec{c}\) from \(B\) to \(A\) or \(A\) to \(B\). Their magnitude are each equal to the sides \(a, b, c\).

We know that \(\|\vec{c}\| = \|\vec{a} + \vec{b}\|\)

The LHS is equal to:

\(\sqrt(\vec{c} \cdot \vec{c})\)

The RHS is equal to:

\(\sqrt((\vec{a} + \vec{b}) \cdot (\vec{a} + \vec{b})) =\)

\(\sqrt((\vec{a} \cdot (\vec{a} + \vec{b}) + \vec{b} \cdot (\vec{a} + \vec{b}))) =\)

\(\sqrt(\vec{a} \cdot \vec{a} + \vec{a} \cdot \vec{b} + \vec{b} \cdot \vec{a} + \vec{b} \cdot \vec{b}) =\)

\(\sqrt(\|\vec{a}\|^2 + \vec{a} \cdot \vec{b} + \vec{b} \cdot \vec{a} + \|\vec{b}\|^2) =\)

\(\sqrt(\|\vec{a}\|^2 + 2 \vec{a} \cdot \vec{b} + \|\vec{b}\|^2) =\)

\(\sqrt(\|\vec{a}\|^2 + 2 \vec{a} \cdot \vec{b} + \|\vec{b}\|^2)\)

Raise by the power of two.

\(\|\vec{c}\|^2 =\|\vec{a}\|^2 + 2 \vec{a} \cdot \vec{b} + \|\vec{b}\|^2\)

Reorder.

\(\|\vec{c}\|^2 =\|\vec{a}\|^2 + \|\vec{b}\|^2 + 2 \vec{a} \cdot \vec{b}\)

The angle \(\gamma\) is the one at the intersection of side \(a\) and side \(b\), so we can use the definition of dot product, \(\vec{a} \cdot \vec{b} = \|\vec{a}\| \|\vec{b}\| \cos{\gamma}\).

\(\|\vec{c}\|^2 =\|\vec{a}\|^2 + \|\vec{b}\|^2 + 2 \|\vec{a}\| \|\vec{b}\| \cos(\gamma)\)

Replace normals with the name of the sides.

\(c^2 = a^2 + b^2 + 2 a b \cos(\theta)\)

11. second attempt.

Show the law of cosines using \(a \cdot b = \|a\| \|b\| \cos(\theta)\).

Law of cosines says that for triangle sides \(a, b, c\), and their opposite angles \(\alpha, \beta, \gamma\) (of corners \(A, B, C\)).

\(a^2 = b^2 + c^2 - 2bc\cos(\alpha)\)

\(b^2 = a^2 + c^2 - 2ac\cos(\beta)\)

\(c^2 = a^2 + b^2 - 2ab\cos(\gamma)\)

\(\vec{a}\) is the vector pointing from \(B\) to \(C\) or \(C\) to \(B\) and has the magnitude of the side \(a\), \(\vec{b}\) points from \(C\) to \(A\) or \(A\) to \(C\) and has the magnitude of side \(b\), \(vec{c}\) points from \(B\) to \(A\) or \(A\) to \(B\) and has the magnitude of side \(c\).

Take \(c^2 = a^2 + b^2 - 2ab\cos(\gamma)\).

Consider the LHS.

\(c^2\)

Replace length of side \(c\) with the distance of \(\vec{c}\).

\(\|\vec{c}\|^2\)

Deconstructing it to its axis aligned parts.

\(c_x^2 + c_y^2\)

Consider the RHS.

\(a^2 + b^2 - 2ab\cos(\gamma)\)

Replace lengths of sides with their vector magnitudes.

\(\|\vec{a}\|^2 + \|\vec{b}\|^2 - 2\|\vec{a}\|\|\vec{b}\|\cos(\gamma)\)

Use the vector magnitude defined as dot product.

\(\vec{a} \cdot \vec{a} + \vec{b} \cdot \vec{b} - 2\|\vec{a}\|\|\vec{b}\|\cos(\gamma)\)

Deconstruct vectors to their axis aligned parts.

\(a_x^2 + a_y^2 + b_x^2 + b_y^2 - 2(a_x^2 + a_y^2)(b_x^2 + b_y^2)\cos(\gamma)\)

Distribute multiplication over addition.

\(a_x^2 + a_y^2 + b_x^2 + b_y^2 - 2(a_x^2(b_x^2 + b_y^2) + a_y^2(b_x^2 + b_y^2))\cos(\gamma)\)

And \(a_x^2 + a_y^2 + b_x^2 + b_y^2 - 2(a_x^2b_x^2 + a_x^2b_y^2 + a_y^2b_x^2 + a_y^2b_y^2)\cos(\gamma)\).

And \(a_x^2 + a_y^2 + b_x^2 + b_y^2 - 2a_x^2b_x^2 \cos(\gamma)- 2a_x^2b_y^2\cos(\gamma) - 2a_y^2b_x^2\cos(\gamma) + 2a_y^2b_y^2\cos(\gamma)\).

Replace \(\|\vec{a}\|\|\vec{b}\|\cos(\gamma)\) with \(\vec{a}\cdot\vec{b}\).

\(\vec{a} \cdot \vec{a} + \vec{b} \cdot \vec{b} - 2\vec{a}\cdot\vec{b}\)

\(\vec{c}\cdot\vec{c} = \vec{a} \cdot \vec{a} + \vec{b} \cdot \vec{b} - 2\vec{a}\cdot\vec{b}\)

\(\vec{c}\cdot\vec{c} - \vec{a} \cdot \vec{a} - \vec{b} \cdot \vec{b} = 2\vec{a}\cdot\vec{b}\)

\((\vec{c}\cdot\vec{c} - \vec{a} \cdot \vec{a} - \vec{b} \cdot \vec{b}) / 2 = \vec{a}\cdot\vec{b}\)

11. third attempt.

Show the law of cosines using \(a \cdot b = \|a\| \|b\| \cos(\theta)\).

Law of cosines says that for triangle sides \(a, b, c\), and their opposite angles \(\alpha, \beta, \gamma\) (of corners \(A, B, C\)).

\(a^2 = b^2 + c^2 - 2bc\cos(\alpha)\)

\(b^2 = a^2 + c^2 - 2ac\cos(\beta)\)

\(c^2 = a^2 + b^2 - 2ab\cos(\gamma)\)

\(\vec{a}\) is the vector pointing from \(B\) to \(C\) or \(C\) to \(B\) and has the magnitude of the side \(a\), \(\vec{b}\) points from \(C\) to \(A\) or \(A\) to \(C\) and has the magnitude of side \(b\), \(vec{c}\) points from \(B\) to \(A\) or \(A\) to \(B\) and has the magnitude of side \(c\).

Take \(c^2 = a^2 + b^2 - 2ab\cos(\gamma)\).

Consider the RHS.

\(a^2 + b^2 - 2ab\cos(\gamma)\)

Replace lengths of sides with their vector magnitudes.

\(\|\vec{a}\|^2 + \|\vec{b}\|^2 - 2\|\vec{a}\|\|\vec{b}\|\cos(\gamma)\)

Using \(\vec{a}\cdot\vec{b} = \|\vec{a}\|\|\vec{b}\|\cos{\gamma}\), replace \(\|\vec{a}\|\|\vec{b}\|\cos{\gamma}\).

\(\vec{a} \cdot \vec{a} + \vec{b} \cdot \vec{b} - 2\vec{a}\cdot\vec{b}\)

Deconstruct vectors to their axis aligned parts.

\(a_x^2 + a_y^2 + b_x^2 + b_y^2 - 2(a_x^2 + a_y^2)(b_x^2 + b_y^2)\)

Distribute multiplication over addition.

\(a_x^2 + a_y^2 + b_x^2 + b_y^2 - 2(a_x^2(b_x^2 + b_y^2) + a_y^2(b_x^2 + b_y^2))\)

And \(a_x^2 + a_y^2 + b_x^2 + b_y^2 - 2(a_x^2b_x^2 + a_x^2b_y^2 + a_y^2b_x^2 + a_y^2b_y^2)\).

And \(a_x^2 - 2a_x^2b_x^2 + b_x^2 + a_y^2 + 2a_y^2b_y^2 + b_y^2 - 2a_x^2b_y^2 - 2a_y^2b_x^2\).

And \(a_x^2 - 2a_x^2b_x^2 + b_x^2 + a_y^2 + 2a_y^2b_y^2 + b_y^2 - 2a_x^2b_y^2 - 2a_y^2b_x^2\).

11

c2 = a2 + b2 -2abcos(gamma)

= ax2 + ay2 + bx2 -2*ax*bx

= ax2 -2*ax*bx + bx2 + ay2

= (ax - bx)2 + ay2

-—

=|c|2 = |a+b|2 = =(sqrt(a+b))2 =

I'm a failure. No idea about 11.

11. Stealing from an MIT solution by djk because I'm a moron.

Via: https://math.mit.edu/~djk/18_01/chapter05/proof05.html.

This is Professor Kleitman's solution which I will try and reproduce it from memory – I've read it a few tens of minutes ago – reducing rigor in the process.

Let's say A, B, C are points on corners of a triangle.

We can represent the sides AB, AC, and BC as the vectors \((A_x - B_x, A_y - B_y)\), \((A_x - C_x, A_y - C_y)\), and \((B_x - C_x, B_y - C_y)\).

Because \vec{AB}, \vec{AC}, and \vec{BC} express sides of a triangle, we know that \(\vec{AB} = \vec{AC} - \vec{BC}\).

The square of the magnitude of \vec{AB}, \(\|\vec{AB}\|^2\), is equal to the dot product of \vec{AB} with itself.

\(\|\vec{AB}\|^2 = \vec{AB} \cdot \vec{AB}\)

In the RHS, we replace \(\vec{AB} = \vec{AC} - \vec{BC}\).

\((\vec{AC} - \vec{BC}) \cdot (\vec{AC} - \vec{BC})\)

We then replace with the axis aligned vector component representation of the vector.

\((\vec{AC} - \vec{BC})_x^2 + (\vec{AC} - \vec{BC})_y^2\)

Algebraisting.

\(\vec{AC}_x^2 - 2\vec{AC}_x\vec{BC}_x + \vec{BC}_x^2 + \vec{AC}_y^2 - 2\vec{AC}_y\vec{BC}_y + \vec{BC}_x^2\)

\(\vec{AC}_x^2 + \vec{AC}_y^2 + \vec{BC}_x^2 + \vec{BC}_y^2 - 2\vec{AC}_x\vec{BC}_x - 2\vec{AC}_y\vec{BC}_y\)

\(\vec{AC}_x^2 + \vec{AC}_y^2 + \vec{BC}_x^2 + \vec{BC}_y^2 - 2(\vec{AC}_x\vec{BC}_x + \vec{AC}_y\vec{BC}_y)\)

Use vector dot products.

\(\vec{AC} \cdot \vec{AC} + \vec{BC} \cdot \vec{BC} - 2(\vec{AC} \cdot \vec{BC})\)

Dot product of a vector with itself is the square of the vector's magnitude.

\(\|\vec{AC}\|^2 + \|\vec{BC}\|^2 - 2(\vec{AC} \cdot \vec{BC})\)

Dot product of a vector with another is the product of their magnitude and the cosine of the angle between them.

\(\|\vec{AC}\|^2 + \|\vec{BC}\|^2 - 2\|\vec{AC}\|\|\vec{BC}\|\cos(\gamma)\)

What I like about this thing is the duality of point and vector, as mentioned in the chapter. \((A_x, A_y\) can be seen as a vector from the origin to the point \(A\) and \(\vec{AB\}\) is the vector from point \(A\) to point \(B\).

12.

Use \( a \cdot b = a_x b_x + a_y b_y \) and trigonometric identities to prove the geometric interpretation of the dot product in 2D.

Let there be \(\vec{a}, \vec{b}\) two 2d vectors and \(\theta_1, \theta_2\) their angles as measured counter clockwise from the positive side of the X axis. Additionally, let \(\theta\) be the small angle between \(\vec{a}\) and \(\vec{b}\).

The axis aligned values of the two vectors are \(\vec{a} = (\vec{a}_x, \vec{a}_y) = (\|\vec{a}\|\cos\theta_1, \|\vec{a}\|\sin\theta_1)\) and \(\vec{b} = (\vec{b}_x, \vec{b}_y) = (\|\vec{b}\|\cos\theta_2, \|\vec{b}\|\sin\theta_2)\).

Replace \(a_x, b_x, a_y, b_y\) with their axis aligned values in the dot product equation.

\(a \cdot b = (\|\vec{a}\|\cos\theta_1) (\|\vec{b}\|\cos\theta_2) + (\|\vec{a}\|\sin\theta_1) (\|\vec{b}\|\sin\theta_2)\)

Take out \(\|\vec{a}\|\|\vec{b}\|\).

\(a \cdot b = \|\vec{a}\|\|\vec{b}\| ((\cos\theta_1)(\cos\theta_2) + (\sin\theta_1)(\sin\theta_2))\)

By \(\cos(a-b) = \cos a \cos b + \sin a \sin b\).

\(a \cdot b = \|\vec{a}\|\|\vec{b}\|\cos(\theta_2 - \theta_1)\)

We know that \(\theta = \theta_2 - \theta_1\).

\(a \cdot b = \|\vec{a}\|\|\vec{b}\|\cos(\theta)\)

There you go.

14.

Show \(\|a \times b\| = \|a\|\|b\|sin(\theta)\).

First multiply each side by itself.

\( \|a \times b\|^2 = (\|a\|\|b\|sin(\theta))^2 \)

LHS – \(\|a \times b\|^2\).

\(a \times b\) is equal to the vector \((a_y b_z - a_z b_y, a_z b_x - a_x b_z, a_x b_y - a_y b_x)\), called \(c\).

Replace with \(c\) and the equality \(\|a\| = \sqrt(a_x^2 + a_y^2 + a_z^2)\).

\( \sqrt(c_x^2 + c_y^2 + c_z^2)^2 \)

Then.

\( c_x^2 + c_y^2 + c_z^2 \)

Use the axis aligned values of \(c\).

\( (a_y b_z - a_z b_y)^2 + (a_z b_x - a_x b_z)^2 + (a_x b_y - a_y b_x)^2 \)

RHS – \((\|a\|\|b\|\sin(\theta))^2\).

Algebraisting.

\( \|a\|^2\|b\|^2\sin^2 \theta \)

By \(\sin^2 \theta + \cos^2 \theta = 1\).

\( \|a\|^2 \|b\|^2 (1 - \cos^2 \theta) \)

Distribute.

\( \|a\|^2 \|b\|^2 - \|a\|^2 \|b\|^2 \cos^2 \theta \)

Algebraisting.

\( \|a\|^2 \|b\|^2 - (\|a\| \|b\| \cos \theta)^2 \)

By \(a \cdot b = \|a\| \|b\| \cos \theta\).

\( \|a\|^2 \|b\|^2 - (a \cdot b)^2 \)

Dot product definition.

\( \|a\|^2 \|b\|^2 - (a_x b_x + a_y b_y + a_z b_z)^2 \)

By \(\|a\| = \sqrt(a \cdot a)\).

\( \sqrt(a \cdot a)^2 \sqrt(b \cdot b)^2 - (a_x b_x + a_y b_y + a_z b_z)^2 \)

And.

\( (a \cdot a) (b \cdot b) - (a_x b_x + a_y b_y + a_z b_z)^2 \)

Dot product definition.

\( (a_x^2 + a_y^2 + a_z^2) (b_x^2 + b_y^2 + b_z^2) - (a_x b_x + a_y b_y + a_z b_z)^2 \)

Expand \((a_x^2 + a_y^2 + a_z^2) (b_x^2 + b_y^2 + b_z^2)\).

\( a_x^2 (b_x^2 + b_y^2 + b_z^2) + a_y^2 (b_x^2 + b_y^2 + b_z^2) + a_z^2 (b_x^2 + b_y^2 + b_z^2)\)

\( a_x^2 b_x^2 + a_x^2 b_y^2 + a_x^2 b_z^2 + a_y^2 b_x^2 + a_y^2 b_y^2 + a_y^2 b_z^2 + a_z^2 b_x^2 + a_z^2 b_y^2 + a_z^2 b_z^2\)

\( (a_x b_x)^2 + (a_x b_y)^2 + (a_x b_z)^2 + (a_y b_x)^2 + (a_y b_y)^2 + (a_y b_z)^2 + (a_z b_x)^2 + (a_z b_y)^2 + (a_z b_z)^2\)

Expand \((a_x b_x + a_y b_y + a_z b_z)^2\)

\( a_x b_x (a_x b_x + a_y b_y + a_z b_z) + a_y b_y (a_x b_x + a_y b_y + a_z b_z) + a_z b_z (a_x b_x + a_y b_y + a_z b_z) \)

\( a_x b_x a_x b_x + a_x b_x a_y b_y + a_x b_x a_z b_z + a_y b_y a_x b_x + a_y b_y a_y b_y + a_y b_y a_z b_z + a_z b_z a_x b_x + a_z b_z a_y b_y + a_z b_z a_z b_z \)

\( (a_x b_x)^2 + a_x b_x a_y b_y + a_x b_x a_z b_z + a_y b_y a_x b_x + (a_y b_y)^2 + a_y b_y a_z b_z + a_z b_z a_x b_x + a_z b_z a_y b_y + (a_z b_z)^2 \)

Put it back into the RHS.

\( (a_x b_x)^2 + (a_x b_y)^2 + (a_x b_z)^2 + (a_y b_x)^2 + (a_y b_y)^2 + (a_y b_z)^2 + (a_z b_x)^2 + (a_z b_y)^2 + (a_z b_z)^2 - (a_x b_x)^2 - a_x b_x a_y b_y - a_x b_x a_z b_z - a_y b_y a_x b_x - (a_y b_y)^2 - a_y b_y a_z b_z - a_z b_z a_x b_x - a_z b_z a_y b_y - (a_z b_z)^2 \)

Subtract the equals.

\( (a_x b_y)^2 + (a_x b_z)^2 + (a_y b_x)^2 + (a_y b_z)^2 + (a_z b_x)^2 + (a_z b_y)^2 - a_x b_x a_y b_y - a_x b_x a_z b_z - a_y b_y a_x b_x - a_y b_y a_z b_z - a_z b_z a_x b_x - a_z b_z a_y b_y \)

\( (a_x b_y)^2 - 2 a_x b_y a_y b_x + (a_y b_x)^2 + (a_x b_z)^2 - 2 a_x b_z a_z b_x + (a_z b_x)^2 + (a_y b_z)^2 - 2 a_y b_z b_y a_z + (a_z b_y)^2 \)

\( (a_x b_y - a_y b_x)^2 + (a_x b_z - a_z b_x)^2 + (a_y b_z - a_z b_y)^2 \)

Reordering and because \((a - b)^2 = (b - a)^2\).

\( (a_y b_z - a_z b_y)^2 + (a_z b_x - a_x b_z)^2 + (a_x b_y - a_y b_x)^2 \)

Which is equal to the result we had of the RHS.

There you go.

15.

\(\|\begin{bmatrix} ... \end{bmatrix}\|_1\)

\(\|\begin{bmatrix} ... \end{bmatrix}\|_2\)

\(\|\begin{bmatrix} ... \end{bmatrix}\|_3\)

\(\|\begin{bmatrix} ... \end{bmatrix}\|_\infty\)

    1. \(\begin{bmatrix} 3 & 4 \end{bmatrix}\)

      \(\|\begin{bmatrix} 3 & 4 \end{bmatrix}\|_1 = |3| + |4| = 3 + 4 = 7\)

      \(\|\begin{bmatrix} 3 & 4 \end{bmatrix}\|_2 = \sqrt(3^2 + 4^2) = \sqrt(9 + 16) = \sqrt(25) = 5\)

      \(\|\begin{bmatrix} 3 & 4 \end{bmatrix}\|_3 = (3^3 + 4^3)^\frac{1}{3} = (27 + 64)^\frac{1}{3} = (91)^\frac{1}{3} \approx 4.5 \)

      \(\|\begin{bmatrix} 3 & 4 \end{bmatrix}\|_\infty = 4\)

    2. \(\begin{bmatrix} -2 & 10 & -7 \end{bmatrix}\)

      \(\|\begin{bmatrix} -2 & 10 & -7 \end{bmatrix}\|_1 = |-2| + |10| + |-7| = 2 + 10 + 7 = 19\)

      \(\|\begin{bmatrix} -2 & 10 & -7 \end{bmatrix}\|_2 = \sqrt((-2)^2 + 10^2 + (-7)^2) = \sqrt(4 + 100 + 49) = 153\)

      \(\|\begin{bmatrix} -2 & 10 & -7 \end{bmatrix}\|_3 = (|-2|^3 + 10^3 + |-7|^3)^\frac{1}{3} = (8 + 1000 + 343)^\frac{1}{3} = (1351)^\frac{1}{3} \approx 11.05\)

      \(\|\begin{bmatrix} -2 & 10 & -7 \end{bmatrix}\|_\infty = 10\)

    3. \(\begin{bmatrix} 6 & 1 & -9 \end{bmatrix}\)

      \(\|\begin{bmatrix} 6 & 1 & -9 \end{bmatrix}\|_1 = |6| + |1| + |-9| = 6 + 1 + 9 = 16\)

      \( \|\begin{bmatrix} 6 & 1 & -9 \end{bmatrix}\|_2 = \sqrt((6)^2 + (1)^2 + (-9)^2) = \sqrt(36 + 1 + 81) \approx 4.904868131524016 \)

      \( \|\begin{bmatrix} 6 & 1 & -9 \end{bmatrix}\|_3 = (|6|^3 + |1|^3 + |-9|^3)^\frac{1}{3} = (216 + 1 + 729)^\frac{1}{3} = 946^\frac{1}{3} \approx 9.81 \)

      \( \|\begin{bmatrix} 6 & 1 & -9 \end{bmatrix}\|_\infty = 9 \)

    4. \(\begin{bmatrix} 5 & -12 \end{bmatrix}\)

      \( \|\begin{bmatrix} 5 & -12 \end{bmatrix}\|_1 = 5 + 12 = 17 \)

      \(\|\begin{bmatrix} 5 & -12 \end{bmatrix}\|_2 = \sqrt(25 + 144) = \sqrt(169 \textnormal{nice}) = 13 \)

      \(\|\begin{bmatrix} 5 & -12 \end{bmatrix}\|_3 = \)

      \(\|\begin{bmatrix} 5 & -12 \end{bmatrix}\|_\infty\)

    5. \(\begin{bmatrix} -2 & -2 & -2 & -2 \end{bmatrix}\)
(cl-labels ((L (v p)
              (expt (cl-loop for x in v
                             sum (expt (abs x) p))
                    (/ 1.0 p))))
  (let ((vectors '((3 4)
                   (-2 10 -7)
                   (6 1 -9)
                   (5 -12)
                   (-2 -2 -2 -2)))
        (ps '(1 2 3 100 10000)))
    (cl-loop
     for v in vectors
     collect (cl-loop
              for p in ps
              collect (L v p)))))
    • For \(L_1\), the points for which \(\|x\|_1 = 1\) would be:

      \(\{(x, y) \mid (y = x + 1 \land x \in [-1, 0]) \lor (y = x - 1 \land x \in [0, 1]) \lor (y = -x + 1 \land x \in [0, 1]) \lor (y = -x - 1 \land x \in [-1, 0]) \}\)

    • For \(L_2\), the points for which \(\|x\|_2 = 1\) would be:

      \(x^2 + y^2 = 1\)

    • For \(L_\infty\), the points for which \(\|x\|_\infty = 1\) would be:

      \(\{(x, y) \mid (|x| = 1 \land |y| \leq 1) \lor (|y| = 1 \land |x| \leq 1)\}\)

16.

In a box shaped 2 feet wide, 2 feet long, and 2 feet tall.

\(\|\begin{bmatrix} 2 & 2 & 2 \end{bmatrix}\| = \sqrt(2^2 + 2^2 + 2^2) = \sqrt(12) \approx 3.5\)

17.

\(a = \begin{bmatrix} -1 & 3 \end{bmatrix}\)

\(b = \begin{bmatrix} 1 & 3 \end{bmatrix}\)

\(c = \begin{bmatrix} 3 & -2 \end{bmatrix}\)

\(d = \begin{bmatrix} -1 & -2 \end{bmatrix}\)

\(e = \begin{bmatrix} -6 & 4 \end{bmatrix}\)

\(f = \begin{bmatrix} -1 & -3 \end{bmatrix}\)

\(a + b + c + d + e + f = \begin{bmatrix} -5 & 3 \end{bmatrix}\)

\(a + b + c + d + e + f = ((a + b + c + d + e + f)_x, (a + b + c + d + e + f)_y)\)

\( (a + b + c + d + e + f)_x = a_x + b_x + c_x + d_x + e_x + f_x = -1+1+3-1-6-1 = -5\)

\( (a + b + c + d + e + f)_y = a_y + b_y + c_y + d_y + e_y + f_y = 3+3-2-2+4-3 = 3\)

18.

Seems to be a left-handed coordinate system. If I place my left pointing finger on the vector \(a\) and left middle finger on the vector \(b\) the thumb points at the direction of the displayed \(\|a \times b\|\).

Oh, oops. You are supposed to make a thumbs up gesture with your hands and see which one's fingers point from the vector on the left side of the cross product operation to the one on the right while the thumb points at the direction of the cross product's vector result. Anyway, all the same, it is the left hand.

19.

  1. \(P_\textnormal{UpperLeft} = c + r \cdot \begin{bmatrix} -1 & 1 \end{bmatrix}\)

    \(P_\textnormal{UpperRight} = c + r \cdot \begin{bmatrix} 1 & 1 \end{bmatrix}\)

    \(P_\textnormal{LowerLeft} = c + r \cdot \begin{bmatrix} -1 & -1 \end{bmatrix}\)

    \(P_\textnormal{LowerRight} = c + r \cdot \begin{bmatrix} 1 & -1 \end{bmatrix}\)

  2. \(P_\textnormal{UpperLeftNear} = c + r \cdot \begin{bmatrix} -1 & 1 & -1 \end{bmatrix}\)

    \(P_\textnormal{UpperRightNear} = c + r \cdot \begin{bmatrix} 1 & 1 & -1 \end{bmatrix}\)

    \(P_\textnormal{LowerLeftNear} = c + r \cdot \begin{bmatrix} -1 & -1 & -1 \end{bmatrix}\)

    \(P_\textnormal{LowerRightNear} = c + r \cdot \begin{bmatrix} 1 & -1 & -1 \end{bmatrix}\)

    \(P_\textnormal{UpperLeftFar} = c + r \cdot \begin{bmatrix} -1 & 1 & 1 \end{bmatrix}\)

    \(P_\textnormal{UpperRightFar} = c + r \cdot \begin{bmatrix} 1 & 1 & 1 \end{bmatrix}\)

    \(P_\textnormal{LowerLeftFar} = c + r \cdot \begin{bmatrix} -1 & -1 & 1\end{bmatrix}\)

    \(P_\textnormal{LowerRightFar} = c + r \cdot \begin{bmatrix} 1 & -1 & 1\end{bmatrix}\)

20.

  1. \(\textnormal{Point position in relation to NPC} = \begin{cases} (x - p) \cdot v > 0, & \textnormal{Point in front of the NPC} \\ (x - p) \cdot v < 0, & \textnormal{Point is behind of the NPC} \end{cases}\)
  2. \(p = \begin{bmatrix} -3 & 4 \end{bmatrix}, v = \begin{bmatrix} 5 & -2 \end{bmatrix}\).
    1. \(\begin{aligned} x & = \begin{bmatrix} 0 & 0 \end{bmatrix}, \\ (x - p) \cdot v & = (\begin{bmatrix} 0 & 0 \end{bmatrix} - \begin{bmatrix} -3 & 4 \end{bmatrix}) \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = \begin{bmatrix} 3 & -4 \end{bmatrix} \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = (3) \cdot (5) + (-4) \cdot (-2) \\ & = (15) + (8) \\ & = 23 > 0 \implies \textnormal{Point x is in front of the NPC} \end{aligned}\)
    2. \(\begin{aligned} x & = \begin{bmatrix} 1 & 6 \end{bmatrix}, \\ (x - p) \cdot v & = (\begin{bmatrix} 1 & 6 \end{bmatrix} - \begin{bmatrix} -3 & 4 \end{bmatrix}) \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = \begin{bmatrix} 4 & 2 \end{bmatrix} \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = (4) \cdot (5) + (2) \cdot (-2) \\ & = (20) + (-4) \\ & = 16 > 0 \implies \textnormal{Point x is in front of the NPC} \end{aligned}\)
    3. \(\begin{aligned} x & = \begin{bmatrix} -6 & 0 \end{bmatrix}, \\ (x - p) \cdot v & = (\begin{bmatrix} -6 & 0 \end{bmatrix} - \begin{bmatrix} -3 & 4 \end{bmatrix}) \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = \begin{bmatrix} -3 & -4 \end{bmatrix} \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = (-3) \cdot (5) + (-4) \cdot (-2) \\ & = (-15) + (8) \\ & = -7 < 0 \implies \textnormal{Point x is behind the NPC} \end{aligned}\)
    4. \(\begin{aligned} x & = \begin{bmatrix} -4 & 7 \end{bmatrix}, \\ (x - p) \cdot v & = (\begin{bmatrix} -4 & 7 \end{bmatrix} - \begin{bmatrix} -3 & 4 \end{bmatrix}) \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = \begin{bmatrix} -1 & 3 \end{bmatrix} \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = (-1) \cdot (5) + (3) \cdot (-2) \\ & = (-5) + (-6) \\ & = -11 < 0 \implies \textnormal{Point x is behind the NPC} \end{aligned}\)
    5. \(\begin{aligned} x & = \begin{bmatrix} 5 & 5 \end{bmatrix}, \\ (x - p) \cdot v & = (\begin{bmatrix} 5 & 5 \end{bmatrix} - \begin{bmatrix} -3 & 4 \end{bmatrix}) \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = \begin{bmatrix} 8 & 1 \end{bmatrix} \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = (8) \cdot (5) + (1) \cdot (-2) \\ & = (40) + (-2) \\ & = 38 > 0 \implies \textnormal{Point x is in front of the NPC} \end{aligned}\)
    6. \(\begin{aligned} x & = \begin{bmatrix} -3 & 0 \end{bmatrix}, \\ (x - p) \cdot v & = (\begin{bmatrix} -3 & 0 \end{bmatrix} - \begin{bmatrix} -3 & 4 \end{bmatrix}) \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = \begin{bmatrix} 0 & -4 \end{bmatrix} \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = (0) \cdot (5) + (-4) \cdot (-2) \\ & = (0) + (8) \\ & = 8 > 0 \implies \textnormal{Point x is in front of the NPC} \end{aligned}\)
    7. \(\begin{aligned} x & = \begin{bmatrix} -6 & -3.5 \end{bmatrix}, \\ (x - p) \cdot v & = (\begin{bmatrix} -6 & -3.5 \end{bmatrix} - \begin{bmatrix} -3 & 4 \end{bmatrix}) \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = \begin{bmatrix} -3 & -7.5 \end{bmatrix} \cdot \begin{bmatrix} 5 & -2 \end{bmatrix} \\ & = (-3) \cdot (5) + (-7.5) \cdot (-2) \\ & = (-15) + (15.0) \\ & = 0.0 = 0 \implies \textnormal{Point x is to the side of the NPC} \end{aligned}\)
(let* ((p '(-3 4))
       (p-x (car p))
       (p-y (cadr p))
       (v '(5 -2))
       (v-x (car v))
       (v-y (cadr v)))
  (cl-loop for i from 1
           for x in '((0 0)
                      (1 6)
                      (-6 0)
                      (-4 7)
                      (5 5)
                      (-3 0)
                      (-6 -3.5))
           concat
           (let* ((x-x (car x))
                  (x-y (cadr x))
                  (at-point-x (- x-x p-x))
                  (at-point-y (- x-y p-y))
                  (mult-x (* v-x at-point-x))
                  (mult-y (* v-y at-point-y))
                  (dot-product (+ mult-x mult-y)))
             (concat
              "   " (number-to-string i) ") \\(\\begin{aligned}\n"
              "      x & = \\begin{bmatrix} " (number-to-string x-x) " & " (number-to-string x-y) " \\end{bmatrix}, \\\\\n"
              "        (x - p) \\cdot v & = (\\begin{bmatrix} " (number-to-string x-x) " & " (number-to-string x-y) " \\end{bmatrix} - \\begin{bmatrix} "
              (number-to-string p-x) " & " (number-to-string p-y)
              " \\end{bmatrix})\n"
              "          \\cdot\n"
              "          \\begin{bmatrix} " (number-to-string v-x) " & " (number-to-string v-y) " \\end{bmatrix} \\\\\n"
              "        & = \\begin{bmatrix} " (number-to-string at-point-x) " & " (number-to-string at-point-y) " \\end{bmatrix} \\cdot \\begin{bmatrix} " (number-to-string v-x) " & " (number-to-string v-y) " \\end{bmatrix} \\\\\n"
              "        & = (" (number-to-string at-point-x) ") \\cdot (" (number-to-string v-x) ") + (" (number-to-string at-point-y) ") \\cdot (" (number-to-string v-y) ") \\\\\n"
              "        & = (" (number-to-string mult-x) ") + (" (number-to-string mult-y) ") \\\\\n"
              "        & = " (number-to-string dot-product) " "
              (cond ((< dot-product 0) "<") ((> dot-product 0) ">") (t "="))
              " 0 \\implies\n"
              "      \\textnormal{"
              (cond ((< dot-product 0) "Point x is behind the NPC")
                    ((> dot-product 0) "Point x is in front of the NPC")
                    ((and (= p-x x-x) (= p-y x-y)) "Point x is at the same position as the NPC")
                    (t "Point x is to the side of the NPC"))
              "}\n"
              "      \\end{aligned}\\)\n"))))

21.

Practical solutions.

Standalone practical solutions are in:

Wordy solutions.

  1. On a 2D plane, let point \(p\) be of the NPC, point \(x\) some arbitrary point, vector \(v\) the direction at which the NPC is faced, the FOV angle be \(\theta\).

    We can define unit vectors \(\hat{l}\) and \(\hat{r}\) as:

    \begin{aligned} v \cdot \hat{l} & = \|v\| \cos(\frac{\tau}{4}-\frac{\theta}{2}) \\ v \cdot \hat{r} & = \|v\| \cos(-(\frac{\tau}{4}-\frac{\theta}{2})) \\ \end{aligned}

    Now we can find whether or not \(x\) is within the FOV by testing \((x-p) \cdot \hat{l} > 0 \land (x-p) \cdot \hat{r} > 0\).

    Rotating \(v\) by angles \(\frac{\tau}{4}-\frac{\theta}{2}\) for angle θl and \(-\theta_l\) for θr and dividing by \(\|v\|\) finds us the value of \(\hat{l}\) and \(\hat{r}\).

    \begin{aligned} \hat{l} & = \frac{\begin{bmatrix} \cos(\theta_l) & -\sin(\theta_l) \\ \sin(\theta_l) & \cos(\theta_l) \end{bmatrix} \cdot v}{\|v\|} \\ \hat{r} & = \frac{\begin{bmatrix} \cos(\theta_r) & -\sin(\theta_r) \\ \sin(\theta_r) & \cos(\theta_r) \end{bmatrix} \cdot v}{\|v\|} \\ \end{aligned}
  2. (cl-labels ((rotate (v angle)
                  (list (+ (* (car v) (cos angle))
                           (* (cadr v) (- (sin angle))))
                        (+ (* (car v) (sin angle))
                           (* (cadr v) (cos angle)))))
                (vec-sub (v u)
                  (cl-loop for v-x in v
                           for u-x in u
                           collect (- v-x u-x)))
                (dot-product (v u)
                  (cl-loop for v-x in v
                           for u-x in u
                           sum (* v-x u-x))))
      (let* ((p (list -3 4))
             (v (list 5 -2))
             (float-tau (* 2 float-pi))
             (theta (* 0.25 float-tau))
             (theta-l (- (* float-tau 0.25 ) (/ theta 2)))
             (theta-r (- theta-l))
             (l (rotate v theta-l))
             (r (rotate v theta-r)))
        (cl-loop for i from 1
                 for x in '((0 0)
                            (1 6)
                            (-6 0)
                            (-4 7)
                            (5 5)
                            (-3 0)
                            (-6 -3.5))
                 concat
                 (let* ((dot-product-l (dot-product (vec-sub x p) l))
                        (dot-product-r (dot-product (vec-sub x p) r)))
                   (format "p = [%s, %s]; v = [%s, %s]; x = [%s %s]; theta = %.4f.  l = [%.4f, %.4f]; r = [%.4f, %.4f].  The point is %s the FOV.\n"
                           (car p) (cadr p)
                           (car v) (cadr v)
                           (car x) (cadr x)
                           theta
                           (car l) (cadr l)
                           (car r) (cadr r)
                           (if (and (> dot-product-l 0)
                                    (> dot-product-r 0))
                               "inside"
                             "outside"))
                   ))))
    
    
    

22.

Practical solution.

A standalone practical solution is in solution_02_22_2.html.

Wordy solution.

We define the two vectors:

\begin{aligned} \vec{AB} & = \begin{bmatrix} x(B) - x(A) & y(B) - y(A) & z(B) - z(A) \end{bmatrix} \\ \vec{BC} & = \begin{bmatrix} x(C) - x(B) & y(C) - y(B) & z(C) - z(B) \end{bmatrix} \\ \end{aligned}

When \(y(\vec{AB} \times \vec{BC}) > 0\), the turn at point \(B\) was a clockwise turn, when \(y(\vec{AB} \times \vec{BC}) < 0\) it's counter clockwise.

23.

p' = p + (k - 1) ( p . n ) n.

[1 0 0] + (k - 1) ( [1 0 0] . [nx ny nz] ) [nx ny nz].

[1 0 0] + (k - 1) nx [nx ny nz].

[1 0 0] + [(k - 1) nx nx, (k - 1) nx ny, (k - 1) nx nz].

p' = [1 + (k - 1) nx nx, (k - 1) nx ny, (k - 1) nx nz].

24.

\(p' = cos\theta(p - (p \cdot n)n) + \sin(\theta)(n \times p) + (p \cdot n)n\)

p = [1, 1, 1];

\(\cos\theta([1, 0, 0] - ([1, 0, 0] \cdot [n_x, n_y, n_z])[n_x, n_y, n_z]) + \sin(\theta)([n_x, n_y, n_z] \times [1, 0, 0]) + ([1, 0, 0] \cdot [n_x, n_y, n_z])[n_x, n_y, n_z]\)

\(\cos\theta([1, 0, 0] - (n_x)[n_x, n_y, n_z]) + \sin(\theta)([n_x, n_y, n_z] \times [1, 0, 0]) + ([1, 0, 0] \cdot [n_x, n_y, n_z])[n_x, n_y, n_z]\)

\(\cos\theta([1, 0, 0] - [n_x^2, n_x n_y, n_x n_z]) + \sin(\theta)([n_x, n_y, n_z] \times [1, 0, 0]) + ([1, 0, 0] \cdot [n_x, n_y, n_z])[n_x, n_y, n_z]\)

\(\cos\theta([1- n_x^2, -n_x n_y, -n_x n_z]) + \sin(\theta)([n_x, n_y, n_z] \times [1, 0, 0]) + ([1, 0, 0] \cdot [n_x, n_y, n_z])[n_x, n_y, n_z]\)

\(\cos\theta([1- n_x^2, -n_x n_y, -n_x n_z]) + \sin(\theta)([n_y 0 - n_z 0, n_z 1 - n_x 0, n_x 0 - n_y 1]) + ([1, 0, 0] \cdot [n_x, n_y, n_z])[n_x, n_y, n_z]\)

\(\cos\theta([1- n_x^2, -n_x n_y, -n_x n_z]) + \sin(\theta)([0, n_z 1, - n_y 1]) + ([1, 0, 0] \cdot [n_x, n_y, n_z])[n_x, n_y, n_z]\)

\(\cos\theta([1- n_x^2, -n_x n_y, -n_x n_z]) + \sin(\theta)([0, n_z 1, - n_y 1]) + (n_x)[n_x, n_y, n_z]\)

\(\cos\theta([1- n_x^2, -n_x n_y, -n_x n_z]) + \sin(\theta)([0, n_z 1, - n_y 1]) + [n_x n_x, n_x n_y, n_x n_z]\)

\([\cos\theta(1- n_x^2), -\cos\theta n_x n_y, -\cos\theta n_x n_z] + [0, \sin(\theta) n_z, - \sin(\theta) n_y] + [n_x n_x, n_x n_y, n_x n_z]\)

\([\cos\theta(1- n_x^2), -\cos\theta n_x n_y + \sin(\theta) n_z, -\cos\theta n_x n_z - \sin(\theta) n_y] + [n_x n_x, n_x n_y, n_x n_z]\)

\([\cos\theta(1- n_x^2) + n_x n_x, -\cos\theta n_x n_y + \sin(\theta) n_z + n_x n_y, -\cos\theta n_x n_z - \sin(\theta) n_y + n_x n_z]\)

Sure hope I've got it right ~;~.

Chapter 3.

1.

  1. Upright space.
  2. World peace.
  3. Object space.
  4. Camera space.

2.

The point would be move counterclockwise by 42 degrees, then translated along the world z axis by -6 units and -12 units along the world x axis.

Or am I supposed to translate along the x and z axes of the vectors after their rotation? I am not sure about that.

3.

  1. The zero vector \begin{bmatrix} 0 \\ 0 \\ 0 \end{bmatrix} can be expressed as a linear combination of any other 3d vectors.

    In the linear combination \begin{aligned}a \begin{bmatrix} 1 \\ 0 \\ 0\end{bmatrix} + b \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}\end{aligned} set their linear contributions to zero, i.e. \(a = 0, b = 0\).

  2. We can attempt to find the values of two of these vector's linear contributions in a linear combination such that the linear combination would equal to the third.

    \begin{aligned} \begin{bmatrix} 1 \\ 0 \\ 2 \end{bmatrix} & = a \begin{bmatrix} -1 \\ 1 \\ 2 \end{bmatrix} + b \begin{bmatrix} 0 \\ 1 \\ 2 \end{bmatrix} \\ \end{aligned}

    We can express this combination as a system of equations.

    \begin{aligned} 1 & = a (-1) + b (0) \\ 0 & = a ( 1) + b (1) \\ 2 & = a ( 2) + b (2) \\ \end{aligned}

    Take the second equation and substract \(-b\) from both sides and you get \(a = -b\).

    Assign the newly discovered value of \(a\) into the first equation and you get \(1 = (-b)(-1) = b\).

    We now know \(a = -1\) and \(b = 1\), so assign their values in the third equation and you get \(2 = (-1) 2 + 2 = 0\). That is a contradiction, which means that the system of equation has no solution and that the vectors are linearly independent.

  3. We can see that we can get one of the vectors from the other three in the following linear combination, which means this set of vectors is linearly dependent.

    \begin{aligned}\begin{bmatrix} -1 \\ 2 \\ 3 \end{bmatrix} + \begin{bmatrix} 1 \\ -2 \\ 3 \end{bmatrix} + \begin{bmatrix} 1 \\ 2 \\ -3 \end{bmatrix} = \begin{bmatrix} -1 + 1 + 1 \\ 2 -2 + 2 \\ 3 + 3 - 3 \end{bmatrix} = \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix} \end{aligned}
  4. Let us solve the corresponding system of equations.

    \begin{aligned} 1 = a 0 + b (-2) \\ 2 = a 1 + b (-4) \\ 3 = a 5 + b (-6) \end{aligned}

    From the first equation we find \( 1 = -2b \) and then \( b = -\frac{1}{2} \). We set \(b\)'s value in the second equation as \( 2 = a -\frac{1}{2}(-4) = a + 2 \). Subtract two from the two sides in \( 2 - 2 = a + 2 - 2 \) and we get \( a = 0 \).

    We set both currently known values of the unknowns into the third equation and get \( 3 = (0) 5 -\frac{1}{2}(-6) = 3 \). Oh crap. \(\begin{bmatrix} 1 \\ 2 \\ 3\end{bmatrix}\) is obviously \( 0 \begin{bmatrix} 0 \\ 1 \\ -5\end{bmatrix} + (\frac{-1}{2})\begin{bmatrix} -2 \\ -4 \\ -6 \end{bmatrix}\). I am so dumb.

  5. Following our previous exercise we try and look at the number to see an obvious pattern and we see that \(0 = 1 - 1\), \(-5 = -4 -1\), and \(4 = 9 - 5\). Therefore the linear combination \(\begin{bmatrix} 0 \\ -5 \\ 4 \end{bmatrix} = \begin{bmatrix} 1 \\ -4 \\ 9 \end{bmatrix} - \begin{bmatrix} 1 \\ 1 \\ 5 \end{bmatrix}\) implies that this here set of vectors is linearly dependent.
  6. \(1 = a(-1) + b\) → \(1 + a - 1 = -a + b + a - 1\) → \(a = b - 1\).

    We set \(a\) into the second equation as \(2 = 2(b-1) -2b\) → \(2 = 2b -2 -2b\) → \(2 = -2\), a contradiction implying the vectors are linearly independent.

4.

Reading on the Wikipedia I see that two vectors \(a\) and \(b\) are orthogonal if and only if \(a \cdot b = 0\). I didn't see it stated clearly and I am too dumb to figure it out from the text. It makes sense. The 90 degrees projection / shadow of one vector onto another when these two vectors are orthogonal would be of zero length.

Also, LibreTexts™ Mathematics's text on "Orthogonal Vectors and Matrices" is gosh darn good.

  1. We immediately see that the first vector is equal to the \(\hat{x}\) unit vector, the second is equal to \(4\hat{z}\), and the third to \(2\hat{y}\). Multiplying each vector by a scalar does not change the angles between the vectors, so these stay orthogonal.
  2. \(\begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix} \cdot \begin{bmatrix} -1 \\ 2 \\ 3 \end{bmatrix} = 1 (-1) + 2 (2) + 3 (3) = -1 + 4 + 9 = 12 \neq 0\). These two aren't orthogonal, therefore this set of vectors is not orthogonal.
  3. \(\begin{bmatrix} 0 \\ 4 \\ 1 \end{bmatrix} \cdot \begin{bmatrix} 0 \\ -1 \\ 4 \end{bmatrix} = 0 - 4 + 4 = 0\). This pair is orthogonal.

    \(\begin{bmatrix} 0 \\ 4 \\ 1 \end{bmatrix} \cdot \begin{bmatrix} 8 \\ 0 \\ 0 \end{bmatrix} = 0(8) + 4(0) + 1(0) = 0\). This pair is orthogonal.

    \(\begin{bmatrix} 0 \\ 4 \\ 1 \end{bmatrix} \cdot \begin{bmatrix} 0 \\ -1 \\ 4 \end{bmatrix} = 0(0) + 4(-1) + 1(4) = 0\). This pair is orthogonal.

    All three pairs of vectors are orthogonal to each other which means this is an orthogonal set of vectors.

…

5.

Vectors are orthonormal if and only if they are both orthogonal and of unit length, right? So we test that all vector pairs of vectors are \(a \cdot b = 0\) and that every vector \(\|v\| = 1\).

  1. We know from problem 4 that these three are orthogonal, but the second and third vectors' lengths are 4 and 2, not 1, therefore this set of vectors are not orthonormal.
  2. We already know they are not orthogonal, so they are not orthonormal.
  3. These three obviously each has the length of 1 are obviously orthogonal, therefore they are orthonormal.
  4. \(\begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix} \cdot \begin{bmatrix} 0 \\ 0.707 \\ 0.707 \end{bmatrix} = 0.707 \neq 0\) therefore they are not orthogonal and therefore are not orthonormal.
  5. [0, 0.707, -0.707] ⋅ [0, 0.707, 0.707] = 0.7072 - 0.7072 = 0. The pairing the third and the first and the third and the second in a dot product operation would obviously yield zero, therefore they are orthogonal vectors. [0, 0.707, -0.707] ⋅ [0, 0.707, -0.707] = 0.7072 + 0.7072 = 2 (0.7072) ≈ 1, but not quite, so these two 0.707 vectors are almost unit vectors, but a bit shorter by a few ten thousandth of a unit. Adapting this book's First Law of Computer Graphics – if the vectors look like they're orthonormal, they are orthonormal.
  6. God almighty, I don't want to make any more of these calculations.

6.

Let's draw a diagram.

Imagine this is a top-down view over an XZ plane at Y = 0, with the Y axis pointing at you.

                         ^ Z
..................τ......|.....
...............sin-......|.....
.............L__..8......|.....
............/.\.|.... τ..|.....
.........../...\|.-cos-..|.....
----------v-----v-----8--+------> X
......right....front.....|.....
.........................|.....

The world space location is at about:

\begin{aligned} L = \begin{pmatrix} -12 \\ 0 \\ 3 \end{pmatrix} \end{aligned}

At \(\theta = 45^\circ = \frac{\tau}{8}\), \( \cos \theta = \sin \theta \approx 0.707 \), so the upright space vectors (p for right, q for up, and r for forward) are:

\begin{aligned} p = \begin{bmatrix} -\cos \frac{\tau}{8} \\ 0 \\ -\cos \frac{\tau}{8} \end{bmatrix}, q = \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}, r = \begin{bmatrix} +\cos \frac{\tau}{8} \\ 0 \\ -\cos \frac{\tau}{8} \end{bmatrix}. \end{aligned}

Let's say a point in object space is right at unit length to the right of the origin:

\begin{aligned} A = \begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix} \end{aligned}

To get this point's coordinates in upright space we:

\begin{aligned} upright(A, p, q, r) & = x(A) \times p + y(A) \times q + z(A) \times r \\ & = 1 \times p + 0 \times q + 0 \times r \\ & = 1 \times \begin{bmatrix} -\cos \frac{\tau}{8} \\ 0 \\ -\cos \frac{\tau}{8} \end{bmatrix} \\ & = \begin{pmatrix} -\cos \frac{\tau}{8} \\ 0 \\ -\cos \frac{\tau}{8} \end{pmatrix} \end{aligned}

(if you haven't noticed it before, parentheses denote points while brackets denote vectors)

Now that we have the point in upright space, we add the location of the object in world space to the location of the point in upright space.

\begin{aligned} world(upright(A), L) & = world(A, L) \\ & = A + L \\ & = \begin{pmatrix} -13 \\ 0 \\ 2 \end{pmatrix} + \begin{pmatrix} 1 \\ 0 \\ -3 \end{pmatrix} \\ & = \begin{pmatrix} -13 + 1 \\ 0 + 0 \\ 2 + (-3) \end{pmatrix} \\ & = \begin{pmatrix} -12 \\ 0 \\ -1 \end{pmatrix} \end{aligned}

Seems right.

Actual problem.

Now that we sorta kinda get what the fudge is going on, we can calculate the gosh darn thing.

We express the \(M\) points of object \(O_{3\times M}\) in world space by doing these calculations:

  • Point of object O in upright space = ([upright vectors] ⋅ points of object O in object space).

    \begin{aligned} \textnormal{upright}(O, p, q, r) & = \begin{bmatrix} p & q & r \end{bmatrix} \cdot O \\ & = \begin{bmatrix} p_x && q_x && r_x \\ p_y && q_y && r_y \\ p_z && q_z && r_z \end{bmatrix} \cdot O \end{aligned}
  • Point of object O in world space = (point of object O in upright space + location L of object O in world space).

    \begin{aligned} \textnormal{world}(\textnormal{upright}(O, p, q, r), L) & = \begin{bmatrix} p & q & r \end{bmatrix} \cdot O \\ & = \begin{bmatrix} p_x && q_x && r_x \\ p_y && q_y && r_y \\ p_z && q_z && r_z \end{bmatrix} \cdot O \end{aligned}

We know the following:

\begin{aligned} L & = \begin{pmatrix} 1 \\ 10 \\ 3 \end{pmatrix}. \\ p & = \begin{bmatrix} +0.866 \\ +0.000 \\ -0.500 \end{bmatrix}, q = \begin{bmatrix} +0.000 \\ +1.000 \\ +0.000 \end{bmatrix}, r = \begin{bmatrix} +0.500 \\ +0.000 \\ +0.866 \end{bmatrix}. \end{aligned}
  1. \begin{aligned} \textnormal{upright}(\begin{pmatrix} -1 \\ 2 \\ 0 \end{pmatrix}, p, q, r) & = (-1) [+0.866, 0, -0.5] + 2 [0, 1, 0] + 0 [0.5, 0, 0.866] \\ & = (-0.866, 2, 0.5) \\ \textnormal{world}(\textnormal{upright}(\begin{pmatrix} -1 \\ 2 \\ 0 \end{pmatrix}, p, q, r), L) & = \textnormal{world}((-0.366, 1, 0.366), (1, 10, 3)) \\ & = (-0.366 + 1, 1 + 10, 0.366 + 3) \\ & = (0.634, 11, 3.366) \end{aligned}
  2. upright((1, 2, 0), p, q, r) =

    = 1 [0.866, 0, -0.5] + 2 [0, 1, 0] + 0 =

    = (0.866 + 0, 0 + 2, -0.5 + 0) =

    = (0.866, 2, -0.5)

    world((0.866, 2, -0.5), (1, 10, 3)) =

    = (1.866, 12, 2.5)

  3. upright((0, 0, 0), p, q, r) = (0, 0, 0).

    world((0, 0, 0), (1, 10, 3)) = (1, 10, 3).

  4. upright((1, 5, 0.5), p, q, r) =

    = 1 * [0.866, 0, -0.5] + 5 * [0, 1, 0] + 0.5 * [0.5, 0, 0.866] =

    = (1 * 0.866 + 5 * 0 + 0.5 * 0.5, 1 * 0 + 5 * 1 + 0.5 * 0, 1 * (-0.5) + 5 * 0 + 0.5 * 0.866) =

    = (1 * 0.866 + 0.25, 5, -0.5 + 0.433) =

    = (1.116, 5, -0.067)

    world((1.116, 5, -0.067), (1, 10, 3)) = (2.116, 15, 2.933)

  5. …
  6. world_to_upright((1, 10, 3), (1, 10, 3)) = (1, 10, 3) - (1, 10, 3) =
    (0, 0, 0).
    

    The zeroth point, (0, 0, 0), is equal in value both upright space and in object space.

  7. world_to_upright((0, 0, 0), (1, 10, 3)) = (0, 0, 0) - (1, 10, 3) =
    (-1, -10, -3).
    

    We would have to find the solution to [p, q, r] (object space loration) = (upright space location).

    | +0.866 | 0 |   0.5 |   |  -1 |
    |      0 | 1 |     0 | = | -10 |
    |   -0.5 | 0 | 0.866 |   |  -3 |
    
    (-2) L3 -> L3
    
    | +0.866 | 0 |    0.5 |   |  -1 |
    |      0 | 1 |      0 | = | -10 |
    |      1 | 0 | -1.732 |   |   6 |
    
    (1/0.866) L1 -> L1
    
    | 1 | 0 |  0.577 |   | -1.15 |
    | 0 | 1 |      0 | = |   -10 |
    | 1 | 0 | -1.732 |   |     6 |
    
    L3 - L1 -> L3
    
    | 1 | 0 |  0.577 |   | -1.15 |
    | 0 | 1 |      0 | = |   -10 |
    | 0 | 0 | -2.309 |   |  7.15 |
    
    (-1/2.309) L3 -> L3
    
    | 1 | 0 | 0.577 |   |  -1.15 |
    | 0 | 1 |     0 | = |    -10 |
    | 0 | 0 |     1 |   | -3.096 |
    
    L1 - 0.577 L3 -> L1
    
    | 1 | 0 | 0 |   | 0.6364 |
    | 0 | 1 | 0 | = |    -10 |
    | 0 | 0 | 1 |   | -3.096 |
    

    (0.6364, -10, -3.096) is the object space location.

  8. The upright to object recipe is:

    (-2) L3 -> L3
    
    (1/0.866) L1 -> L1
    
    L3 - L1 -> L3
    
    (-1/2.309) L3 -> L3
    
    L1 - 0.577 L3 -> L1
    

    That is:

    (defun kakafarm/chapter-03/object-to-upright (x, y, z, p, q, r)
         \begin{aligned}
        \textnormal{upright}(\begin{pmatrix} -1 \\ 2 \\ 0 \end{pmatrix}, p, q, r)
            & = (-1) [+0.866, 0, -0.5] +
                  2  [0, 1, 0] +
                  0  [0.5, 0, 0.866] \\
            & = (-0.866 + 0.5, 1, -0.5 + 0.866) \\
            & = (-0.366, 1, 0.366) \\
        \textnormal{world}(\textnormal{upright}(\begin{pmatrix} -1 \\ 2 \\ 0 \end{pmatrix}, p, q, r), L)
            & = \textnormal{world}((-0.366, 1, 0.366), (1, 10, 3)) \\
            & = (-0.366 + 1, 1 + 10, 0.366 + 3) \\
            & = (0.634, 11, 3.366)
    \end{aligned}
    
    )
    
    (defun kakafarm/chapter-03/upright-to-object (x, y, z)
      (let* ((z (* -2 z))
             (x (/ x 0.866))
             (z (- z x))
             (z (/ z -2.309))
             (x (- x (* 0.577 z))))
        (list x y z)))
    
    (kakafarm/chapter-03/upright-to-object
    
(setq kakafarm/chapter-03/problem-06-bases
      '((0.866 0 -0.5)
        (0     1  0)
        (0.5   0  0.866)))

(defun kakafarm/chapter-03/object-to-upright (point bases)
  (cl-loop for axe-index from 0 to (1- (length bases))
           collect (cl-loop for base-index from 0 to (1- (length bases))
                            sum (let* ((point-axe (nth base-index point))
                                       (base-axe (nth axe-index (nth base-index bases)))
                                       (res (* point-axe base-axe)))
                                  res))))

(defun kakafarm/chapter-03/upright-to-object-0 (x y z)
  (let* ((z (* -2.0 z))
         (x (/ x 0.866))
         (z (- z x))
         (z (/ z -2.309))
         (x (- x (* 0.577 z))))
    (list x y z)))

(defun kakafarm/chapter-03/upright-to-object-1 (upright-point bases)
  (cl-loop for base in bases
           collect (cl-loop for axe-of-point in upright-point
                            for axe-of-base in base
                            sum (* axe-of-point axe-of-base))))

(cl-loop for X in '(-1  1  0  1     0)
         for Y in '( 2  2  0  5     5)
         for Z in '( 0  0  0  0.5  10)
         collect
         (kakafarm/chapter-03/object-to-upright
          (list X Y Z)
          kakafarm/chapter-03/problem-06-bases)
         )

'((-0.866 2 0.5)
  (0.866 2 -0.5)
  (0.0 0 0.0)
  (1.116 5.0 -0.067)
  (5.0 5 8.66))

(cl-loop for X in '(-1  1  0  1     0)
         for Y in '( 2  2  0  5     5)
         for Z in '( 0  0  0  0.5  10)
         collect
         (apply #'kakafarm/chapter-03/upright-to-object-0
                (kakafarm/chapter-03/object-to-upright (list X Y Z)
                                                       kakafarm/chapter-03/problem-06-bases)))
'((-1.0 2 -0.0)
  (1.0 2 -0.0)
  (0.0 0 0.0)
  (1.0001377219575576 5.0 0.5000795161417767)
  (0.002754439151148702 5 10.001590322835535))

(cl-loop for X in '(-1  1  0  1     0)
         for Y in '( 2  2  0  5     5)
         for Z in '( 0  0  0  0.5  10)
         collect
         (apply #'kakafarm/chapter-03/upright-to-object-1 (list (kakafarm/chapter-03/object-to-upright (list X Y Z) kakafarm/chapter-03/problem-06-bases)
                                                                kakafarm/chapter-03/problem-06-bases)))

'((-0.999956 2.0 0.0)
  (0.999956 2.0 0.0)
  (0.0 0.0 0.0)
  (0.9999560000000001 5.0 0.49997800000000003)
  (0.0 5.0 9.999559999999999))

Chapter 4.

https://gamemath.com/book/matrixintro.html.

\begin{aligned} A & = \begin{bmatrix} 13 & 4 & -9 \\ 12 & 0 & 6 \\ -3 & -1 & 5 \\ 10 & -2 & 5 \end{bmatrix} & B & = \begin{bmatrix} k_x & 0 & 0 \\ 0 & k_y & 0 \\ 0 & 0 & k_z \end{bmatrix} & C & = \begin{bmatrix} 15 & 8 \\ -7 & 3 \end{bmatrix} \\ D & = \begin{bmatrix} a & g \\ b & h \\ c & i \\ d & j \\ f & k \end{bmatrix} & E & = \begin{bmatrix} 0 & 1 & 3 \end{bmatrix} & F & = \begin{bmatrix} x \\ y \\ z \\ w \end{bmatrix} \\ G & = \begin{bmatrix} 10 & 20 & 30 & 1 \end{bmatrix} & H & = \begin{bmatrix} \alpha \\ \beta \\ \gamma \end{bmatrix} \end{aligned}
    • \(A_{4 \times 3}\), non-square, non-diagonal.
    • \(B_{3 \times 3}\), square, diagonal.
    • \(C_{2 \times 2}\), square, non-diagonal.
    • \(D_{5 \times 2}\), non-square, non-diagonal.
    • \(E_{1 \times 3}\), non-square, non-diagonal.
    • \(F_{4 \times 1}\), non-square, non-diagonal.
    • \(G_{1 \times 4}\), non-square, non-diagonal.
    • \(H_{1 \times 3}\), non-square, non-diagonal.
  1. \begin{aligned} A^T & = \begin{bmatrix} 13 & 12 & -3 & 10 \\ 4 & 0 & -1 & -2 \\ -9 & 6 & 5 & 5 \end{bmatrix} & B = B^T & = \begin{bmatrix} k_x & 0 & 0 \\ 0 & k_y & 0 \\ 0 & 0 & k_z \end{bmatrix} & C^T & = \begin{bmatrix} 15 & -7 \\ 8 & 3 \end{bmatrix} \\ D^T & = \begin{bmatrix} a & b & c & d & f \\ g & h & i & j & k \end{bmatrix} & E^T & = \begin{bmatrix} 0 \\ 1 \\ 3 \end{bmatrix} & F^T & = \begin{bmatrix} x & y & z & w \end{bmatrix} \\ G^T & = \begin{bmatrix} 10 \\ 20 \\ 30 \\ 1 \end{bmatrix} & H^T & = \begin{bmatrix} \alpha & \beta & \gamma \end{bmatrix} \end{aligned}
  2. All legal matrix multiplications between pairs of the A to H matrices:

    \begin{aligned} (AB)_{4 \times 3} && (AH)_{4 \times 1} && (GA)_{1 \times 3} \\ (BB)_{3 \times 3} && (EB)_{1 \times 3} && (HB)_{1 \times 3} \\ (CC)_{2 \times 2} && (DC)_{5 \times 2} \\ (EH)_{1 \times 1} && (FE)_{4 \times 3} \\ (FG)_{4 \times 4} \\ (HG)_{3 \times 4} \end{aligned}

    I do not see others. Maybe with transposition?

    \begin{aligned} AA^T_{4 \times 4} && A^TA_{3 \times 3} && AE^T_{4 \times 1} && BB_{3 \times 3} && EB_{1 \times 3} && HB_{1 \times 3} \\ CC_{2 \times 2} && DC_{5 \times 2} \\ FE_{4 \times 3} \\ FG_{4 \times 4} && FH_{4 \times 3} \end{aligned}
    • a)

      | 1 -2 | | -3   7 |
      | 5  0 | |  4 1/3 |
      =
      | 1(-3) -2(4)   1(7) -2(1/3) |
      | 5(-3) +0(4)   5(7) +0(1/3) |
      =
      | -3 -8         7    -2/3    |
      | 5(-3) +0(4)   5(7) +0(1/3) |
      =
      | -11  19/3 |
      | -15    35 |
      
    • b) Impossible.
    • c) Possibe, but come oooon.
    • d) \(\begin{bmatrix} x & y & z & w \end{bmatrix}\).
    • e) Impossible.
    • f) \(\begin{bmatrix} m_{11} && m_{12} \\ m_{21} && m_{22} \end{bmatrix}\).
    • g) AAAAA. \( \begin{bmatrix} 3 \times 6 - 3 \times 4 \\ -3 \times 7 + 3 \times 5 \end{bmatrix}^T \)
    • h) Impossible.
    • a) Same on both.
    • b) Not on both. Don't see any symmetries along the diagonal.
    • c) Symmetric along the diagonal, so yes.
    • d) 0, 4 and -3 are not the same as 0, -4, and 3, etc. so probably not.
    • a) It's the identity matrix, so we just get the vector back.
    • b) [5, -1, 2] ⋅ [2, 1, -2]T = 5*2 -1 -4 = 5

      [5, -1, 2] ⋅ [5, 7, -1]T = 25 -7 -2 = 16

      [5, -1, 2] ⋅ [-3, 1, 4]T = -15 -1 +8 = -8

      (cl-loop for a in '(5 -1 2) for b in '(-3 1 4) sum (* a b)) -8

    • c) [5, -1, 5] ⋅ [1, 7, 2]T = [1, 7, 2] ⋅ [5, -1, 5]T and so on so yes.
    • d) [5, -1, 2] ⋅ [0, 4, -3]T = -4 -6 = -10

      [0, -4, 3] ⋅ [5, -1, 2]T = 4 + 6 = 10

      no.

    • a) Because \((M^T)^T = M\), \(((A^T)^T)^T = A^T\).
    • b) Because \((AB)^T = B^TA^T\), \((BA^T)^T(CD^T) = AB^T(CD^T) = AB^TCD^T\).
    • c) Because blah blah blah yadda yadda yadda, \(((D^TC^T)(AB)^T)^T = AB(D^TC^T)^T = ABCD\).
    • d) \(((AB)^T(CDE)^T)^T = CDEAB\).
    • a) Turn 90 degrees counter clockwise.
    • b) Turn 45 degrees clockwise.
    • c) Double the size both horizontally and vertically.
    • d) Quadruple the size horizontally and septuple vertically.
    • e) Mirror everything along the Y axis as if it were a mirror.
    • f) Same as in a), but also double.
  3. We say that \(a \times b = aM\).

    By definition of 3d cross product:

    \begin{aligned} a \times b = \begin{bmatrix} a_y b_z - b_y a_z \\ a_z b_x - b_z a_x \\ a_x b_y - b_x a_y \end{bmatrix}^T \end{aligned}

    The explicit vector-matrix multiplication's value is:

    \begin{aligned} aM = \begin{bmatrix} a_x m_{11} + a_y m_{21} + a_z m_{31} \\ a_x m_{12} + a_y m_{22} + a_z m_{32} \\ a_x m_{13} + a_y m_{23} + a_z m_{33} \end{bmatrix}^T \end{aligned}

    We compare the two explicit expressions:

    \begin{aligned} \begin{bmatrix} a_x m_{11} + a_y m_{21} + a_z m_{31} \\ a_x m_{12} + a_y m_{22} + a_z m_{32} \\ a_x m_{13} + a_y m_{23} + a_z m_{33} \end{bmatrix}^T = \begin{bmatrix} a_y b_z - b_y a_z \\ a_z b_x - b_z a_x \\ a_x b_y - b_x a_y \end{bmatrix}^T \end{aligned}

    Just set values for each \(m_{ij}\) in the explicit value of the vector-matrix multiplication until we get the value of the cross product:

    \begin{aligned} aM & = \begin{bmatrix} a_x & a_y & a_z \end{bmatrix} \cdot \begin{bmatrix} 0 & -b_z & b_y \\ b_z & 0 & -b_x \\ -b_y & b_x & 0 \end{bmatrix} \\ & = \begin{bmatrix} a_x 0 + a_y (-b_z) + a_z b_y \\ a_x b_z + a_y 0 + a_z (-b_x) \\ a_x (-b_y) + a_y b_x + a_z 0 \end{bmatrix}^T \\ & = \begin{bmatrix} a_y b_z - b_y a_z \\ a_z b_x - b_z a_x \\ a_x b_y - b_x a_y \end{bmatrix}^T \\ & = a \times x \end{aligned}

    And, indeed, it is skew-symmetric!

    • Matrix 1 belongs to robot 3.
    • Matrix 2 belongs to robot 1.
    • Matrix 3 belongs to robot 4.
    • Matrix 4 belongs to robot 2.
  4. \(M_{10 \times 10} v_{10 \times 1} = w_{10 \times 1}\)

    \begin{aligned} w = \begin{bmatrix} v_1 \\ v_2 - v_1 \\ v_3 - v_2 \\ v_4 - v_3 \\ v_5 - v_4 \\ v_6 - v_5 \\ v_7 - v_6 \\ v_8 - v_7 \\ v_9 - v_8 \\ v_{10} - v_9 \end{bmatrix} \end{aligned}

    It's a diagonal-ish matrix, tracing a diagonal line of -1, 1.

    \begin{aligned} M = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ -1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & -1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & -1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & -1 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & -1 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & -1 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & -1 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 & 1 \\ \end{bmatrix} \end{aligned}
  5. \(N_{10 \times 10} v_{10 \times 1} = w_{10 \times 1}\).

    I suppose that would be:

    \begin{aligned} N = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 0 \\ 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 \\ 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\ \end{bmatrix} \end{aligned}
    1. \(MN = ?!\) – Haven't got a clue. If N integrates, and M differentiates, maybe they cancel out?
    2. \(NM = ?!\) – Same here? Iuno maaaaan.
    3. We can probably do a few lines before finding the schtick.

      \begin{aligned} MN = \begin{bmatrix} (+1 \times 1) + (0 \times 1) + ... + (0 \times 1) = 1 & (1 \times 0) + (0 \times 1) + ... + (0 \times 1) = 0 & 0 ... \\ (-1 \times 1) + (1 \times 1) + (0 \times 1) ... + (0 \times 1) = 0 & (-1 \times 0) + (1 \times 1) + ... + (0 \times 1) = 1 & 0 ... \\ (0 \times 1) (-1 \times 1) + (1 \times 1) ... + (0 \times 1) = 0 & (0 \times 0) (-1 \times 1) + ... + (0 \times 1) = 1 & 0 ... \end{bmatrix} \end{aligned}

      Okay, that's the \(I_{10\times10}\) matrix.

      \begin{aligned} NM = \begin{bmatrix} (1 \times 1) + (0 \times -1) + (0 \times 0) ... + (0 \times 0) = 1 & (1 \times 0) + (0 \times 1) + (0 \times -1) ... + (0 \times 1) = 0 & 0 ... \\ (1 \times 1) + (1 \times -1) + (0 \times 0) ... + (0 \times 0) = 0 & (1 \times 0) + (1 \times 1) + (0 \times -1) + (0 \times 0) ... + (0 \times 0) = 1 & (1 \times 0) + (1 \times 0) + (0 \times 1) + (0 \times -1) ... + (0 \times 0) = 0 & 0 ... \\ (1 \times 1) + (1 \times -1) + (1 \times 0) ... + (0 \times 0) = 0 & (1 \times 0) + (1 \times 1) + (1 \times -1) + (0 \times 0) ... + (0 \times 0) = 0 & (1 \times 0) + (1 \times 0) + (1 \times 1) + (0 \times -1) + 0 ... + (0 \times 0) = 1 & 0 ... \\ \end{bmatrix} \end{aligned}

      Again the identity matrix. They're two forces equal in size but in the exact opposite directions, so we get the matrix of no change. Yes, I don't know if it makes sense theoretically, but as a metaphor, maybe.

Chapter 5.

Problem 2.

\begin{aligned} R_x(-22^\circ) & = \begin{bmatrix} 1 & 0 & 0 \\ 0 & cos(-22^\circ) & -sin(-22^\circ) \\ 0 & sin(-22^\circ) & cos(-22^\circ) \end{bmatrix} \end{aligned}

Looking at the book's solution, I see that what I have here is the transpose of Rx(θ). I would multiply an horizontal vector \(v\) and the rotation matrix like \(v R_x(-22^\circ)\), but I see that the book also multiplies it this way, even with its rotation matrix made of horizontal basis vectors \(R_x(\theta) = \begin{bmatrix} - p - \\ - q' - \\ - r' - \end{bmatrix}\).

Let's just try it with a vertical basis rotation matrix and an horizontal basis rotation matrix.

Their rotation matrix \(R_x(90^\circ)\):

\begin{aligned} v & = \begin{bmatrix} 1 & 1 & 1 \end{bmatrix} \\ R_x(90^\circ) & = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos(90^\circ) & \sin(90^\circ) \\ 0 & -\sin(90^\circ) & \cos(90^\circ) \end{bmatrix} \\ v R_x(90^\circ) & = \begin{bmatrix} 1 \times 1 + 1 \times 0 + 1 \times 0 \\ 1 \times 0 + 1 \times \cos(90^\circ) + 1 \times (-\sin(90^\circ)) \\ 1 \times 0 + 1 \times \sin(90^\circ) + 1 \times \cos(90^\circ) \end{bmatrix}^T \\ & = \begin{bmatrix} 1 \times 1 + 1 \times 0 + 1 \times 0 \\ 1 \times 0 + 1 \times 0 + 1 \times (-1) \\ 1 \times 0 + 1 \times 1 + 1 \times 0 \end{bmatrix}^T \\ & = \begin{bmatrix} 1 + 0 + 0 \\ 0 + 0 - 1 \\ 0 + 1 + 0 \end{bmatrix}^T \\ & = \begin{bmatrix} 1 \\ -1 \\ 1 \end{bmatrix}^T \\ & = \begin{bmatrix} 1 & -1 & 1 \end{bmatrix} \\ \end{aligned}

My badly constructed rotation(?!) matrix:

\begin{aligned} v & = \begin{bmatrix} 1 & 1 & 1 \end{bmatrix} \\ R_x(90) & = \begin{bmatrix} 1 & 0 & 0 \\ 0 & cos(90) & -sin(90) \\ 0 & sin(90) & cos(90) \end{bmatrix} v R_x(90^\circ) & = \begin{bmatrix} 1 \times 1 + 1 \times 0 + 1 \times 0 \\ 1 \times 0 + 1 \times \cos(90^\circ) + 1 \times \sin(90^\circ) \\ 1 \times 0 + 1 \times (-\sin(90^\circ)) + 1 \times \cos(90^\circ) \end{bmatrix}^T \\ & = \begin{bmatrix} 1 \times 1 + 1 \times 0 + 1 \times 0 \\ 1 \times 0 + 1 \times 0 + 1 \times 1 \\ 1 \times 0 + 1 \times (-1) + 1 \times 0 \end{bmatrix}^T \\ & = \begin{bmatrix} 1 + 0 + 0 \\ 0 + 0 + 1 \\ 0 - 1 + 0 \end{bmatrix}^T \\ & = \begin{bmatrix} 1 \\ 1 \\ -1 \end{bmatrix}^T \\ & = \begin{bmatrix} 1 & 1 & -1 \end{bmatrix} \\ \end{aligned}

A vector pointing at \(\begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix}^T\) turned \(90^\circ\) around the X axis would indeed point at \(\begin{bmatrix} 1 \\ -1 \\ 1 \end{bmatrix}^T\), and I was very very wrong about how one constructs matrices from basis vectors.

The source of the confusion was probably looking at

\begin{aligned} v' & = v_x \cdot \begin{bmatrix} p_x \\ p_y \\ p_z \end{bmatrix} + v_y \cdot \begin{bmatrix} q_x \\ q_y \\ q_z \end{bmatrix} + v_z \cdot \begin{bmatrix} r_x \\ r_y \\ r_z \end{bmatrix} \end{aligned}

and seeing all those tall vectors and confusing it with

\begin{aligned} v' & = \begin{bmatrix} v \cdot \begin{bmatrix} p_x \\ q_x \\ r_x \end{bmatrix}, & v \cdot \begin{bmatrix} p_y \\ q_y \\ r_y \end{bmatrix}, & v \cdot \begin{bmatrix} p_z \\ q_z \\ r_z \end{bmatrix} \end{bmatrix} \end{aligned}

Anyway, inner dot product between x component of vector with x components of the basis vectors, vy with py qy and ry, and vz with pz qz and rz.

Okay, so now that we know lets feed it:

\begin{aligned} R_x(-22^\circ) & = \begin{bmatrix} 1 & 0 & 0 \\ 0 & cos(-22^\circ) & sin(-22^\circ) \\ 0 & -sin(-22^\circ) & cos(-22^\circ) \end{bmatrix} & = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0.927 & -0.375 \\ 0 & 0.375 & 0.927 \end{bmatrix} \end{aligned}

That's about that.

Problem 3.

Using the left hand rule for a left hand space, we get basis vectors \(p'=\begin{bmatrix} cos(\theta) \\ 0 \\ -sin(\theta) \end{bmatrix}^T\), \(q'=\begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}^T\), \(r'=\begin{bmatrix} sin(\theta) \\ 0 \\ cos(\theta) \end{bmatrix}^T\).

Stackin' 'em up in a transformation matrix we get:

\begin{aligned} R_y(\theta) = \begin{bmatrix} cos(\theta) & 0 & -sin(\theta) \\ 0 & 1 & 0 \\ sin(\theta) & 0 & cos(\theta) \end{bmatrix} \end{aligned}

That's a pretty pretty pretty good looking matrix, innit?

Feed it with 30^ˆ:

\begin{aligned} R_y(30^\circ) & = \begin{bmatrix} cos(30^\circ) & 0 & -sin(30^\circ) \\ 0 & 1 & 0 \\ sin(30^\circ) & 0 & cos(30^\circ) \end{bmatrix} \\ & = \begin{bmatrix} 0.866 & 0 & -0.5 \\ 0 & 1 & 0 \\ 0.5 & 0 & 0.866 \end{bmatrix} \\ \end{aligned}

Problem 4.

Construct for \(\hat{n} = \begin{bmatrix} 0.267 & -0.535 & 0.802 \end{bmatrix}, \theta = -15^\circ, R(\hat{n}, \theta)\).

After reading the derivation, I want to write it again here from memory.

We split v into its parallel and perpendicular components \(v = v_\parallel + v_\perp\).

We find the parallel component with the inner dot product \(v_\parallel = (\hat{n} \cdot v) \hat{n}\).

Setting the value of the parallel componet to the inner dot product we get the perpendicular component \(v_\perp = v - (\hat{n} \cdot v) \hat{n}\).

A vector perpendicular to both \(\hat{n}\) and v⊥ is found using the cross product \(w = \hat{n} \times v_\perp\).

Because the parallel component of v does not change after a rotation, i.e. \(v'_\parallel = v_\parallel\), we can write \(v' = v'_\perp + v'_\parallel\) as \(v' = v'_\perp + v_\parallel\).

The vector v⊥ and w form the mutually perpendicular basis vectors of the plane on which we rotate \(v'_\perp\), so \(v'_\perp = cos(\theta) v_\perp + sin(\theta) w\).

Setting the value of \(v'_\perp\) into \(v' = v'_\perp + v_\parallel\) we get \(v' = cos(\theta) v_\perp + sin(\theta) w\).

All we now need to do is to set v with our concrete basis vectors p, q, and r, and algebraise.

Now let's skip all this boring stuff and use the existing book solution.

\begin{aligned} \begin{bmatrix} & \textnormal{Well, you know what?} \\ & & \textnormal{Let's not.} \\ & & & \textnormal{This is painful drudgery.} \\ & & & & \textnormal{Maybe later.} \end{bmatrix} \end{aligned}

Problem 5.

\begin{aligned} \begin{bmatrix} 2 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 2 \end{bmatrix} \end{aligned}

TODO Problem 6.

TODO Problem 7.

TODO Problem 8.

Problem 9.

a)

First rotation about the y-axis.

\begin{aligned} R_y(30^\circ) & = \begin{bmatrix} cos 30^\circ & 0 & -sin 30^\circ \\ 0 & 1 & 0 \\ sin 30^\circ & 0 & cos 30^\circ \end{bmatrix} \end{aligned}

Second rotation about the world x-axis.

\begin{aligned} R_x(-20^\circ) & = \begin{bmatrix} 1 & 0 & 0 \\ 0 & cos (-20^\circ) & sin (-20^\circ) \\ 0 & -sin (-20^\circ) & cos (-20^\circ) \end{bmatrix} \end{aligned}

Multiplying them together

\begin{aligned} p_{\textnormal{object}} & = \begin{bmatrix} 1 \times cos 30^\circ + 0 \times 0 + 0 \times sin 30^\circ \\ 1 \times 0 + 0 \times 1 + 0 \times 0 \\ 1 \times (-sin 30^\circ) + 0 \times 0 + 0 \times cos 30^\circ \end{bmatrix}^T \\ q_{\textnormal{object}} & = \begin{bmatrix} 0 \times cos 30^\circ + cos (-20^\circ) \times 0 + sin (-20^\circ) \times sin 30^\circ \\ 0 \times 0 + cos (-20^\circ) \times 1 + sin (-20^\circ) \times 0 \\ 0 \times (-sin 30^\circ) + cos (-20^\circ) \times 0 + sin (-20^\circ) \times cos 30^\circ \end{bmatrix}^T \\ r_{\textnormal{object}} & = \begin{bmatrix} 0 \times cos 30^\circ - sin (-20^\circ) \times 0 + cos (-20^\circ) \times sin 30^\circ \\ 0 \times 0 - sin (-20^\circ) \times 1 + cos (-20^\circ) \times 0 \\ 0 \times (-sin 30^\circ) - sin (-20^\circ) \times 0 + cos (-20^\circ) \times cos 30^\circ \end{bmatrix}^T \\ M_{\textnormal{object} \rightarrow \textnormal{world}} & = \begin{bmatrix} cos 30^\circ & 0 & -sin 30^\circ \\ sin (-20^\circ) \times sin 30^\circ & cos (-20^\circ) & sin (-20^\circ) \times cos 30^\circ \\ cos (-20^\circ) \times sin 30^\circ & -sin (-20^\circ) & cos (-20^\circ) \times cos 30^\circ \\ \end{bmatrix} \\ \end{aligned}

b)

Multiply \(R_x(20^\circ) R_y(-30^\circ)\).

TODO c)

???

Chapter 6.

1.

\(\begin{bmatrix} 3 & -2 \\ 1 & 4 \end{bmatrix} = 3 \times 4 - (-2) \times 1 = 12 + 2 = 14\)

2.

\(\begin{bmatrix} 3 & -2 & 0 \\ 1 & 4 & 0 \\ 0 & 0 & 2 \end{bmatrix}\)

  • Determinant.
    \begin{aligned} 3 \times \begin{vmatrix} 4 & 0 \\ 0 & 2 \end{vmatrix} - (-2) \begin{vmatrix} 1 & 0 \\ 0 & 2 \end{vmatrix} + 0 \begin{vmatrix} 1 & 4 \\ 0 & 0 \end{vmatrix} \\ = & 3 \times (4 \times 2 - 0 \times 0) - (-2) (1 \times 2 - 0 \times 0) + 0 (1 \times 0 - 4 \times 0) \\ = & 3 \times 8 - (-2) 2 \\ = & 24 - (-2) 2 \\ = & 28 \end{aligned}
  • Adjoint.
    • Minors.
      \begin{aligned} M^{\{11\}} & = \begin{vmatrix} 4 & 0 \\ 0 & 2 \end{vmatrix} = 8, & M^{\{12\}} & = \begin{vmatrix} 1 & 0 \\ 0 & 2 \end{vmatrix} = 2, & M^{\{13\}} & = \begin{vmatrix} 1 & 4 \\ 0 & 0 \end{vmatrix} = 0, \\ M^{\{21\}} & = \begin{vmatrix} -2 & 0 \\ 0 & 2 \end{vmatrix} = -4, & M^{\{22\}} & = \begin{vmatrix} 3 & 0 \\ 0 & 2 \end{vmatrix} = 6, & M^{\{23\}} & = \begin{vmatrix} 3 & -2 \\ 0 & 0 \end{vmatrix} = 0 \\ M^{\{31\}} & = \begin{vmatrix} -2 & 0 \\ 4 & 0 \end{vmatrix} = 0, & M^{\{32\}} & = \begin{vmatrix} 3 & 0 \\ 1 & 0 \end{vmatrix} = 0, & M^{\{33\}} & = \begin{vmatrix} 3 & -2 \\ 1 & 4 \end{vmatrix} = 14 \\ \end{aligned}
    • Cofactors.
      \begin{aligned} C^{\{11\}} & = (-1)^{1 + 1} 8 = 8, & C^{\{12\}} & = (-1)^{1 + 2} 2 = -2, & C^{\{13\}} & = (-1)^{1 + 3} 0 = 0 \\ C^{\{21\}} & = (-1)^{2 + 1} (-4) = 4, & C^{\{22\}} & = (-1)^{2 + 2} 6 = 6, & C^{\{23\}} & = (-1)^{2 + 3} 0 = 0 \\ C^{\{31\}} & = (-1)^{3 + 1} 0 = 0, & C^{\{32\}} & = (-1)^{3 + 2} 0 = 0, & C^{\{33\}} & = (-1)^{3 + 3} 14 = 14 \end{aligned}
    • Adjoint.
      \begin{aligned} adj \ \begin{bmatrix} 3 & -2 & 0 \\ 1 & 4 & 0 \\ 0 & 0 & 2 \end{bmatrix} = \begin{bmatrix} C^{\{11\}} & C^{\{12\}} & C^{\{13\}} \\ C^{\{21\}} & C^{\{22\}} & C^{\{23\}} \\ C^{\{31\}} & C^{\{32\}} & C^{\{33\}} \end{bmatrix}^T = \begin{bmatrix} 8 & -2 & 0 \\ 4 & 6 & 0 \\ 0 & 0 & 14 \end{bmatrix}^T = \begin{bmatrix} 8 & 4 & 0 \\ -2 & 6 & 0 \\ 0 & 0 & 14 \end{bmatrix} \end{aligned}
  • Inverse.
    \begin{aligned} & \begin{bmatrix} 3 & -2 & 0 \\ 1 & 4 & 0 \\ 0 & 0 & 2 \end{bmatrix}^{-1} \\ = & \frac{ adj \ \begin{bmatrix} 3 & -2 & 0 \\ 1 & 4 & 0 \\ 0 & 0 & 2 \end{bmatrix} }{ \begin{vmatrix} 3 & -2 & 0 \\ 1 & 4 & 0 \\ 0 & 0 & 2 \end{vmatrix} } \\ = & \frac{ \begin{bmatrix} 8 & 4 & 0 \\ -2 & 6 & 0 \\ 0 & 0 & 14 \end{bmatrix} }{28} \\ = & \frac{1}{28} \begin{bmatrix} 8 & 4 & 0 \\ -2 & 6 & 0 \\ 0 & 0 & 14 \end{bmatrix} \\ = & \begin{bmatrix} \frac{8}{28} & \frac{4}{28} & \frac{0}{28} \\ \frac{-2}{28} & \frac{6}{28} & \frac{0}{28} \\ \frac{0}{28} & \frac{0}{28} & \frac{14}{28} \end{bmatrix} \\ = & \begin{bmatrix} \frac{2}{7} & \frac{1}{7} & 0 \\ -\frac{1}{14} & \frac{3}{14} & 0 \\ 0 & 0 & \frac{1}{2} \end{bmatrix} \\ \end{aligned}

3.

\begin{aligned} \begin{bmatrix} -0.1495 & -0.1986 & -0.9685 \\ -0.8256 & 0.5640 & 0.0117 \\ -0.5439 & -0.8015 & 0.2484 \end{bmatrix} = \begin{bmatrix} - p - \\ - q - \\ - r - \end{bmatrix} \end{aligned}
(let ((p '(-0.1495 -0.1986 -0.9685))
      (q '(-0.8256 0.5640 0.0117))
      (r '(-0.5439 -0.8015 0.2484)))
  (list (cl-loop for n in p
                 for m in q
                 sum (* n m))
        (cl-loop for n in p
                 for m in r
                 sum (* n m))
        (cl-loop for n in q
                 for m in r
                 sum (* n m))))

Each of these are fairly small, so within the limits of writing not too many digits in a book's page, they're orthogonal.

4.

When a matrix is orthogonal, one can invert it by applying transposition:

\begin{aligned} & \begin{bmatrix} -0.1495 & -0.1986 & -0.9685 \\ -0.8256 & 0.5640 & 0.0117 \\ -0.5439 & -0.8015 & 0.2484 \end{bmatrix}^{-1} \\ = & \begin{bmatrix} -0.1495 & -0.1986 & -0.9685 \\ -0.8256 & 0.5640 & 0.0117 \\ -0.5439 & -0.8015 & 0.2484 \end{bmatrix}^T \\ = & \begin{bmatrix} -0.1495 & -0.8256 & -0.5439 \\ -0.1986 & 0.5640 & -0.8015 \\ -0.9685 & 0.0117 & 0.2484 \end{bmatrix} \end{aligned}

TODO 5

(let ((matrix '((-0.1495 -0.1986 -0.9658 0)
                (-0.8256 +0.5640 +0.0117 0)
                (-0.5439 -0.8015 +0.2484 0)
                (+1.7928 -5.3116 +8.0151 1))))
  (cl-loop for i from 0 to 3
           append
           (cl-loop for j from (1+ i) to 3
                    collect
                    (list
                     i j
                     (cl-loop for n in (nth i matrix)
                              for m in (nth j matrix)
                              sum (* n m))))))

No transposing into invertedness here.

6.

\begin{aligned} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 4 & 2 & 3 & 0 \end{bmatrix} \end{aligned}

7.

\begin{aligned} & \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos 20^\circ & \sin 20^\circ & 0 \\ 0 & -\sin 20^\circ & \cos 20^\circ & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 4 & 2 & 3 & 1 \end{bmatrix} \\ = & \begin{bmatrix} 1 \times 1 + 0 \times 0 + 0 \times 0 + 0 \times 4 & 1 \times 0 + 0 \times 1 + 0 \times 0 + 0 \times 2 & 1 \times 0 + 0 \times 0 + 0 \times 1 + 0 \times 3 & 1 \times 0 + 0 \times 0 + 0 \times 0 + 0 \times 1 \\ 0 \times 1 + \cos 20^\circ \times 0 + \sin 20^\circ \times 0 + 0 \times 4 & 0 \times 0 + \cos 20^\circ \times 1 + \sin 20^\circ \times 0 + 0 \times 2 & 0 \times 0 + \cos 20^\circ \times 0 + \sin 20^\circ \times 1 + 0 \times 3 & 0 \times 0 + \cos 20^\circ \times 0 + \sin 20^\circ \times 0 + 0 \times 1 \\ 0 \times 1 + (-\sin 20^\circ \times 0) + \cos 20^\circ \times 0 + 0 \times 4 & 0 \times 0 + (-\sin 20^\circ \times 1) + \cos 20^\circ \times 0 + 0 \times 2 & 0 \times 0 + (-\sin 20^\circ \times 0) + \cos 20^\circ \times 1 + 0 \times 3 & 0 \times 0 + (-\sin 20^\circ \times 0) + \cos 20^\circ \times 0 + 0 \times 1 \\ 0 \times 1 + 0 \times 0 + 0 \times 0 + 1 \times 4 & 0 \times 0 + 0 \times 1 + 0 \times 0 + 1 \times 2 & 0 \times 0 + 0 \times 0 + 0 \times 1 + 1 \times 3 & 0 \times 0 + 0 \times 0 + 0 \times 0 + 1 \times 1 \end{bmatrix} \\ = & \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos 20^\circ & \sin 20^\circ & 0 \\ 0 & -\sin 20^\circ & \cos 20^\circ & 0 \\ 4 & 2 & 3 & 1 \end{bmatrix} \end{aligned}

8.

\begin{aligned} & \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 4 & 2 & 3 & 1 \end{bmatrix} \cdot \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos 20^\circ & \sin 20^\circ & 0 \\ 0 & -\sin 20^\circ & \cos 20^\circ & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \\ = & \begin{bmatrix} 1 \times 1 + 0 \times 0 + 0 \times 0 + 0 \times 0 & 1 \times 0 + 0 \times \cos 20^\circ + 0 \times (-\sin 20^\circ) + 0 \times 0 & 1 \times 0 + 0 \times \sin 20^\circ + 0 \times \cos 20^\circ + 0 \times 0 & 1 \times 0 + 0 \times 0 + 0 \times 0 + 0 \times 1 \\ 0 \times 1 + 1 \times 0 + 0 \times 0 + 0 \times 0 & 0 \times 0 + 1 \times \cos 20^\circ + 0 \times (-\sin 20^\circ) + 0 \times 0 & 0 \times 0 + 1 \times \sin 20^\circ + 0 \times \cos 20^\circ + 0 \times 0 & 0 \times 0 + 1 \times 0 + 0 \times 0 + 0 \times 1 \\ 0 \times 1 + 0 \times 0 + 1 \times 0 + 0 \times 0 & 0 \times 0 + 0 \times \cos 20^\circ + 1 \times (-\sin 20^\circ) + 0 \times 0 & 0 \times 0 + 0 \times \sin 20^\circ + 1 \times \cos 20^\circ + 0 \times 0 & 0 \times 0 + 0 \times 0 + 1 \times 0 + 0 \times 1 \\ 4 \times 1 + 2 \times 0 + 3 \times 0 + 1 \times 0 & 4 \times 0 + 2 \times \cos 20^\circ + 3 \times (-\sin 20^\circ) + 1 \times 0 & 4 \times 0 + 2 \times \sin 20^\circ + 3 \times \cos 20^\circ + 1 \times 0 & 4 \times 0 + 2 \times 0 + 3 \times 0 + 1 \times 1 \end{bmatrix} \\ = & \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos 20^\circ & \sin 20^\circ & 0 \\ 0 & -\sin 20^\circ & \cos 20^\circ & 0 \\ 4 & 2 \cos 20^\circ -3 \sin 20^\circ & 2 \sin 20^\circ + 3 \cos 20^\circ & 1 \end{bmatrix} \end{aligned}

9.

\begin{aligned} \begin{bmatrix} 1 & 0 & 0 & \frac{1}{5} 0 & 1 & 0 & 0 0 & 0 & 1 & 0 0 & 0 & 0 & 0 \end{bmatrix} \end{aligned}

10.

We have \(v = \begin{bmatrix} 105 & -243 & 89 & 1 \end{bmatrix}\) and we want to project it on a plane at \(x = 5\).

We define a projection matrix as in the last exercise.

\begin{aligned} M = \begin{bmatrix} 1 & 0 & 0 & \frac{1}{5} \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 \end{bmatrix} \end{aligned}

And multiply:

\begin{aligned} v \cdot M = & \begin{bmatrix} 105 & -243 & 89 & 1 \end{bmatrix} \cdot \begin{bmatrix} 1 & 0 & 0 & \frac{1}{5} \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 \end{bmatrix} \\ = & \begin{bmatrix} 105 \times 1 + (-243) \times 0 + 89 \times 0 + 1 \times 0 \\ 105 \times 0 + (-243) \times 1 + 89 \times 0 + 1 \times 0 \\ 105 \times 0 + (-243) \times 0 + 89 \times 1 + 1 \times 0 \\ 105 \times \frac{1}{5} + (-243) \times 0 + 89 \times 0 + 1 \times 0 \end{bmatrix}^T \\ = & \begin{bmatrix} 105 \times 1 \\ (-243) \times 1 \\ 89 \times 1 \\ \frac{105}{5} \end{bmatrix}^T \\ = & \begin{bmatrix} 105 \\ -243 \\ 89 \\ \frac{105}{5} \end{bmatrix}^T \end{aligned}

Now we do so:

\begin{aligned} v & = \begin{bmatrix} 105 \\ -243 \\ 89 \\ \frac{105}{5} \end{bmatrix}^T \\ v' & = \frac{1}{v_w} \begin{bmatrix} 105 \\ -243 \\ 89 \end{bmatrix}^T = \frac{5}{105} \begin{bmatrix} 105 \\ -243 \\ 89 \end{bmatrix}^T = \begin{bmatrix} \frac{5}{105} \times 105 \\ \frac{5}{105} \times (-243) \\ \frac{5}{105} \times 89 \end{bmatrix}^T = \begin{bmatrix} 5 \\ -11.57 \\ 4.24 \end{bmatrix}^T \end{aligned}

Now we do it using the equation:

\begin{aligned} v' = & \begin{bmatrix} dx/x \\ dy/x \\ dz/x \end{bmatrix}^T = \begin{bmatrix} 5 \times 105 / 105 \\ 5 \times (-243) / 105 \\ 5 \times 89 / 105 \end{bmatrix}^T = \begin{bmatrix} 5 \\ -11.57 \\ 4.24 \end{bmatrix}^T \end{aligned}

Chapter 7.

1.

\begin{aligned} a = & (2, 60^\circ) \\ & \textnormal{in Cartesian coordinates:} \\ = & (2 \times \cos 60^\circ, 2 \times \sin 60^\circ) \\ = & (2 \times 0.5, 2 \times \sin 60^\circ) \\ = & (1, 1.73) \\ b = & (5, 195^\circ) \\ & \textnormal{in Cartesian coordinates:} \\ = & (5 \times \cos 195^{\circ}, 5 \sin 195^{\circ}) \\ = & (5 \times (-0.966), 5 \times (-0.259)) \\ = & (-4.83, -1.30) \\ c = & (3, -45^\circ) \\ & \textnormal{in Cartesian coordinates:} \\ = & (3 \times \cos (-45^\circ), 3 \times \sin (-45^\circ)) \\ = & (3 \times 0.707, 3 \times -0.707) \\ = & (2.12, -2.12) \\ d = & (-2.75, 300^\circ) \\ & \textnormal{in Cartesian coordinates:} \\ = & (-2.75 \cos 300^\circ, -2.75 \sin 300^\circ) \\ = & (-1.38, 2.38) \\ e = & (4, \frac{\pi}{6} \textnormal{rad}) \\ & \textnormal{in Cartesian coordinates:} \\ = & (4 \cos (\frac{\pi}{6} \textnormal{rad}), 4 \sin (\frac{\pi}{6} \textnormal{rad})) \\ = & (3.46, 2.00) \\ f = & (1, \frac{4\pi}{3} \textnormal{rad}) \\ = & (\cos \frac{4\pi}{3}, \sin \frac{4\pi}{3}) \\ = & (-0.500, -0.866) \\ g = & (-\frac{5}{2}, -\frac{\pi}{2} \textnormal{rad}) \\ = & (-2.5 \times \cos (-\frac{\pi}{2} \textnormal{rad}), -2.5 \times \sin (-\frac{\pi}{2} \textnormal{rad})) \\ = & (0, 2.5) \end{aligned}

Mind you, SVG's vertical Y axis points downwards on the screen.

2.

\begin{aligned} a = & (4, 207^\circ) \\ = & (4, 207^\circ - 360^\circ) \\ = & (4, -153^\circ) \\ b = & (-5, 720^\circ) \\ = & (5, 900^\circ) \\ = & (5, 540^\circ) \\ = & (5, 180^\circ) \\ c = & (0, 45.2^\circ) \\ = & (0, 0^\circ) \\ d = & (12.6, \frac{11 \pi}{4}) \\ = & (12.6, \frac{11 \times 180^\circ}{4}) \\ = & (12.6, 495^\circ) \\ = & (12.6, 135^\circ) \end{aligned}

3.

1, 45°

cos 45°, sin 45°

cos 45 tau / 360, sin 45 tau / 360

(cl-loop for v in '((1 (deg 45))
                    (3 (deg 0))
                    (4 (deg 90))
                    (10 (deg -30))
                    (5.5 (rad 0.5)))
         collect (let* ((radius (car v))
                        (type (caadr v))
                        (angle (cadadr v)))
                   (cond ((eq type 'rad)
                          (list (* radius (cos angle))
                                (* radius (sin angle))))
                         ((eq type 'deg)
                          (list (* radius (cos (* float-pi angle (/ 180.0))))
                                (* radius (sin (* float-pi angle (/ 180.0)))))))))

4.

\begin{aligned} a = & (4, -153^\circ) \\ b = & (5, 180^\circ) \\ c = & (0, 0^\circ) \\ d = & (12.6, 135^\circ) \end{aligned}

AAAAA.

5.

  • 10, 20

    sqrt(10 * 10 + 20 * 20), atan2(20, 10)

    (sqrt (+ (* 10 10) (* 20 20))), (atan (/ 20.0 10.0))

    22.360679774997898, 1.1071487177940904 rad

  • -12, -5

    sqrt((-12) * (-12) + (-5) * (-5)), atan2(-5, -12)

    (sqrt (+ (* -12 -12) (* -5 -5))), (- (atan (/ -5.0 -12.0)) float-pi)

    (sqrt (+ 144 25)), -2.7468015338900313 rad

    (sqrt 169 nice)), -2.7468015338900313 rad

    13, -2.7468015338900313 rad

  • 0, 4.5

    sqrt(4.5 * 4.5), atan2(4.5, 0)

    4.5, 90 °

  • -3, 4

    (sqrt (+ (* -3 -3) (* 4 4))), atan2(4, -3)

    (sqrt (+ (* -3 -3) (* 4 4))), atan2(4, -3)

    (sqrt (+ 9 16)), atan2(4, -3)

    (sqrt 25), atan2(4, -3)

    5, atan2(4, -3)

  • 0, 0

    0, 0

  • -5280, 0

    5280, (atan2 0 -5280)

    5280, (+ (atan (/ 0 -5280)) float-pi)

    5280, (+ (atan 0) float-pi)

    5280, (+ 0 float-pi)

    5280, \(\frac{\tau}{2}\)

(defun atan2 (y x)
  (cond ((= x 0.0) (cond ((> y 0.0) float-pi)
                         ((< y 0.0) float-pi)
                         ((= y 0.0) 0.0)))
        ((> x 0.0) (atan (/ y x)))
        ((< x 0.0) (cond ((>= y 0.0) (+ (atan (/ y x)) float-pi))
                         ((< y 0.0) (- (atan (/ y x)) float-pi))))))

(cl-loop for v in '((10 20)
                    (-12 -5)
                    (0 4.5)
                    (-3 4)
                    (0 0)
                    (-5280 0))
         collect (let ((x (float (car v)))
                       (y (float (cadr v))))
                   (list (sqrt (+ (* x x) (* y y)))
                         (atan2 y x))))

6.

  • 4, 120°, 5.

    4 cos 120 °, 4 sin 120 °, 5.

    (* 4 (cos (* (float 120) float-pi (/ (float 180))))), (* 4 (sin (* (float 120) float-pi (/ (float 180))))), 5.

    -2, 3.464101615137755, 5.

  • 2, 45°, -1.

    (* 2.0 (cos (* 45.0 float-pi (/ 180.0)))), (* 2.0 (sin (* 45.0 float-pi (/ 180.0)))), -1.

    1.4142135623730951, 1.414213562373095, -1.

  • 6, -π/6 rad, -3.

    (* 6 (cos (- (/ float-pi 6.0)))), (* 6 (sin (- (/ float-pi 6)))), -3.

    5.196152422706632, -2.9999999999999996, -3.

  • 3, 3/π, 1

    (* 3 (cos (* 3 float-pi)), (* 3 (sin (* 3 float-pi)), 1

    -3.0, 1.102182119232618e-15, 1

(cl-loop for v in `((4 (deg 120) 5)
                    (2 (deg 45) -1)
                    (6 (rad ,(- (/ float-pi 6))) -3)
                    (3 (rad ,(* 3 float-pi)) 1))
         collect (let* ((radius (float (car v)))
                        (type (car (cadr v)))
                        (angle (cadr (cadr v)))
                        (theta (cond ((eq type 'deg) (* angle float-pi (/ 180.0)))
                                     ((eq type 'rad) angle)))
                        (z (caddr v)))
                   (list (* radius (cos theta))
                         (* radius (sin theta))
                         z)))

7.

  • 1, 1, 1.

    (sqrt 2.0), (atan2 1.0 1.0), 1.

    1.4142135623730951, (atan (/ 1.0 1.0)), 1.

    1.4142135623730951, (atan 1), 1.

    1.4142135623730951, 0.7853981633974483, 1.

  • 0, -5, 2.

    5, (atan2 -5.0 0.0), 2.

    5, -90 °, 2.

  • -3, 4, -7.

    (sqrt (+ (* -3 -3) (* 4 4))), (atan2 4 -3), -7.

    5, (+ (atan 4 -3) float-pi), -7.

    5, 5.355890089177974, -7.

  • 0, 0, -3.

    0, 0, -3.

8.

  • 4, π / 3, 3 π / 4.

    4 cos (3 π / 4) cos (π / 3), 4 cos (3 π / 4) sin (π / 3), 4 cos 3 π / 4.

    (* 4 (cos (* 3.0 float-pi (/ 4.0))) (cos (* float-pi (/ 3.0)))), (* 4.0 (cos (* 3.0 float-pi (/ 4.0))) (sin (/ float-pi 3.0))), (* 4.0 (cos (* 3.0 float-pi (/ 4.0)))).

    -1.4142135623730951, -2.449489742783178, -2.82842712474619.

  • 5, -5 π / 6, π / 3.

    5 cos (π / 3) cos (-5 π / 6), 5 cos (π / 3) sin (-5 π / 6), 5 cos (π / 3).

    (* 5.0 (cos (/ float-pi 3.0)) (cos (* -5.0 float-pi (/ 6.0)))), (* 5.0 (cos (/ float-pi 3.0)) (sin (* -5.0 float-pi (/ 6.0)))), (* 5.0 (cos (/ float-pi 3.0))).

    -2.1650635094610964, -1.250000000000001, 2.5000000000000004.

  • 2, -π / 6, π.

    2 cos(π) cos(-π / 6), 2 cos(π) sin(-π / 6), 2 cos(π).

    (* 2.0 (cos float-pi) (cos (/ float-pi -6.0))), (* 2.0 (cos float-pi) (sin (/ float-pi -6.0))), (* 2.0 (cos float-pi).

    (-1.7320508075688774 0.9999999999999999 -2.0).

  • 8, 9 π / 4, π / 6.

    (list (* 8.0 (cos (/ float-pi 6.0)) (cos (* 9.0 float-pi (/ 4.0)))) (* 8.0 (cos (/ float-pi 6.0)) (sin (* 9.0 float-pi (/ 4.0)))) (* 8.0 (cos (/ float-pi 6.0))))

    (4.8989794855663575 4.898979485566356 6.92820323027551)

9.

    • x = r cos p sin h
    • y = -r sin p
    • z = r cos p cos h
  • 4, π / 3, 3 π / 4.

    r = 4.

    h = π / 3.

    p = 3 π / 4.

    d = r cos p = 4 cos (3π/4).

    y = -r sin p = -4 sin (3π/4).

    x = d sin h = r cos p sin h = 4 cos (3π4) sin (π/3).

    z = d cos h = r cos p cos h = 4 cos (3π4) cos (π/3).

    `((,(* 4.0
           (cos (* 3.0 float-pi (/ 4.0)))
           (sin (/ float-pi 3.0))))
      (,(* -4.0
           (sin (* 3.0 float-pi (/ 4.0)))))
      (,(* 4.0
           (cos (* 3.0 float-pi (/ 4.0)))
           (cos (/ float-pi 3.0)))))
    
  • 5, -5 π / 6, π / 3.

    r = 5.

    h = -5π/6.

    p = π/3.

    d = r cos p = 5 cos (π/3)

    y = -5 sin (π/3)

    x = r cos p sin h = 5 cos (π/3) sin (-5π/6)

    z = r cos p cos h = 5 cos (π/3) cos (-5π/6)

    `((,(* 5.0 (cos (/ float-pi 3.0)) (sin (* -5.0 float-pi (/ 6.0)))))
      (,(* -5.0 (sin (/ float-pi 3.0))))
      (,(* 5.0 (cos (/ float-pi 3.0)) (cos (* -5.0 float-pi (/ 6.0))))))
    
  • 2, -π / 6, π.

    r = 2.

    h = -π/6.

    p = π.

    d = r cos p = 2 cos π.

    y = -r sin p = -2 cos π.

    x = r cos p sin h = 2 cos (π) sin (-π/6).

    z = r cos p cos h = 2 cos (π) cos (-π/6).

    `((,(* 2.0 (cos float-pi) (sin (/ float-pi -6.0))))
      (,(* -2.0 (sin float-pi)))
      (,(* 2.0 (cos float-pi) (cos (/ float-pi -6.0)))))
    
  • 8, 9 π / 4, π / 6.

    r = 8.

    h = 9π/4.

    p = π/6.

    d = r cos p = 8 cos (π/6).

    y = -r sin p = -8 cos (π/6).

    x = r cos p sin h = 8 cos (π/6) sin (9π/4).

    z = r cos p cos h = 8 cos (π/6) cos (9π/4).

    `((,(* 8.0 (cos (/ float-pi 6.0)) (sin (* 9.0 float-pi (/ 4.0)))))
      (,(* 8.0 (sin (/ float-pi 6.0))))
      (,(* 8.0 (cos (/ float-pi 6.0)) (sin (* 9.0 float-pi (/ 4.0))))))
    

10.

Y r d p y(V) Z X r h x(V) z(V)

Using the above diagrams we can find the Gamemath polar coordinates of some \(v = \begin{bmatrix} x(v) & y(v) & z(v) \end{bmatrix}\) whose three Cartesian coordinates are known in a left handed 3D space.

We will use:

  • Radius using Pythagoras's thingamajig!

    \begin{aligned} r = sqrt(x(v)^2 + y(v)^2 + z(v)^2) \end{aligned}
  • Heading using Eytan Mark Bet!

    \begin{aligned} h = \textnormal{atan2}(x(v), z(v)) \end{aligned}
  • And pitch using algebra! (not \(p = \textnormal{atan2}(y(v), d) = \textnormal{atan2}(y(v), \sqrt{x(v)^2 + z(v)^2})\), which is close but no cigar, alas.)

    \begin{aligned} y = & - r \sin p & & \textnormal{divide by} \ (-r) \\ -y / r = & \sin p & & \textnormal{strain through} \arcsin \\ \arcsin(-y / r) = & p \\ p = & \arcsin(-y / r) \end{aligned}

With that we can define the GaMaPoCoSy, or the GameMath Polar Coordinate System:

\begin{aligned} \begin{bmatrix} r & h & p \end{bmatrix} \end{aligned}
  • \(x = \sqrt{2}; y = 2 \sqrt{3}; z = -\sqrt{2}\).

    \begin{aligned} x = & \sqrt{2} \\ y = & 2 \sqrt{3} \\ z = & -\sqrt{2} \\ r = & \sqrt{x^2 + y^2 + z^2} \\ = & \sqrt{\sqrt{2}^2 + (2 \sqrt{3})^2 + (-\sqrt{2})^2} \\ = & \sqrt{2 + 4 * 3 + 2} \\ = & \sqrt{4 + 12} \\ = & \sqrt{16} \\ = & 4 \\ h = & \textnormal{atan2}(x, z) \\ = & \textnormal{atan2}(\sqrt{2}, -\sqrt{2}) = \\ = & \arctan(\sqrt{2} / (-\sqrt{2})) + 180^\circ = \\ = & \arctan(-1) + 180^\circ = \\ = & \textnormal{(+ (atan -1) float-pi)} \\ = & 2.356194490192345 \\ p = & \arcsin(-y/r) \\ = & \arcsin(-2 \sqrt{3} / r) \\ = & -1.0471975511965976 \end{aligned}
  • \(x = 2 \sqrt{3}; y = 6; z = -4\).

    \begin{aligned} x = & 2 \sqrt{3} \\ y = & 6 \\ z = & -4 \\ r = & \sqrt{x^2 + y^2 + z^2} \\ = & \sqrt{(2 \sqrt{3})^2 + 6^2 + (-4)^2} \\ = & \sqrt{4 \times 3 + 36 + 16} \\ = & \sqrt{12 + 36 + 16} \\ = & \sqrt{64} \\ = & 8 \\ h = & \textnormal{atan2}(x, z) \\ = & \textnormal{atan2}(2 \sqrt{3}, -4) = \\ = & \arctan(2 \sqrt{3} / (-4)) + 180^\circ = \\ = & 2.4278682746450277 \\ p = & \arcsin(-y/r) \\ = & \arcsin(-6 / 8) \\ = & \arcsin(-3 / 4) \\ = & -0.848062078981481 \end{aligned}
  • \(x = -1; y = -1; z = -1\).

    \begin{aligned} x = & -1 \\ y = & -1 \\ z = & -1 \\ r = & \sqrt{x^2 + y^2 + z^2} \\ = & \sqrt{3(-1)^2} \\ = & \sqrt{3} \\ = & 1.7320508075688772 \\ h = & \textnormal{atan2}(x, z) \\ = & \textnormal{atan2}(-1, -1) = \\ = & \arctan(-1 / -1) - 180^\circ = \\ = & \arctan(1) - 180^\circ = \\ = & \textnormal{(- (atan 1.0) float-pi)} \\ = & -2.356194490192345 \\ p = & \arcsin(-y/r) \\ = & \arcsin(1 / 1.7320508075688772) \\ = & \textnormal{(asin (/ 1.7320508075688772))} \\ = & 0.6154797086703875 \end{aligned}
  • \(x = 2; y = -2 \sqrt{3}; z = 4\).

    \begin{aligned} x = & 2 \\ y = & -2 \sqrt{3} \\ z = & 4 \\ r = & \sqrt{x^2 + y^2 + z^2} \\ = & \sqrt{4 + 4 \times 3 + 16} \\ = & \sqrt{4 + 12 + 16} \\ = & \sqrt{16 + 16} \\ = & \sqrt{32} \\ = & \sqrt{(2 \times 2) \times (2 \times 2) \times 2} \\ = & \sqrt{4^2 \times 2} \\ = & \sqrt{4^2} \sqrt{2} \\ = & 4 \times \sqrt{2} \\ = & \textnormal{(* 4 (sqrt 2))} \\ = & 5.656854249492381 \\ h = & \textnormal{atan2}(x, z) \\ = & \textnormal{atan2}(2, 4) \\ = & \arctan(2 / 4) \\ = & \arctan(1 / 2) \\ = & \textnormal{(atan (/ 2.0))} \\ = & 0.4636476090008061 \\ p = & \arcsin(-y/r) \\ = & \arcsin(2 \sqrt{3} / 5.656854249492381) \\ = & \textnormal{(asin (* 2 (sqrt 3) (/ 5.656854249492381)))} \\ = & 0.6590580358264089 \end{aligned}
  • \(x = -\sqrt{3}; y = -\sqrt{3}; z = 2 \sqrt{2}\).

    \begin{aligned} x = & -\sqrt{3} \\ y = & -\sqrt{3} \\ z = & 2 \sqrt{2} \\ r = & \sqrt{x^2 + y^2 + z^2} \\ = & \sqrt{3 + 3 + 4 * 2} \\ = & \sqrt{6 + 8} \\ = & \sqrt{14} \\ = & \textnormal{(sqrt 14)} \\ = & 3.7416573867739413 \\ h = & \textnormal{atan2}(x, z) \\ = & \textnormal{atan2}(-\sqrt{3}, 2 \sqrt{2}) \\ = & \arctan(-\sqrt{3} / (2 \sqrt{2})) \\ = & \textnormal{(atan (/ (- (sqrt 3)) (* 2.0 (sqrt 2))))} \\ = & -0.5494672447576273 \\ p = & \arcsin(-y/r) \\ = & \arcsin(\sqrt{3} / 3.7416573867739413) \\ = & \textnormal{(asin (/ (sqrt 3) 3.7416573867739413))} \\ = & 0.4812753739423435 \end{aligned}
  • \(x = 3; y = 4; z = 12\).

    \begin{aligned} x = & 3 \\ y = & 4 \\ z = & 12 \\ r = & \sqrt{x^2 + y^2 + z^2} \\ = & \sqrt{9 + 16 + 12 * 12} \\ = & \sqrt{9 + 16 + 100 + 20 + 20 + 4} \\ = & \sqrt{9 + 16 + 144} \\ = & \sqrt{25 + 144} \\ = & \sqrt{169 \ \textnormal{nice}} \\ = & \textnormal{(sqrt 169) ;; nice} \\ & \textnormal{Hey, now!} \\ & \textnormal{I'm rote learning and it's extremely boring,} \\ & \textnormal{so I'm trying to entertain myself a wee bit} \\ & \textnormal{by adding a lame joke here and there between} \\ & \textnormal{the atan2s and sqrts and asins, it's no sin.} \\ & \textnormal{So give me a rest now why won'tcha!} \\ = & 13.0 \\ h = & \textnormal{atan2}(x, z) \\ = & \textnormal{atan2}(3, 12) \\ = & \arctan(3 / 12) \\ = & \textnormal{(atan (/ 3.0 12.0))} \\ = & 0.24497866312686414 \\ p = & \arcsin(-y/r) \\ = & \arcsin(-4 / 13) \\ = & \textnormal{(asin (/ -4.0 13.0))} \\ = & -0.312766721941545 \end{aligned}
(defun kakafarm/vec3-cartesian-to-polar (v)
  (let* ((x (float (car v)))
         (y (float (cadr v)))
         (z (float (caddr v)))
         (radius (sqrt (+ (* x x) (* y y) (* z z)))))
    (if (> radius 0.0)
        (let ((pitch (asin (/ (- y) radius))))
          (if (>= (abs pitch)
                  (* 2.0 float-pi 0.9999))
              (list radius 0.0 pitch)
            (list radius (kakafarm/atan2 x z) pitch)))
      (list 0.0 0.0 0.0))))


(cons (list 'radius 'heading 'pitch)
      (cl-loop for v in (list (list (sqrt 2) (* 2 (sqrt 3)) (- (sqrt 2)))
                              (list (* 2 (sqrt 3)) 6 -4)
                              (list -1 -1 -1)
                              (list 2 (* -2 (sqrt 3)) 4)
                              (list (- (sqrt 3)) (- (sqrt 3)) (* 2 (sqrt 2)))
                              (list 3 4 12))
               collect (kakafarm/vec3-cartesian-to-polar v)))

11.

Nice!

  • A fixed radius is the surface of a sphere.
  • A fixed heading would be a plane that includes the Y axis.
  • A fixed pitch would be the surface of two mirror cones with their tips touching at the origin. Looks like light cones.

12.

Har har… at least you didn't make a penguin eaten by a polar bear joke.

I suppose the authors were also losing their minds writing this book the same way I'm losing my mind reading it.

8. Rotation in Three Dimensions.

DONE 1.

  • State "DONE" from "TODO" [2026-10-20 Tue 16:16]
  • a -> 5.
  • b -> 3.
  • c -> 6.
  • d -> 1.
  • e -> 2.
  • f -> 4.

DONE 2.

  • State "DONE" from "TODO" [2026-10-20 Tue 17:42]
  • a -> 3. Canonical.
  • b -> 4. Canonical.
  • c -> 5. Non-canonical. In a canonical trio, when pitch is 1/4 or -1/4 a turn, bank must be zero, which isn't the case here.
  • d -> 1. Canonical.
  • e -> 2. Canonical.
  • f -> 3. Non-canonical. In a canonical trio, pitch must be within \([-\frac{\tau}{4} \textnormal{rad}, +\frac{\tau}{4} \textnormal{rad}]\).
  • g -> 5. Canonical.
  • h -> 2. Non-canonical. Pitch cannot be smaller than \(-90^\circ\).
  • i -> 6. Cnonical.

DONE 3.

  • State "DONE" from "TODO" [2026-10-21 Wed 01:17]

DONE 1.

  • State "DONE" from "TODO" [2026-10-19 Mon 01:12]
\begin{aligned} & \begin{bmatrix} \cos(30^\circ/2) & \sin(30^\circ/2) \begin{bmatrix} 1 & 0 & 0 \end{bmatrix} \end{bmatrix} \\ & = \begin{bmatrix} \cos(30^\circ/2) & \begin{bmatrix} \sin(30^\circ/2) & 0 & 0 \end{bmatrix} \end{bmatrix} \end{aligned}

DONE 2.

  • State "DONE" from "TODO" [2026-10-19 Mon 01:15]
\begin{aligned} |q| & = \sqrt{w^2 + x^2 + y^2 + z^2} \\ & = \sqrt{cos^2(30^\circ/2) + sin^2(30^\circ/2)} \\ & = \sqrt{1} \\ & = 1 \end{aligned}

DONE 3.

  • State "DONE" from "TODO" [2026-10-19 Mon 01:21]

If \(q = \begin{bmatrix} w & v \end{bmatrix}\), then \(q^* = \begin{bmatrix} w & -v \end{bmatrix}\).

In our case \(q = \begin{bmatrix} \cos(30^\circ/2) & \begin{bmatrix} \sin(30^\circ/2) \\ 0 \\ 0 \end{bmatrix} \end{bmatrix}\), therefore \(q = \begin{bmatrix} \cos(30^\circ/2) & \begin{bmatrix} -\sin(30^\circ/2) \\ 0 \\ 0 \end{bmatrix} \end{bmatrix}\).

DONE 4.

  • State "DONE" from "TODO" [2026-10-21 Wed 01:17]

We have the following quaternion and we want to convert it into oy-ler angles.

w = cos(30^ˆ/2) x = sin(30^ˆ/2) y = 0 z = 0

p = \arcsin(-2 (yz - wx))
  = \arcsin(-2 (0 - \cos(30^\circ/2) \sin(30^\circ/2)))
  = \arcsin(2\cos(..)\sin(..))
  = \arcsin(\sin(30^\circ))
  = 30^\circ
h = atan2(xz + wy, 1/2 - x^2 - y^2)
  = atan2(0 + 0, 1/2 - \sin^2(..) - 0)
  = atan2(0, 1/2 - \sin^2(..) - 0)
  = 0
b = atan2(xy + wz, 1/2 - x^2 - z^2)
  = atan2(0, ...)
  = 0

I'm a retard. Of course a 30 agrees on the x-axis is just a fucking pitch.

TODO 4.

  • a - [-1 0 0 0].

    this is the identity quaternion.

    It fits 2.

  • b - [0.653 -0.653 -0.271 -0.271].

    ;; p = arcsin(-2((-0.271)(-0.271) - 0.653(-0.653)))
    
    (* (/ 180.0 float-pi)
       (asin (* -2.0
                (- (* -0.271 -0.271)
                   (* 0.653 -0.653)))))
    
  • c - [0.364 -0.].

TODO 5.

DONE 6.

\begin{aligned} q1 q2 & = \begin{bmatrix} w_1 & v_1 \end{bmatrix} \begin{bmatrix} w_1 & v_2 \end{bmatrix} \\ & = (w_1 + x_1 i + y_1 j + z_1 k) (w_2 + x_2 i + y_2 j + z_2 k) \\ & = w_1 w_2 + w_1 (x_2 i) + w_1 (y_2 j) + w_1 (z_2 k) \\ & = (x_1 i) w_2 + (x_1 i) (x_2 i) + (x_1 i) (y_2 j) + (x_1 i) (z_2 k) \\ & = (y_1 j) w_2 + (y_1 j) (x_2 i) + (y_1 j) (y_2 j) + (y_1 j) (z_2 k) \\ & = (z_1 k) w_2 + (z_1 k) (x_2 i) + (z_1 k) (y_2 j) + (z_1 k) (z_2 k) \\ & = w_1 w_2 + w_1 x_2 i + w_1 y_2 j + w_1 z_2 k \\ & = x_1 w_2 i + x_1 x_2 i i + x_1 y_2 i j + x_1 z_2 i k \\ & = y_1 w_2 j + y_1 x_2 j i + y_1 y_2 j j + y_1 z_2 j k \\ & = z_1 w_2 k + z_1 x_2 k i + z_1 y_2 k j + z_1 z_2 k k \\ \textnormal{bases multiplications:} \\ ii & = jj = kk = -1 \\ ij & = k \\ ji & = -k \\ jk & = i \\ kj & = -i \\ ki & = j \\ ik & = -j \\ \textnormal{deriving the value of} jk \textnormal{:} \\ ik & = i(ij) = -j \\ & = w_1 w_2 + w_1 x_2 i + w_1 y_2 j + w_1 z_2 k \\ & + x_1 w_2 i + x_1 x_2 (-1) + x_1 y_2 k + x_1 z_2 (-j) \\ & + y_1 w_2 j + y_1 x_2 (-k) + y_1 y_2 (-1) + y_1 z_2 i \\ & + z_1 w_2 k + z_1 x_2 j + z_1 y_2 (-i) + z_1 z_2 (-1) \\ & = w_1 w_2 + w_1 x_2 i + w_1 y_2 j + w_1 z_2 k \\ & + x_1 w_2 i + x_1 x_2 (-1) + x_1 y_2 k + x_1 z_2 (-j) \\ & + y_1 w_2 j + y_1 x_2 (-k) + y_1 y_2 (-1) + y_1 z_2 i \\ & + z_1 w_2 k + z_1 x_2 j + z_1 y_2 (-i) + z_1 z_2 (-1) \\ & = \begin{bmatrix} (w_1 w_2) - ((x_1 x_2) + (y_1 y_2) + (z_1 z_2)) & \begin{bmatrix} (w_1 x_2) + (x_1 w_2) + (y_1 z_2) - (z_1 y_2) \\ (w_1 y_2) + (y_1 w_2) + (z_1 x_2) - (x_1 z_2) \\ (w_1 z_2) + (x_1 y_2) + (z_1 w_2) - (y_1 x_2) \end{bmatrix} \end{bmatrix} \\ & \begin{bmatrix} w_1 w_2 - v_1 \cdot v_2 & \begin{bmatrix} w_1 x_2 + x_1 w_2 + y_1 z_2 - z_1 y_2 \\ w_1 y_2 + y_1 w_2 + z_1 x_2 - x_1 z_2 \\ w_1 z_2 + x_1 y_2 + z_1 w_2 - y_1 x_2 \end{bmatrix} \end{bmatrix} \\ & \begin{bmatrix} w_1 w_2 - v_1 \cdot v_2 & w_1 v_2 + w_2 v_1 + v_1 \times v_2 \end{bmatrix} \end{aligned}

Created: 2026-10-26 Mon 20:15

Validate