helgegudmundsen.comhttp://helgegudmundsen.com/Life and LearningenSat, 01 Oct 2016 10:53:33 GMThttps://getnikola.com/http://blogs.law.harvard.edu/tech/rssJust a buttonhttp://helgegudmundsen.com/posts/just-a-button/Helge Gudmundsen<div><p>I sincerely hope the orange menace will lose the upcoming election.</p>
<p><img alt="All Hail Drumpf" src="http://helgegudmundsen.com/images/DrumpfButton.png" title="Modern Fascism"></p></div>politicshttp://helgegudmundsen.com/posts/just-a-button/Sat, 01 Oct 2016 10:42:45 GMT3D Maths Primer - Multiple Coordinate Systemshttp://helgegudmundsen.com/posts/3d-maths-primer-multiple-coordinate-systems/Helge Gudmundsen<div><p>This article contains my reading notes from the third chapter of the book <a href="https://www.amazon.co.uk/Math-Primer-Graphics-Game-Development/dp/1568817231/ref=as_li_ss_tl?s=books&ie=UTF8&qid=1470312834&sr=1-1&keywords=3d+math+primer+for+graphics+and+game+development&linkCode=ll1&tag=helgegudmunds-21&linkId=89b01042e666e205b6d46b5fbf75225a" title="Amazon link for 3D Math Primer for Graphics and Game Development, 2nd edition">3D Math Primer for Graphics and Game Development, 2nd edition</a>. The subject of the chapter is Multiple Coordinate Systems.</p>
<h3>Multiple Coordinate Systems</h3>
<p>The reason multiple coordinate spaces are used is that certain pieces of information are known only in the context of a particular reference frame. It might be true that theoretically all points could be expressed using a single "
"world" coordinate system. However, for a certain point a, we may not know the coordinates of a in the "world" coordinate system. But we may be able to express a relative to some other coordinate system.</p>
<h3>Common Coordinate Systems</h3>
<h4>World Space</h4>
<p>The world coordinate system is a special coordinate system that establishes the “global” reference frame for all other coordinate systems to be specified.</p>
<h4>Object Space</h4>
<p>Object space is the coordinate space associated with a particular object. Every object has its own independent object space. When an object moves or changes orientation, the object coordinate space associated with that object is carried along with it, so it moves or changes orientation too.</p>
<h4>Camera Space</h4>
<p>One especially important example of an object space is camera space, which is the object space associated with the viewpoint used for rendering. Note carefully the differences between camera space, which is a 3D space, and screen space, which is a 2D space. The mapping of camera-space coordinates to screen-space coordinates involves an operation known as projection. </p>
<h4>Upright Space</h4>
<p>When communicating either to human beings via words or to computers via code, it is helpful to associate with each object a new coordinate space, which we call the upright coordinate space of the object. An object’s upright space is, in a certain sense, “halfway” between world space and its object space. The axes of upright space are parallel with the axes of world space, but the origin of upright space is coincident with the origin of object space.</p>
<p>Why is upright space interesting? To transform a point between object space and upright space requires only rotation, and to transform a point between upright space and world space requires only a change of location, which is usually called a translation. Thinking about these two things independently is easier than trying to cope with them both at once.</p>
<h3>Coordinate Space Transformations</h3>
<p>Do we have to rotate first, and then translate? The answer to this question is basically yes. Although it may seem more natural to translate before rotating, it’s usually easier to rotate first. Here’s why. When we rotate the object first, the center of rotation is the origin. Rotation about the origin and translation are two primitive tools we have at our disposal, and each is easy.</p>
<p>Specifying the position of the coordinate space is straightforward. All we have to do is describe the location of the origin. We do this just like we do for any other point. Of course, we must express this point relative to the parent coordinate space, not the local child space. The origin of the child space, by definition, is always (0, 0, 0) when expressed in child coordinate space.</p>
<p>Specifying the orientation of a coordinate space in 3D is only slightly more complicated. The axes are vectors (directions), and can be specified like any other direction vector. Just as with position, we do not use the object space itself to describe the object-space axis directions, since those coordinates are [1, 0] and [0, 1] by definition. Instead, the coordinates are specified in upright space.</p>
<h3>Nested coordinate spaces</h3></div>graphicsmathjaxmathsprogramminghttp://helgegudmundsen.com/posts/3d-maths-primer-multiple-coordinate-systems/Thu, 18 Aug 2016 15:00:30 GMT3D Math Primer - Vectorshttp://helgegudmundsen.com/posts/vectors/Helge Gudmundsen<div><p>This article contains my reading notes from the second chapter of the book <a href="https://www.amazon.co.uk/Math-Primer-Graphics-Game-Development/dp/1568817231/ref=as_li_ss_tl?s=books&ie=UTF8&qid=1470312834&sr=1-1&keywords=3d+math+primer+for+graphics+and+game+development&linkCode=ll1&tag=helgegudmunds-21&linkId=89b01042e666e205b6d46b5fbf75225a" title="Amazon link for 3D Math Primer for Graphics and Game Development, 2nd edition">3D Math Primer for Graphics and Game Development, 2nd edition</a>. The subject of the chapter is Vectors, and the chapter starts with the basic properties of vectors. Below I have noted some important (to me) definitions.</p>
<p>As the subject of the book is graphics, the coverage is focused on the geometric interpretations of vectors and vector operations. Geometrically speaking, a vector is a directed line segment that has <em>magnitude</em> and <em>direction</em>.</p>
<p>For any given vector dimension, there is a special vector, known as the zero vector, that has zeroes in every position. The zero vector has zero magnitude, and no direction. Think of the zero vector as a way to express the concept of "no displacement", much as the scalar zero stands for the concept of "no quantity". Below is the three-dimensional zero vector:</p>
<p>\[ \boldsymbol{0} =
\begin{bmatrix}
0 \\
0 \\
0 \\
\end{bmatrix} \]</p>
<p>It is important to understand that points and vectors are conceptually distinct, but mathematically equivalent. When you think of a location, think of a point and visualize a dot. When you think of a displacement, think of a vector and visualize an arrow. The math we develop in the following sections operates on "vectors" rather than "points". Keep in mind that any point can be represented as a vector from the origin.</p>
<p>Negating a vector results in a vector of the same magnitude but opposite direction. We negate a vector by negating each component of it, i.e.:</p>
<p>\[ - \begin{bmatrix}
2 \\
2 \\
\end{bmatrix} =
\begin{bmatrix}
-2 \\
-2 \\
\end{bmatrix} \]</p>
<p>A vector can be multiplied by a scalar, and this will change the magnitude of the vector, and possibly the direction as well.</p>
<!-- TEASER_END -->
<p>The linear algebra rules for vector addition are simple: to add two vectors, we add the corresponding components:</p>
<p>\[ \begin{bmatrix}
a_1 \\
a_2 \\
\vdots \\
a_n \\
\end{bmatrix}
+
\begin{bmatrix}
b_1 \\
b_2 \\
\vdots \\
b_n \\
\end{bmatrix}
=
\begin{bmatrix}
a_1 + b_1 \\
a_2 + b_2 \\
\vdots \\
a_n + b_n \\
\end{bmatrix} \]</p>
<p>Vector multiplication by a scalar is straightforward; we simply multiply each component of the vector by the scalar:</p>
<p>\[ k \begin{bmatrix}
a_1 \\
a_2 \\
\vdots \\
a_n \\
\end{bmatrix}
=
\begin{bmatrix}
a_1 \\
a_2 \\
\vdots \\
a_n \\
\end{bmatrix} k
=
\begin{bmatrix}
k a_1 \\
k a_2 \\
\vdots \\
k a_n \\
\end{bmatrix} \]</p>
<p>Vector addition is commutative,</p>
<p>\[ a+b = b+a \]</p>
<p>whereas vector subtraction is anticommutative,</p>
<p>\[ a−b = −(b−a) \]</p>
<p>The vector subtraction \( b − a \) yields a vector from a to b.</p>
<p>The equation for computing the magnitude of a vector of arbitrary dimension n is as follows:</p>
<p>\[ \lVert \boldsymbol{v} \rVert = \sqrt{\sum_{i=1}^{n} {v_{i}}^{2}} = \sqrt{{v_{1}}^{2} + {v_{2}}^{2} + \dots + {v_{n}}^{2}} \]</p>
<p>A unit vector is a vector that has a magnitude of one. When this book refers to a vector as a "normal" it means "a unit vector perpendicular to something else". This is common usage, but be warned that the word "normal" primarily means "perpendicular" and not "unit length".</p>
<p>For any nonzero vector \( \boldsymbol{v} \), we can compute a unit vector that points in the same direction as \( \boldsymbol{v} \). This process is known as normalizing the vector. The book uses the common notation of putting a hat symbol over unit vectors; for example, \( \hat{\boldsymbol{v}} \), (pronounced "v hat"). To normalize a vector, we divide the vector by its magnitude</p>
<p>\[ \hat{\boldsymbol{v}} = \frac{\boldsymbol{v}}{\lVert \boldsymbol{v} \rVert} \]</p>
<h3>The distance formula</h3>
<p>The distance between two points can be calculated by determining the length of the vector from one point to another. The distance between two points \( a \) and \( b \) can be determined by subtracting \( b \) from \( a \) (thus getting a vector \( \boldsymbol{d} \)) and calculating the magnitude of this vector. Note, in this formula we are treating points as if they were vectors starting from the origin of the coordinate system.</p>
<p>\[ distance(\boldsymbol{a}, \boldsymbol{b}) = \lVert \boldsymbol{b} - \boldsymbol{a} \rVert = \sqrt{(b_x - a_x)^2 + (b_y - a_y)^2 + (b_z - a_z)^2 } \]</p>
<h3>Dot product</h3>
<p>The dot product is the sum of the products of corresponding components, resulting in a scalar.</p>
<p>\[ \begin{bmatrix}
a_1 \\
a_2 \\
\vdots \\
a_n \\
\end{bmatrix}
\cdot
\begin{bmatrix}
b_1 \\
b_2 \\
\vdots \\
b_n \\
\end{bmatrix}
= a_1 b_1 + a_2 b_2 + \dots + a_n b_n \]</p>
<p>Formally, this can be described as follows:</p>
<p>\[ \boldsymbol{a} \cdot \boldsymbol{b} = \sum_{i=1}^{n} a_i b_i \]</p>
<p>For 2D and 3D vectors, this yields the following:</p>
<p>\[ \boldsymbol{a} \cdot \boldsymbol{b} = a_x b_x + a_y b_y \]
\[ \boldsymbol{a} \cdot \boldsymbol{b} = a_x b_x + a_y b_y + a_z b_z \]</p>
<p>The dot product \(\boldsymbol{a} \cdot \boldsymbol{b} \) is equal to the signed length of the projection of \( \boldsymbol{b} \) onto any line parallel to \(\boldsymbol{a}\), multiplied by the length of \(\boldsymbol{a}\).</p>
<p>The dot product can also be defined trigonometrically as follows:</p>
<p>\[ \boldsymbol{a} \cdot \boldsymbol{b} = \lVert \boldsymbol{a} \rVert \lVert \boldsymbol{b} \rVert \cos \theta \]</p>
<p>In the formula above, \( \theta \) is the angle between the two vectors when having the same origin.</p>
<p>Given two vectors, we can use the dot product to find the angles between them:</p>
<p>\[ \theta = \arccos \left( \frac{\boldsymbol{a} \cdot \boldsymbol{b}}{\lVert \boldsymbol{a} \rVert \lVert \boldsymbol{b} \rVert} \right) \]</p>
<p>If \( \boldsymbol{a} \) and \( \boldsymbol{b} \) are unit vectors, the equation simply becomes:</p>
<p>\[ \theta = \arccos \left( \hat{\boldsymbol{a}} \cdot \hat{\boldsymbol{b}} \right) \]</p>
<p>One very common use of the dot product is as a projection. Assume once more that \( \hat{\boldsymbol{a}} \) is a unit vector and \( \boldsymbol{b} \) has arbitrary length. Using the dot product, it’s possible to separate \( \boldsymbol{b} \) into two values, \( \boldsymbol{b_{\parallel}} \) and \( \boldsymbol{b_{\perp}} \) (read "b parallel" and "b perp"), which are parallel and perpendicular to \( \hat{\boldsymbol{a}} \), respectively, such that \( \boldsymbol{b} = \boldsymbol{b_{\parallel}} + \boldsymbol{b_{\perp}} \).</p>
<p>We’ve already established that the length of \( \boldsymbol{b_{\parallel}} \) will be equal to \( \hat{\boldsymbol{a}} \cdot \boldsymbol{b} \). But the dot product yields a scalar, and \( \boldsymbol{b_{\parallel}} \) is a vector, so we’ll take the direction specified by the unit vector \( \hat{\boldsymbol{a}} \) and scale it up:</p>
<p>\[ \boldsymbol{b_{\parallel}} = (\hat{\boldsymbol{a}} \cdot \boldsymbol{b}) \hat{\boldsymbol{a}}\]</p>
<p>Once we know \( \boldsymbol{b_{\parallel}} \), we can easily solve for \( \boldsymbol{b_{\perp}} \):</p>
<p>\[ \boldsymbol{b_{\perp}} = \boldsymbol{b} - \boldsymbol{b_{\parallel}} \]</p>
<h3>Cross product</h3>
<p>The other vector product, known as the cross product, can be applied only in 3D. Unlike the dot product, which yields a scalar and is commutative, the vector cross product yields a 3D vector and is not commutative. The equation for the cross product is:</p>
<p>\[ \begin{bmatrix}
x_1 \\
y_1 \\
z_1 \\
\end{bmatrix}
\times
\begin{bmatrix}
x_2 \\
y_2 \\
z_2 \\
\end{bmatrix}
=
\begin{bmatrix}
y_1 z_2 - z_1 y_2\\
z_1 x_2 - x_1 z_2\\
x_1 y_2 - y_1 x_2\\
\end{bmatrix}
\]</p>
<p>The cross product yields a vector that is perpendicular to the original two vectors. </p>
<p>The length of the vector \( \boldsymbol{a} \times \boldsymbol{b} \) is:</p>
<p>\[ \lVert \boldsymbol{a} \times \boldsymbol{b} \rVert = \lVert \boldsymbol{a} \rVert \lVert \boldsymbol{b} \rVert \sin \theta \]</p>
<p>One of the most important uses of the cross product is to create a vector that is perpendicular to a plane.</p></div>graphicsmathjaxmathsprogramminghttp://helgegudmundsen.com/posts/vectors/Wed, 17 Aug 2016 12:10:04 GMTBrowniehttp://helgegudmundsen.com/posts/brownie/Helge Gudmundsen<div><p>This is an photo I shot of our young dog. She is only four months old, and cute as a button.</p>
<p><img alt="Brownie" src="http://helgegudmundsen.com/images/brownie-2016-08-06.png"></p></div>browniehttp://helgegudmundsen.com/posts/brownie/Sat, 06 Aug 2016 09:35:47 GMT3D Math Primer - Cartesian Coordinate Systemshttp://helgegudmundsen.com/posts/3d-math-primer-cartesian-coordinate-systems/Helge Gudmundsen<div><p>At work I am currently doing simulation and rendering of 3D models, and need to brush up on related mathematics. I was recommended a book on the subject called <a href="https://www.amazon.co.uk/Math-Primer-Graphics-Game-Development/dp/1568817231/ref=as_li_ss_tl?s=books&ie=UTF8&qid=1470312834&sr=1-1&keywords=3d+math+primer+for+graphics+and+game+development&linkCode=ll1&tag=helgegudmunds-21&linkId=89b01042e666e205b6d46b5fbf75225a" title="Amazon link for 3D Math Primer for Graphics and Game Development, 2nd edition">3D Math Primer for Graphics and Game Development, 2nd edition</a>. Although the title contains the words game development, the main focus of the book is on 3D math and the geometry and algebra of 3D space. It is also written in an informal and relaxed style, making it a fun read as well as a useful one. </p>
<p>I will chronicle my learning journey here.</p>
<h3>1D Mathematics</h3>
<p>The book starts with the absolute basics covering 1D mathematics and number lines (with the numbers represented as dead sheep, and negative numbers as ghost sheep). At this point it was becoming obvious that this was no regular textbook, but although the language is tongue-in-cheek, the book is a thorough treatment of the subject matter. The chapter quickly convers natural numbers, real numbers and rational numbers.</p>
<h3>2D Cartesian Space</h3>
<p>The book moves on to 2D Cartesian Space, and quickly covers origins, axes and axes orientation. We quickly learn that axes orientation is an arbitrary concept, and that it 2D space we can alway rotate the coordinate space to whatever orientation we want.</p>
<h3>3D Cartesian Space</h3>
<p>Adding a third axis to a plane creating a 3D space increases the difficulty for humans to visualize and describe the space. In 3D space points are specified using the numbers \(x\), \(y\) and \(z\), which give the signed distance to the planes \(yz\), \(xz\) and \(xy\) planes respectively.</p>
<p>All 3D coordinate spaces are not equal. While 2D coordinate spaces can always be rotated to line up with each other, this is not the case with 3D coordinate spaces. There are two distinct types, left-handed coordinate spaces and right-handed coordinate spaces. If two coordinate spaces have the same handedness, they can always be rotated so that the axes are aligned, but if they are of opposite handedness, this is not possible.</p>
<p>The easiest way to visualize this is having the thumb, index and middle finger pointing in perpendicular directions, signalling the positive direction of the three axes. The left and the right hand can never have the same orientation for all the three axes at the same time.</p>
<p>The definition of positive rotation is also different for left- and right-handed coordinate systems. Holding the hand with the thumb up, and the direction of the thumb representing the positive side of the axis, positive rotation around the axis is the direction in which the other fingers are curled.</p>
<h3>Trigonometry</h3>
<p>The final part of the chapter gives a brief overview of trigonometric functions, their values and properties as they relate to 3D Math.</p></div>graphicsmathjaxmathsprogramminghttp://helgegudmundsen.com/posts/3d-math-primer-cartesian-coordinate-systems/Thu, 04 Aug 2016 12:10:41 GMTNotes on Learninghttp://helgegudmundsen.com/posts/notes-on-learning/Helge Gudmundsen<div><p>On this site I will document the things I do, and write about the things I want to learn, and the process of learning them. The idea is to provide a structure for myself while learning, but my hope is that this also can serve as help for other people trying to learn the same things.</p>
<p>The stuff I write about will for the most part be related to computers, maths and music, as these are the things I work with and care about. However when the mood strikes I will post on other subjects as well.</p></div>http://helgegudmundsen.com/posts/notes-on-learning/Wed, 03 Aug 2016 09:12:10 GMT