Andrew Harvey's Blog - Entries tagged mathematicsEntries tagged mathematics
//tianjara.net/blog/
en-auThe content on this blog by Andrew Harvey, unless otherwise noted is licensed under a Creative Commons Attribution 3.0 Australia License.Chronicle/blog/img/blog-icon.pngAndrew Harvey's Blog
//tianjara.net/blog/
Polyhypercubes and That Whole Area of Combinatorics...
/blog/archive/2012/02/polyhypercubes_and_that_whole_area_of_combinatorics___.html
/blog/archive/2012/02/polyhypercubes_and_that_whole_area_of_combinatorics___.htmlSat, 4 Feb 2012 11:09:21 +1100<p><em>I've pulled this post from my draft archives from July 2010. I think it is about time I post it.</em></p>
<p>I stumbled upon Tetris the other day and began to wonder about the pieces, which lead me to stumble into a whole area of maths that I didn't know had been documented: polyforms.</p>
<p>In 2D you have n squares which can be formed into Polyominos, for an arrangement of squares to form a polyomino each square must share at least one of it's edges with another square. If you use 2 squares you get Dominos, 3 squares gives you Trominos, 4 gives Tetrominos, 5 gives Pentominos, and so on to n-minos. These all fall under the category of polyminos.</p>
<p>In 3D you have cubes with the principle that each cube must share a face with at least one other cube. These shapes are called <a title="Polycube" href="http://en.wikipedia.org/wiki/Polycube">polycube</a>s. If you use 3 cubes you get tricubes, and so on.</p>
<p>You can extrapolate this concept to nD hypercubes with the principle that each n-cube must share at least one of its <a href="http://en.wikipedia.org/wiki/Hypercube#Elements">(n-1)-faces</a> with another n-cube. Lets call these polyhypercubes.</p>
<p>We shall also say that polyhypercubes are the same if we can rotate (or mirror as well, depending on your definition of equality) them to match exactly. Note that if you are looking at the set of all poly-n-cubes for some n, the total size will vary depending whether you decide to allow mirroring (...although mirroring is the same as allowing rotation in a dimension 1 higher than the dimension of the space).</p>
<p><a href="/blog/attachments/2010/02/two-mirror-image-pentacubes.png"><img class="size-full wp-image-1050" title="two-mirror-image-pentacubes" src="/blog/attachments/2010/02/two-mirror-image-pentacubes.png" alt="Two pentacubes which are the same if you count mirroring as an allowed operation when testing for equality, but not the same if you don't (you can't rotate one to fall on the other)." width="349" height="147" /></a></p>
<blockquote>
<p>Two pentacubes which are the same if you count mirroring as an allowed operation when testing for equality, but not the same if you don't (you can't rotate one to fall on the other)."</p>
</blockquote>
<p>To generate these shapes you can start with one cube, from this you can make a graph where you add one block to every possible place. You can turn this into a directed graph, where an edge indicates you can get one shape by adding another cube to the previous shape. Perhaps this can be extended to a hypergraph, where two shapes are linked if you can morph from one to another by moving just one block (square, cube...)?</p>
<p>[caption id="attachment_1381" align="aligncenter" width="1024" caption="Evolution of the 5-polycubes where an edge represents adding one cube to a polycube."]<a href="/blog/attachments/2012/02/polycubes-gen.png"><img class="size-large wp-image-1381" title="polycubes-gen" src="/blog/attachments/2012/02/polycubes-gen.png?w=1024" alt="Evolution of the 5-polycubes where an edge represents adding one cube to a polycube." width="1024" height="199" /></a>[/caption]</p>
<p>You can also do a similar graph (well actually it would be a multigraph as you would have islands) by only allowing an edge where you can make a "rubix cube" like change to the object.</p>
<p>[caption id="attachment_1382" align="aligncenter" width="1024" caption="All 5-polycubes where an edge indicates a "rubix cube" like transformation."]<a href="/blog/attachments/2012/02/5-polycubes-rubix.png"><img class="size-large wp-image-1382" title="5-polycubes-rubix" src="/blog/attachments/2012/02/5-polycubes-rubix.png?w=1024" alt="All 5-polycubes where an edge indicates a "rubix cube" like transformation." width="1024" height="172" /></a>[/caption]</p>
<p>I was originally interested in two problems here. Generating all possible n-polycubes for a given n, and finding the total number of n-polycubes for a given n. The diagrams are examples of what I mean, but it was only done manually and only up to 5-polycubes. Code used to generate those diagrams is at <a href="https://github.com/andrewharvey/phc/tree/master/concrete-cases/5-polycubes">https://github.com/andrewharvey/phc/tree/master/concrete-cases/5-polycubes</a>.</p>
A method for two parties to verify if they share a common secret without revealing that secret if they don't.
/blog/archive/2010/07/a_method_for_two_parties_to_verify_if_they_share_a_common_secret_without_revealing_that_secret_if_they_don_t_.html
/blog/archive/2010/07/a_method_for_two_parties_to_verify_if_they_share_a_common_secret_without_revealing_that_secret_if_they_don_t_.htmlFri, 23 Jul 2010 20:04:07 +1000<p>We didn't cover zero knowledge proofs in the Security Engineering course I did last semester. But part way into the course I needed a way for two people, A and B to verify that some number they each know is infact the same number N in the case that they don't have a trusted arbitrator and they don't want to reveal the number they each know to the other person unless the other person has the same number.</p>
<p>I don't think this is exactly a zero knowledge proof situation by it seems closely related. The motivating situation for this was a web application that set some cookies and I wanted to know if one of these cookies set was unique per user or unique per some other setting (but the web application doesn't allow just anyone to create a new account, so I couldn't determine this on my own). In the case that it was unique per user then I don't want to tell anyone what my value for this cookie is because then they may be able to hijack my session.</p>
<p>So a method I thought of was that each person reveals one bit of the number to the other person at a time.</p>
<p>I'll try to formalise this a bit more.</p>
<p>I'll call this number the message. $latex A_M$ is the message $latex A$ knows, $latex B_M$ is the message $latex B$ knows. $latex A$ and $latex B$ arrange that they each know some message and arrange that they wish to verify if $latex A_M = B_M$. If $latex A_M = B_M$ then $latex A$ and $latex B$ must each know that that is the case and if $latex A_M \ne B_M$ then $latex A$ and $latex B$ must also know (after conducting the verification) that this is the case, but do not wish to let the other one know what their message was.</p>
<p>$latex A$ and $latex B$ meet letting $latex A$ be the entity that begins the verification. Each message is first encoded into a binary representation using an agreed upon method. $latex A$ then tells $latex B$ what the 1st bit of $latex A_M$ is (denoted $latex A_M \left [1\right ]$). $latex B$ now verifies this bit with $latex B_M$. If $latex A_M \left [1\right ] = B_M \left [1\right ]$, $latex B$ tells $latex A$ the second bit of $latex B_M$. If $latex A_M \left [1\right ] \ne B_M \left [1\right ]$, $latex B$ randomly selects a bit (ie. randomly selects either 0 or 1) and tells $latex A$ that random bit instead, and flags that $latex A_M \ne B_M$. As soon as either $latex A$ or $latex B$ flags that $latex A_M \ne B_M$ they subsequently always report a random bit regardless of whether the last bit reported to them was correct or not.</p>
<p>We could use an end of message token to indicate the end of the message. Of course this method isn't perfect because if one's random stream of bits matches what the other expects then one thinks that $latex A_M = B_M$ but the other thinks that $latex A_M \ne B_M$.</p>
<p>Another problem is if both parties have determined that $latex A_M \ne B_M$ then when do they stop sending random bits to each other? If both parties are happy to reveal the length of their message then there is no problem. Otherwise both parties can keep sending random bits until they feel that the the message space they have opened up is large enough and they don't mind revealing that the length of their message is less than the bit number they are up too.</p>
<p>Here's an example. A's number is 0110. B's number is 0110 and they want to check if they share the same number.</p>
<pre>A -> B: 0 (B expects this)
B -> A: 1 (A expects this)
A -> B: 1 (B expects this)
B -> A: 0 (A expects this)
A -> B: $ (B expects this) (not needed if they first agree on revealing the message length)
</pre>
<p>Another case A knows 0110, B knows 0010.</p>
<pre>A -> B: 0 (B expects this)
B -> A: 0 (A does not expect this, so A concludes A_M != B_M, and subsequently sends randomness)
A -> B: Rand(0,1) (two cases)
A sent 0 (B does not expect this, so B also concludes A_M != B_M, and subsequently sends randomness)
... continues until the end of M or until one party stops sending randomness.
A sent 1 (B expects this, but A hasn't revealed anything as they made a random selection)
B -> A: 0 (A doesn't know if B is sending randomness or not)
if they agreed upon a message length,
(A knows that A_M != B_M, but B thinks that A_M == B_M)
(but A has only revealed 1 bit of A_M to B (because B doesn't know if A was sending A_M or randomness after the 1st bit),
and B hasn't revealed anything of B_M to A (because A doesn't know if B was sending randomness))#
(the probability of this happening is z)
or, no message length agreed upon,
A keeps sending randomness and B will detect this (because B is expecting the end of stream token and didn't get it), so they both know that A_M != B_M.
</pre>
<p>This is not very formal and I'm confident I've missed some details or left some a bit fuzzy, I only really wanted to explain the general concept.</p>
<h1>To be honest I'm not so sure if this is correct. Rather than me going around in circles unable to solve the math, and just abandoning this post, I'll just leave it be and post with this uncertainty.</h1>
A Maths Problem: Transformed Horizontal Lines
/blog/archive/2010/01/a_maths_problem__transformed_horizontal_lines.html
/blog/archive/2010/01/a_maths_problem__transformed_horizontal_lines.htmlThu, 7 Jan 2010 18:09:40 +1100<p>This is the kind of post that I originally envisioned that I would post about when I started this blog. But after trying to complete this post I realised why I don't do this very much, because I can't always solve the problems I come up with. Anyway...</p>
<p>You can generate a funky kind of grid by taking a Cartesian coordinate system, joining lines from $latex (0, t)$ to $latex (t, 0)$ for some values <em>t</em>. Here are some examples,</p>
<p><a href="/blog/attachments/2010/01/montage_2.png"><img class="aligncenter size-full wp-image-981" title="Transformed Grid Montage" src="/blog/attachments/2010/01/montage_2.png" alt="Transformed Grid Montage" width="412" height="1236" /></a></p>
<p>If you draw lots of lines you get something like,</p>
<p>[caption id="attachment_982" align="aligncenter" width="500" caption="Generated using code at http://github.com/andrewharvey/cairomisc/blob/bd41c8feb1beba38849878aed566c6f45a70856b/curved_grid_simple.pl"]<a href="/blog/attachments/2010/01/inc050.png"><img class="size-full wp-image-982" title="Transformed Grid 50 lines" src="/blog/attachments/2010/01/inc050.png" alt="Transformed Grid (50 lines)" width="500" height="500" /></a>[/caption]</p>
<p style="text-align:left;">This is also what you get if you take a bunch of horizontal lines from $latex x = 0$ to $latex x = 1$ (where the horizontal lines are equally spaced above each other), and take all the endpoints from the line $latex x = 1$ and rotate them $latex 90^\circ$ about the point $latex 1, 0$.</p>
<p style="text-align:left;">The thing I was interested in was as you draw more and more of these lines it looks like a curve emerges on the boundary. I imagined that if you drew infinitely many lines like these you would get a nice smooth curve. I want to know what is the formula for that curve. But as I started to try to work it out, it didn't seem so simple.</p>
<p style="text-align:left;">I tried a lot of approaches, none of which seemed to work. So after a few initial set backs I tried to take a parametric approach taking <em>t</em> to be a value between 0 and 1 where this <em>t</em> indicates the line with start point $latex (0, t)$. The point on the curve for this <em>t</em> is some point on that line. I tried to get that point via the intersection with the next line, ie. the point on this line that is also on the curve is between the intersection of that line and the line for $latex t + \phi$ and $latex t - \phi$ for some really small $latex \phi$. But when I tried this approach as you make $latex \phi$ zero, then we get infinitely many points of intersection.</p>
<p style="text-align:left;">That didn't work so easy but then I realised that if the point is on this line then (although I have not proved this but it seems obvious from the picture) that I have the gradient.</p>
<p style="text-align:left;">So all those lines as shown above have equation $latex y = \frac{-t}{\left ( 1 - t \right )}x + t$. (Except for t = 1 where we'll just use a y value of 1). We can use this same <em>t</em> to define a point on the curve (which I call $latex f$ from here on) parametrically. So I assumed that the gradient of $latex f$ is given as $latex f'(t) = \frac{-t}{1-t}$. But now I'm not so sure that I have enough rigour here.</p>
<p style="text-align:left;">But then I got stuck again. I can try to go some integrals but this won't work because you don't know the relation between increasing <em>t</em> and the length along the curved you have moved. As you could have two different parametric functions which both have the same derivative function (ignoring the +c constant that disappears when you differentiate), just knowing the function defining the derivative of $latex f$ parametrically won't tell me the equation of the original curve.</p>
<p style="text-align:left;">Moving on I now tried to calculate the area under the curve. I could partition it like how a Riemann integral is done.</p>
<p style="text-align:center;"><a href="/blog/attachments/2010/01/discret_areas_axis_withdots.png"><img class="aligncenter size-full wp-image-988" title="discret_areas_axis_withdots" src="/blog/attachments/2010/01/discret_areas_axis_withdots.png" alt="discret_areas_axis_withdots" width="585" height="560" /></a></p>
<p style="text-align:left;">We can easily calculate the area of any of these trapezoids (bounded by red). $latex A = \frac{x_n - x_{(n-1)}}{2}(y_{x_n} + y_{x_{(n-1)}})$. We can get the <em>x</em> values by finding the point of intersection of the 2 lines that intersect at that <em>x</em> (and have the largest <em>y</em> value if there are several points of intersection for that <em>x</em>). Each line for some value <em>t</em> will have a point of intersection of the line before and after it (based on the <em>t</em> value). When I say the area of <em>t</em> = some number, I mean the area of the trapezoid starting with the intersection of the previous <em>t</em> line and ending with the intersection of the next <em>t</em> line. So the area of t = 1 is zero (because <em>x</em><sub>0</sub> and <em>x</em><sub>1</sub> are the same). The diagram above has $latex \phi = 0.125$. So,</p>
<p style="text-align:left;">Point A is the intersection of $latex y = \frac{-t}{\left ( 1-t \right )}x + t$ and $latex y = \frac{- \left ( t + \phi \right )}{1-\left ( t + \phi\right )}x + t + \phi$, which is,</p>
<p style="text-align:left;">$latex x_A = (1-t)(1-t-\phi)$
$latex y_A = t(t+\phi)$</p>
<p style="text-align:left;">Point B is the intersection of $latex y = \frac{-t}{\left ( 1-t \right )}x + t$ and $latex y = \frac{- \left ( t - \phi \right )}{1-\left ( t - \phi\right )}x + t - \phi$, which is,</p>
<p style="text-align:left;">$latex x_B = (1-t)(1-t+\phi)$
$latex y_B = t(t-\phi)$</p>
<p style="text-align:left;">So the area of this trapezoid is $latex \frac{x_B - x_A}{2}(y_A + y_B)$, which is $latex 2t^2\phi(1-t)$</p>
<p style="text-align:left;">But then I got stuck here. I can compute a value for the approximate area.</p>
<pre style="text-align:left;padding-left:30px;">phi = 0.0001;
area = 0;
for (t = 1; t > 0; t -= phi) {
area += 2*t*t*phi*(1-t);
}
print area;
</pre>
<p>Which gives a value very close to 1/6, and if I integrate that area equation for <em>t</em> = 0..1 you get $latex \frac{1}{6}\phi$. But I don't want the area, I want the formula that defines the area from <em>x</em> = 0 to some value <em>x</em> so that I can then differentiate this to get the equation of the original curve. So this is where I give up, and leave this for another day. If you work it out please post in the comments!</p>
<p>Oh and there is <a href="http://github.com/andrewharvey/cairomisc/tree/master/curved_grid_1/">some rough code I wrote to make those images here</a>. And a nice <a href="http://github.com/andrewharvey/cairomisc/raw/master/curved_grid_1/2to300lines.mp4">animation too</a>.</p>
A Response to Terence Tao's "An airport-inspired puzzle"
/blog/archive/2008/12/a_response_to_terence_tao_s__an_airport_inspired_puzzle_.html
/blog/archive/2008/12/a_response_to_terence_tao_s__an_airport_inspired_puzzle_.htmlFri, 12 Dec 2008 23:59:35 +1100<p>In Terence Tao's latest post he poses three questions. Here are my solutions.</p>
<blockquote>Suppose you are trying to get from one end A of a terminal to the other end B. (For simplicity, assume the terminal is a one-dimensional line segment.) Some portions of the terminal have moving walkways (in both directions); other portions do not. Your walking speed is a constant v, but while on a walkway, it is boosted by the speed u of the walkway for a net speed of v+u. (Obviously, one would only take those walkway that are going in the direction one wishes to travel in.) Your objective is to get from A to B in the shortest time possible.
<ol>
<li>Suppose you need to pause for some period of time, say to tie your shoe. Is it more efficient to do so while on a walkway, or off the walkway? Assume the period of time required is the same in both cases.</li>
<li>Suppose you have a limited amount of energy available to run and increase your speed to a higher quantity v' (or v'+u, if you are on a walkway). Is it more efficient to run while on a walkway, or off the walkway? Assume that the energy expenditure is the same in both cases.</li>
<li>Do the answers to the above questions change if one takes into account the effects of special relativity? (This is of course an academic question rather than a practical one.)</li>
</ol>
Source: Terence Tao, <a href="http://terrytao.wordpress.com/2008/12/09/an-airport-inspired-puzzle/">http://terrytao.wordpress.com/2008/12/09/an-airport-inspired-puzzle/</a></blockquote>
<h2>Q1.</h2>
<p>After just thinking about it without any mathematics I was not to sure so I used a mathematical approach. The first thing I did was to draw a diagram,</p>
<p><img class="aligncenter size-full wp-image-153" title="diagram1" src="/blog/attachments/2008/12/diagram1.png" alt="diagram1" width="373" height="90" />Admittedly, I did simplify the problem in my diagram, however I am confident that this will not affect the final answer. (How do I prove this? I don't know.) Along with this diagram I also had to define some things in terms of variables.</p>
<p>As shown in the diagram, A is the starting point, B is the ending point, C is an arbitrary point in between which separates the escalator section from the non-escalator sections.</p>
<p>Let,
<em>t</em> = time it takes to tie shoe lace
<em>v</em> = walking speed
<em>u</em> = escalator speed
$latex T_{ac}$ = time it takes to get from A to C
$latex T_{cb}$ = time it takes to get from C to B
$latex T_{ab}$ = time it takes to get from A to B</p>
<p>We also know, $latex speed = \frac {distance}{time}$.</p>
<p>Now lets consider two scenarios. Scenario A, the person ties their shoe lace in the non-escalator section. Scenario B, the person ties their shoe lace in the escalator section.</p>
<h3>Scenario A:</h3>
<p>$latex T_{ac}=T_{ab}+T_{bc}=\left (t+\frac{d_1}{v}\right )+\left (\frac{d_2}{v+u}\right )$</p>
<h3>Scenario B:</h3>
<p>$latex T_{ac}=T_{ab} + T_{bc}=\left ( \frac{d_1}{v}\right )+T_{bc}$
Now let $latex d_3 = \mbox{distance traveled in} d_2 \mbox{while the person is tieing their shoe lace.}\\ \ =vt$
$latex \therefore \mbox{walking on escalator time for time } t_2 = \frac {d_2 - vt}{v+u}$</p>
<p>I shall now make some reasonable assumptions (also formalising things a bit more),</p>
<p>All variables are real, and we shall assume that the person has time to tie their shoe lace while on the escalator. I.e. $latex t \le \frac{d_2}{u}$</p>
<p>I shall denote $latex T_A$ to be $latex T_{ac}$ from scenario A and $latex T_B$ to be $latex T_{ac}$ from scenario B. Now to see which is larger $latex T_A$ or $latex T_B$ we can examine the sign of $latex T_A - T_B$. If it is positive then $latex T_A > T_B$, if it is negative then $latex T_A < T_B$.</p>
<p>By some algebra $latex T_A - T_B = \frac{vt}{v+u}$ and as $latex v, u, t > 0$, $latex T_A - T_B > 0$. Hence $latex T_B < T_A$. Therefore it would be more efficient pause for a moment while on an escalator walkway.\</p>
<h2>Q2.</h2>
<p>I will take a similar approach for Q2, examining the two cases and then comparing the resultant time.</p>
<p>(I'll re-edit the post when I get around to working out the solution)</p>
The Mathematics Behind Graphical Drawing Projections in Technical Drawing
/blog/archive/2008/11/the_mathematics_behind_graphical_drawing_projections_in_technical_drawing.html
/blog/archive/2008/11/the_mathematics_behind_graphical_drawing_projections_in_technical_drawing.htmlSat, 15 Nov 2008 10:48:55 +1100<p><em>In the field of technical drawing, projection methods such as isometric, orthogonal, perspective are used to project three dimensional objects onto a two dimensional plane so that three dimensional objects can be viewed on paper or a computer screen. In this article I examine the different methods of projection and their mathematical roots (in an applied sense).</em></p>
<p>The approach that seems to be used by Technical Drawing syllabuses in NSW to draw simple 3D objects in 2D is almost entirely graphical. I don't think you can say this is a bad thing because you don't always want or need to know the mathematics behind the process, you just want to be able to draw without thinking about this. However to have an appreciation of what's really happening the mathematical understanding is a great thing to learn.</p>
<p>Many 3D CAD/CAM packages available on the market today (such as AutoCAD, Inventor, Solidworks, CATIA, Rhinoceros) can generate isometric, three point perspective or orthogonal drawings from 3D geometry, however from what I've seen they can't seem do other projections such as dimetric, trimetric, oblique, planometric, one and two point perspective. Admittedly I don't think these projections are any use or even needed, but when your at high school and you have to show that you know how do to oblique, et al. it can be a problem when the software cannot do it for you from your 3D model. (So I actually wrote a small piece of software to help with this in <a href="http://andrewharvey4.wordpress.com/2008/11/29/a-custom-drawing-projections-tool/">this article</a>). But to do so, I needed to understand the mathematics behind these graphical projections. So I will try to explain that here.</p>
<p>The key idea is to think of everything having coordinates in a coordinate system (I will use the Cartesian system for simplicity). We can then express all these projections as mathematical transformations or maps. Like a function, you feed in the 3D point, and then you get out the projected 2D point. Things get a bit arbitrary here because an isometric view is essentially exactly the same as a front view. So we keep to the convention that when we assign the axis of the coordinate system we try to keep the three planes of the axis parallel to the three main planes of the object.</p>
<p>[caption id="attachment_107" align="aligncenter" width="450" caption="The three "main" planes of the object are placed parallel to the three planes of the axis. This is how we will choose our axis in relation to the object."]<a href="/blog/attachments/2008/11/model-axis-1.png"><img class="size-full wp-image-107" title="model-axis-1" src="/blog/attachments/2008/11/model-axis-1.png" alt="The three "main" planes of the object are placed parallel to the three planes of the axis. This is how we will choose our axis in relation to the object." width="450" height="416" /></a>[/caption]</p>
<p>We will not do this though,</p>
<p>[caption id="attachment_108" align="aligncenter" width="450" caption="We will not choose it like this..."]<a href="/blog/attachments/2008/11/model-axis-2.png"><img class="size-full wp-image-108" title="model-axis-2" src="/blog/attachments/2008/11/model-axis-2.png" alt="We will not choose it like this..." width="450" height="416" /></a>[/caption]</p>
<p>[caption id="attachment_109" align="aligncenter" width="450" caption="...or this."]<a href="/blog/attachments/2008/11/model-axis-3.png"><img class="size-full wp-image-109" title="model-axis-3" src="/blog/attachments/2008/11/model-axis-3.png" alt="...or this." width="450" height="416" /></a>[/caption]</p>
<p>In fact doing something like that shown just above with the object rotated is how we get projections like isometric.</p>
<p>Now what we do is take the coordinates of each point and "transform" them to get the projected coordinates, and join these points with lines where they originally were. However we can only do this for some kinds of projections, indeed for all the ones I have mentioned in this post this will do but only because these projections have a special property. They are linear maps (affine maps also hold this property and are a superset of the set of linear maps) which means that straight lines in 3D project to straight lines in 2D.</p>
<p>For curves we can just project a lot of points on the curve (subdivide it) and then join them up after they are projected. It all depends what our purpose is and if we are applying it practically. We can generate equations of the projected curves if we know the equation of the original curve but it won't always be as simple. For example circles in 3D under isometric projection become ellipses on the projection plane.</p>
<p>Going back to the process of the projection, we can use matrices to represent these projections where</p>
<p style="text-align:center;">$latex \begin{pmatrix}x'\\ y'\\ z'\end{pmatrix} = \begin{pmatrix}a&b&c\\ d&e&f\\ g&h&i\end{pmatrix}\begin{pmatrix}x\\ y\\ z\end{pmatrix}$</p>
<p>is the same as,</p>
<p style="text-align:center;">$latex x' = ax+by+cz\\ y' = dx+ey+fz\\ z' = gx+hy+iz.$</p>
<p>We call the 3 by 3 matrix above as the matrix of the projection.</p>
<p>Knowing all this, we can easily define orthogonal projection as you just take two of the dimensions and cull the third. So for say an orthographic top view the projection matrix is simply,</p>
<p style="text-align:center;">$latex \begin{pmatrix}1&0&0\\ 0&1&0\\ 0&0&0\end{pmatrix}.$</p>
<p>Now we want a projection matrix for isometric. One way would be to do the appropriate rotations on the object then do an orthographic projection, we can get the projection matrix by multiplying the matrices for the rotations and orthographic projection together. However I will not detail that here. Instead I will show you another method that I used to describe most of the projections that I learnt from high school (almost all except perspectives).</p>
<p>I can describe them as well as many "custom" projections in terms of what the three projected axis look like on the projection plane. I described them all in terms of a scale on each of the three axis, as well as the angle two of the axis make with the projection plane's horizontal.</p>
<p>[caption id="attachment_112" align="aligncenter" width="151" caption="Projection attributes described in terms of the projected axis."]<a href="/blog/attachments/2008/11/pp-description.png"><img class="size-full wp-image-112" title="pp-description" src="/blog/attachments/2008/11/pp-description.png" alt="Projection attributes described in terms of the projected axis." width="151" height="154" /></a>[/caption]</p>
<p style="text-align:left;">Using this approach we can think of the problem back in a graphical perspective of what the final projected drawing will look like rather than looking at the mathematics of how the object gets rotated prior to taking an orthographic projection or what angle do the projection lines need to be at in relation to the projection plane to get oblique, etc. Note also that the <em>x</em>, <em>y</em>, <em>z</em> in the above diagram are the scales of the <em>x</em>, <em>y</em>, <em>z</em> axis respectively. So we can see in the table below that we can now describe these projections in terms of a graphical approach that I was first taught.</p>
<table style="height:183px;border-style:solid;border-width:1px;" border="0" width="289">
<tbody>
<tr>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;"><strong>Projection</strong></td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;"><strong>α (alpha)</strong></td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;"><strong>β (beta)</strong></td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;"><em><strong>S</strong></em><sub><strong>x</strong></sub></td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;"><em><strong>S</strong></em><sub><strong>y</strong></sub></td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;"><em><strong>S</strong></em><sub><strong>z</strong></sub></td>
</tr>
<tr>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">Isometric</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">30°</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">30°</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
</tr>
<tr>
<td style="width:101px;text-align:center;border-style:solid;border-width:1px;">Cabinet Oblique</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">45°</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">0°</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">0.5</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
</tr>
<tr>
<td style="width:101px;text-align:center;border-style:solid;border-width:1px;">Cavalier Oblique</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">45°</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">0°</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
</tr>
<tr>
<td style="width:101px;text-align:center;border-style:solid;border-width:1px;">Planometric</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">45°</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">45°</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
</tr>
</tbody>
</table>
<p style="text-align:left;">Now all we need is a projection matrix that takes in alpha, beta and the three axes scale's and does the correct transformation to give the projection. The matrix is,</p>
<p style="text-align:center;">$latex \begin{bmatrix}x'\\y'\\z'\\1\end{bmatrix}=\begin{bmatrix}S_x\cos\alpha&-S_y\cos\beta&0&0\\ S_x\sin\alpha&S_y\sin\beta&S_z&0\\ 0&0&0&0\\ 0&0&0&1\end{bmatrix}\begin{bmatrix}x\\y\\z\\1\end{bmatrix}$</p>
<p style="text-align:left;">Now for the derivation. First we pick a 3D Cartesian coordinate system to work with. I choose the Z-up Left Hand Coordinate System, shown below and we imagine a rectangular prism in the 3D coordinate system.</p>
<p style="text-align:left;"></p>
<p>[caption id="attachment_114" align="aligncenter" width="450" caption="Block in 3D coordinate system."]<a href="/blog/attachments/2008/11/block-3d.png"><img class="size-full wp-image-114" title="block-3d" src="/blog/attachments/2008/11/block-3d.png" alt="Block in 3D coordinate system." width="450" height="253" /></a>[/caption]</p>
<p style="text-align:left;">Now we imagine what it would look like in a 2D coordinate system using isometric projection.</p>
<p style="text-align:left;"></p>
<p>[caption id="attachment_115" align="aligncenter" width="450" caption="Block in 2D coordinate system (isometric)."]<a href="/blog/attachments/2008/11/block-2d.png"><img class="size-full wp-image-115" title="block-2d" src="/blog/attachments/2008/11/block-2d.png" alt="Block in 2D coordinate system (isometric)." width="450" height="245" /></a>[/caption]</p>
<p style="text-align:left;">As the alpha and beta angles (shown below) can change, and therefore not limited to a specific projection, we need to use alpha and beta in the derivation.</p>
<p style="text-align:center;"><a href="/blog/attachments/2008/11/pp-description.png"><img class="size-full wp-image-112 aligncenter" title="pp-description" src="/blog/attachments/2008/11/pp-description.png" alt="pp-description" width="151" height="154" /></a></p>
<p style="text-align:left;">Now using these simple trig equations below we can deduce the following.</p>
<p style="text-align:center;"><a href="/blog/attachments/2008/11/polar.png"><img class="alignnone size-full wp-image-116" title="polar" src="/blog/attachments/2008/11/polar.png" alt="polar" width="203" height="100" /></a></p>
<p style="text-align:left;">All the points on the <em>xz</em> plane have <em>y</em> = 0. Therefore the <em>x</em>’ and <em>y</em>’ values on the 2D plane will follow the trig property shown above, so:</p>
<p style="text-align:center;">$latex x'=x\cos\alpha$
$latex y' = z + y\sin\alpha$</p>
<p style="text-align:left;">However not all the points lie on the <em>xz</em> plane, <em>y</em> is not always equal to zero. By visualising a point with a fixed <em>x </em>and <em>z </em>value but growing larger in <em>y </em>value, its <em>x</em>’ will become lower, and <em>y</em>’ will become larger. The extent of the <em>x</em>’ and <em>y</em>’ growth can again be expressed with the trig property shown, and this value can be added in the respective sense to obtain the final combined <em>x</em>’ and <em>y</em>’ (separately).</p>
<p style="text-align:center;">$latex x'=x\cos\alpha -y\cos\beta$
$latex y' = z + x \sin \alpha + y \sin \beta$</p>
<p style="text-align:left;">If <em>y</em> is in the negative direction then the sign will automatically change accordingly. The next step is to incorporate the scaling of the axes. This was done by replacing the <em>x</em>, <em>y</em> & <em>z</em> with a the scale factor as a multiple of the <em>x</em>, <em>y</em> & <em>z</em>. Hence,</p>
<p style="text-align:center;">$latex x'=S_x x\cos\alpha -S_y y\cos\beta$
$latex y' = S_z z + S_x x\sin\alpha + S_y y \sin \beta$</p>
<p style="text-align:left;">This can now easily be transferred into matrix form as shown at the start of this derivation or left as is.</p>
<p style="text-align:left;"><strong>References:
</strong>Harvey, A. (2007). <em>Industrial Technology - Graphics Industries 2007
HSC Major Project Management Folio</em>. (<a
href="//tianjara.net/hsc/itg-major-work/ITG_MajorProject_2007_ManagementFolio_Jul09.pdf">Link</a>)</p>
An Introduction to Hypercubes.
/blog/archive/2008/10/an_introduction_to_hypercubes_.html
/blog/archive/2008/10/an_introduction_to_hypercubes_.htmlTue, 21 Oct 2008 08:06:21 +1100<p>Point, Line Segment, Square, Cube. But what comes next, what is the equivalent object in higher dimensions? Well it is called a <em>hypercube </em>or <em>n-cube</em>, although the 4-cube has the special name <em>tesseract</em>.</p>
<h2>Construction Methods</h2>
<p>Before I go on to explain about the elements of hypercubes, let me show you some pictures of some hypercubes. I guess this also raises the question how can you construct these objects. One method is to start with a point. Then stretch it out in one dimension to get a line segment. Then take this line and stretch it out in another dimension perpendicular to the previous one, to get a square. Then take that square and stretch it out in another dimension perpendicular to the previous two to get a cube. This is when your visualisation may hit a wall. Its very hard to then visualise taking this cube and stretching it in another dimension perpendicular to the previous three. However mathematically, this is easy and this is one approach to constructing hypercubes.</p>
<p style="text-align:left;"></p>
<p>[caption id="attachment_55" align="aligncenter" width="297" caption="We place a point in R3."]<a href="/blog/attachments/2008/10/crop1-custom1.png"><img class="size-medium wp-image-56" title="Point" src="/blog/attachments/2008/10/crop1-custom1.png" alt="We place a point in R3." width="297" height="300" /></a>[/caption]</p>
<p>[caption id="attachment_56" align="aligncenter" width="297" caption="...and then stretch the point in one dimension to make a line..."]<a href="/blog/attachments/2008/10/crop2-custom.png"><img class="size-medium wp-image-56" title="Line" src="/blog/attachments/2008/10/crop2-custom.png?w=297" alt="...and then stretch the point in one dimension to make a line..." width="297" height="300" /></a>[/caption]</p>
<p>[caption id="attachment_58" align="aligncenter" width="297" caption="...and then we stretch that line in a direction perpendicular to the previous time..."]<a href="/blog/attachments/2008/10/crop3-custom.png"><img class="size-medium wp-image-58" title="Plane" src="/blog/attachments/2008/10/crop3-custom.png?w=297" alt="...and then we stretch that line in a direction perpendicular to the previous time..." width="297" height="300" /></a>[/caption]</p>
<p>[caption id="attachment_59" align="aligncenter" width="297" caption="...and finally stretch that plane in a direction perpendicular the the previous two times."]<a href="/blog/attachments/2008/10/crop4-custom.png"><img class="size-medium wp-image-59" title="Cube" src="/blog/attachments/2008/10/crop4-custom.png?w=297" alt="...and finally stretch that plane in a direction perpendicular the the previous two times." width="297" height="300" /></a>[/caption]</p>
<p>However there is more mathematical and analytical method. You most probably know that these n-cubes have certain elements to them, namely vertices (points), edges (lines), faces (planes), and then in the next dimension up, cells and then in general n-faces. These elements are summed up nicely <a href="http://en.wikipedia.org/wiki/Hypercube#Elements">here</a>. Firstly we take a field of say $latex \mathbb{R}^n$. Next we construct the vertices of the n-cube. Basically we are taking all the <em>n</em> dimensional vectors which have all the combinations of 0's and 1's for each entry of the vector. More mathematically,
There is a vertex described by each vector $latex \begin{pmatrix}a_1\ a_2\ \vdots\ a_n\end{pmatrix}$ where $latex a_i \in {0, 1}.$
There is an edge between vertices $latex \begin{pmatrix}a_1\ a_2\ \vdots\ a_n\end{pmatrix}$ and $latex \begin{pmatrix}b_1\ b_2\ \vdots\ b_n\end{pmatrix}$ if and only if $latex a_j \ne b_j$ for exactly one $latex j \in {1, \dots, n}$.
$latex \qquad \qquad \vdots&s=4$
There is an m-face between (or though) vertices $latex \begin{pmatrix}a_1\ a_2\ \vdots\ a_n\end{pmatrix}$ and $latex \begin{pmatrix}b_1\ b_2\ \vdots\ b_n\end{pmatrix}$ and ... and $latex \begin{pmatrix}m_1\ m_2\ \vdots\ m_n\end{pmatrix}$ if and only if $latex a_j \ne b_j \ne \dots \ne m_j$ for exactly $latex (m - 1), \;\; j \in {1, \dots, n}$.</p>
<p>Basically this means we list the vertices just as if were were counting in base 2. And then we can group these vertices into different groups based on the n-face level and (if we think of the vertices of a bit string) how many bits we have to change to make two vertices bit streams the same. This approach is very interesting because the concept of grouping these vertices relates strongly to hypergraphs.</p>
<p>Another way to think about it is as follows. Edges, from the set of all edges (i.e. joining each vertex with every other vertex), are the ones that are perpendicular to one of the standard basis vectors. This generalises to n-faces; from the set of all n-faces (i.e. all ways of grouping vertices into groups of <em>n</em>) are those that the object constructed is parallel to the span of any set of <em>n</em> of the standard basis vectors.</p>
<p>When you think about it, a lot of things that you can say about the square or cube generalise. For instance you can think of a square being surrounded by 4 lines, and cube by 6 surfaces, a tesseract by 8 cells, etc.</p>
<h2>Visualisation Methods</h2>
<p>Now that we have some idea how to describe and build n-cubes, the next question is how do we draw them. There are numerous methods and I can't explain them all in this post (such as slicing and stereographic projection, as well as other forms of projection (I'll leave these for another blog article)). But another question is also what aspects do we draw and how do we highlight them. For instance it may seem trivial in two dimensions to ask do I place a dot at each vertex and use just 4 solid lines for the edges. But in higher dimensions we have to think about how do we show the different cells and n-faces.</p>
<p>Firstly, how can we draw or project these <em>n</em> dimensional objects in a lower dimensional world (ultimately we want to see them in 2D or 3D as this is the only space we can draw in). This first method is basically the exact same approach that most people would have first learnt back in primary school. Although, I do not think it makes the most sense or makes visualisation easiest. Basically this method is just the take a dot and perform a series of stretches on it that I described earlier, although most people wouldn't think this is what they were doing. Nor would we usually start with a dot, we would normally start with the square. Although we will, so we start with this.</p>
<p>[caption id="attachment_79" align="aligncenter" width="15" caption="0-cube."]<a href="http://andrewharvey4.files.wordpress.com/2008/10/lines_0-cube.png"><img class="size-full wp-image-79" title="lines_0-cube" src="http://andrewharvey4.files.wordpress.com/2008/11/lines_0-cube.png" alt="0-cube, showing verticies." width="15" height="20" /></a>[/caption]</p>
<p>We would now draw a line along some axis from that dot, and place another dot at the end of this line.</p>
<p>[caption id="attachment_74" align="aligncenter" width="112" caption="1-cube, showing vertices and edges."]<a href="http://andrewharvey4.files.wordpress.com/2008/10/lines_1-cube.png"><img class="size-full wp-image-74" title="lines_1-cube" src="/blog/attachments/2008/11/lines_1-cube.png" alt="1-cube, showing verticies and edges." width="112" height="20" /></a>[/caption]</p>
<p>Now from each of the dots we have, we would draw another line along some other axis and again draw a dot at the end of each of those two lines. We would then connect the newly formed dots.</p>
<p>[caption id="attachment_75" align="aligncenter" width="120" caption="2-cube, showing vertices and edges."]<a href="http://andrewharvey4.files.wordpress.com/2008/10/lines_2-cube.png"><img class="size-full wp-image-75" title="lines_2-cube" src="/blog/attachments/2008/11/lines_2-cube.png" alt="2-cube, showing verticies and edges." width="120" height="120" /></a>[/caption]</p>
<p>Now, we just keep repeating this process where by each time we are drawing another dimension. So we take each of these four dots and draw lines from them in the direction of another axis, placing a dot at the end of each of these lines, and joining each of the dots that came from other dots that were adjacent, with a line.</p>
<p>[caption id="attachment_91" align="aligncenter" width="180" caption="3-cube, showing vertices and edges."]<a href="/blog/attachments/2008/11/lines_3-cube.png"><img class="size-full wp-image-91" title="lines_3-cube" src="/blog/attachments/2008/11/lines_3-cube.png" alt="" width="180" height="180" /></a>[/caption]</p>
<p>Now for 4D and beyond we basically keep the process going, just choosing really anywhere from the new axis, so long as it passes though the origin.</p>
<p>[caption id="attachment_78" align="aligncenter" width="240" caption="4-cube, showing vertices and edges."]<a href="/blog/attachments/2008/11/lines_4-cube.png"><img class="size-full wp-image-78" title="lines_4-cube" src="/blog/attachments/2008/11/lines_4-cube.png" alt="4-cube, showing verticies and edges." width="240" height="240" /></a>[/caption]</p>
<p>If we do a little bit of work we can see that this map is given by the matrix,</p>
<p style="text-align:center;">$latex \begin{pmatrix}1&0&r_1\cos \theta&-r_2\cos\phi\\ 0&1&r_1\sin\theta&r_2\sin\phi \\ 0&0&0&0 \\ 0&0&0&0 \end{pmatrix}$</p>
<p>where $latex \theta$ is the angle of the projected <em>z</em> axis from the <em>x</em> axis, and $latex \phi$ is the angle of the projected <em>w</em> axis from the negative <em>x</em> axis. Also <em>r</em><sub>1</sub> and <em>r</em><sub>2</sub> are the scales of the third and fourth respective receding axis (it makes it "look" more realistic when we use a number less than 1) This is just an extension of oblique projection for 3D to 2D.</p>
<p>Now this method seems very primitive, and a much better approach is to use all the dimensions we have. We live in a three dimensional world, so why just constrict our drawings to two dimensions! Basically, an alternate approach to draw an n-cube in three dimensional space would be to draw <em>n</em> lines all passing though a single point. Although it is not necessary to make all these lines as spread out as possible, we will try to. (This actually presents another interesting idea of how do we equally distribute <em>n</em> points on a sphere. For instance we can try to make it so that all the angles between any two of the points and the origin are equal. But I will leave this for another blog article later.) We then treat each of these lines as one dimension from there we can easily draw, or at least represent an n-dimensional point in 3D space. Now obviously we can have two different points in 4D that map to the same 3D point, but that is always going to happen no matter what map we use. The following set of 4 vectors are the projected axis we will use as a basis.</p>
<p style="text-align:center;">$latex \left \{ \mathbf{e_1}, \mathbf{e_2}, \mathbf{e_3}, \mathbf{e_4} \right \} = \left \{ \begin{pmatrix}1\\1\\1 \end{pmatrix}, \begin{pmatrix}-1\\-1\\1 \end{pmatrix}, \begin{pmatrix}-1\\1\\-1 \end{pmatrix}, \begin{pmatrix}1\\-1\\-1 \end{pmatrix} \right \}$</p>
<p>Now I won't say how I got these (actually I took them from Wikipedia, they are just the vertices of a 3-simplex) but all of the vectors share a common angle between any two and the origin.</p>
<p style="text-align:left;">Now if we draw in our tesseract, highlighting the cells with different colours (not this became problematic with some faces and edges as they are a common boundary for two different faces, so you cannot really make them one colour or the other) we get something like this,</p>
<p>[caption id="attachment_93" align="aligncenter" width="450" caption="Tesseract projected onto R3. The cells are shown in different colours, the purple lines show the four axis."]<a href="/blog/attachments/2008/11/tesseractwithcells1.png"><img class="size-full wp-image-93" title="tesseractwithcells1" src="/blog/attachments/2008/11/tesseractwithcells1.png" alt="Tesseract projected onto R3. The cells are shown in different colours, the purple lines show the four axis." width="450" height="390" /></a>[/caption]</p>
<p>The projection matrix for this projection is then simply (from the vectors that each of the standard basis maps to),</p>
<p style="text-align:center;">$latex \begin{pmatrix}1&-1&-1&1\\ 1&-1&1&-1\\ 1&1&-1&-1 \end{pmatrix}$</p>
<p>Now if we compare this to our original drawing (note I'm not talking about the projection used, but rather the presentation of the drawings, i.e. the colour.) I think you will see that the second one is clearer and try's to show where the cells and faces are, not just the vertices and edges. Note also the second one is in 3D so you can rotate around it. Looking at the first one though, you will notice it doesn't show where the faces or cells are. Remember that we have more than just vertices, edges and faces. We have cells, and n-faces. These are essentially just different groupings of the vertices. But how can we show these. Now the most mathematical way would be to just list all the different groupings. This is okay, but I like to see things in a visual sense. So another way would just show different elements. Like you draw all the vertices on one overhead, edges on another, and so on. Then when you put all these overheads on top of each other we get the full image, but we can also look at just one at a time to see things more clearly. This would be particularly more useful for the higher dimensional objects and higher dimensional elements. We can also use different colours to show the different elements. For example in the square, we can see that the line around surrounding it is 4 lines, but in higher dimensions its not so easy, so we can colour the different parts to the element differently. (When I say part I mean the 4 edges of a square are 4 different parts. Whereas the edges are all one element, but are a different element to the vertices.)</p>
<h2>Some Interesting Properties</h2>
<p>Once you start defining hypercubes there are many interesting properties that we can investigate. For this section lets just assume that we have the standard hypercube of side length 1. Now we can trivially see that the area, volume, etc. for the respective hypercube will always be 1. As described above each time we add another dimension and sweep the object out into that dimension we effectively multiply this hypervolume by 1. So for an n-cube, the hypervolume of it will be $latex 1^n$. When I say hypervolume I mean the one that makes sense for that dimension. E.g. in 2D, area, in 3D, volume, and so on.</p>
<p>The next obvious question to ask is what is the perimeter, surface area, cell volume, ..., n-face hypervolume of the respective n-cube? It gets a little confusing as you have to think about what exactly you are finding. Is it a length, an area, a volume? Well it will just be an (<em>n</em> - 1) volume. Eg. in 2D we are finding a length (the perimeter), in 3D, an area (surface area), and so on so that each time we increase the dimension of the n-cube we increase the units we are measuring in. Well if we just start listing the sequence (starting with a square), 4, 6... we notice this is just the number of (<em>n</em> - 1) degree elements. Namely, the number of edge, faces, cells, etc.</p>
<p>This leads me in the obvious question of how can I calculate the number of m-elements of the n-cube?</p>
<p>Well instead of me just going to the formula, which you can find on Wikipedia anyway, I will go though my lines of thinking when I first tried to work this out. Number of vertices is easy, each component of the n-vector can be either a 0 or a 1. So for each component there is 2 possibilities, but we have n of them, so it is just 2x2x2... <em>n</em> times, or 2<sup><em>n</em></sup>. Now originally when I tried to work out the number of edges, I started listing them and saw that I could construct the recurrence... Although with the help of graph theory it is very simple. In graph theory the handshaking theorem says $latex \displaystyle 2\left |E \right| = \sum_{v \in V} \mbox{deg}(v).$ Where $latex \left | E \right |$ means the number of edges, and $latex \mbox{deg}(V)$ means the degree of vertex <em>V</em>, which means the number of edges connected two it. Now if we think of an edge being a group of two vertices where you only make one entry of the vector change to get from one vector to the other, then we can see that there are exactly <em>n</em> way of doing this. We can either change the 1st entry of the vector, or the 2nd, or the ...., or the <em>n</em>th. Thus each vertex has of the n-cube graph will have degree <em>n</em>. So as we have 2<sup><em>n</em></sup> vertices and each vertex has degree <em>n</em>, then the sum of the vertex degrees will be <em>n</em>2<sup><em>n</em></sup>. Hence by the handshaking theorem, $latex |E| = \frac{1}{2} n 2^n = n 2^{n-1}.$ I am not exactly sure how to generalise this further. I will leave it for another article. However, the formula is $latex 2^{n-m} \binom{n}{m}.$</p>
<p><em>(I shall try to write more at a later date.)</em></p>
<p><strong>References:</strong></p>
<ul>
<li>Hypercube. (2008, October 14). In <em>Wikipedia, The Free Encyclopedia</em>. Retrieved 08:19, October 21, 2008, from <a class="external free" title="http://en.wikipedia.org/w/index.php?title=Hypercube&oldid=245242295" rel="nofollow" href="http://en.wikipedia.org/w/index.php?title=Hypercube&oldid=245242295">http://en.wikipedia.org/w/index.php?title=Hypercube&oldid=245242295</a></li>
<li>Tran, T., & Britz, T. (2008). MATH1081 Discreet Matematics: 5 Graph Theory.</li>
</ul>
Units, Vectors and Bases. Metrics?
/blog/archive/2008/10/units__vectors_and_bases__metrics_.html
/blog/archive/2008/10/units__vectors_and_bases__metrics_.htmlThu, 2 Oct 2008 09:40:22 +1000<p>I began wondering about this mainly when the idea of a basis is used in linear algebra, although it seems to be strongly related to scalars, just as basis is to vector as one is to scalar.</p>
<p>This area of investigation for me arose when then they took coordinate vectors out of the UNSW MATH1231 (2007) syllabus. So I had to do a bit of reading on my own. To understand coordinate vectors its helpful to look at the vector space of polynomials. For example take the polynomial 3 - 2<span style="font-style:italic;">x</span> + <span style="font-style:italic;">x</span><sup>2</sup>. Now if we put the coefficients into a vector, (3, -2, 1) then this vector is called the coordinate vector of 3 - 2<span style="font-style:italic;">x</span> + <span style="font-style:italic;">x</span><sup>2</sup> with respect to the ordered basis {1, <span style="font-style:italic;">x</span>, <span style="font-style:italic;">x</span><sup>2</sup>}<sup>[1]</sup>. This sounds clear, but let me propose the following.</p>
<p>Say we have the coordinate vector (1,2,3) with respect the the ordered basis S = {(1,0,0), (0,1,0), (0,0,1)}, denoted [(1,2,3)]<sub>S</sub>. How is this different to just (1,2,3)? Aren't all vectors, by convention defined with respect to the standard basis of that vector space? But that cannot possibly make sense because bases are defined in terms of vectors, so that would be a recursive definition which is not logically valid. There must be a more reasonably explanation.</p>
<p>Now looking at this in the vector space of say $latex \mathbb{R}^2$ we can take one basis of B = {(1,0), (0,1)} which is the standard basis, and another C = {(1,1), (-1,1)}.</p>
<p><a href="/blog/attachments/2008/10/coordvectors-wp.png"><img class="aligncenter size-full wp-image-34" title="coordvectors" src="/blog/attachments/2008/10/coordvectors-wp.png" alt="" width="240" height="147" /></a></p>
<p>Now if we define the point (1,2) with respect the the basis C, then with respect to the basis B this is the point, 1(1, 1) + 2(-1, 1) = (-1, 3). So essentially this allows us to still work with respect to the standard basis B, but we can work in the frame of C which allows us to then say treat the point (1,1) as just (1,0) which can simplify things.</p>
<p>Again looking at this graphically say in $latex \mathbb{R}^2$ then we can just draw essentially any two non-parallel lines which we call our axis or basis. Any mathematics that is done in any of these coordinate systems with respect to that coordinate system (i.e. the two lines drawn) would be the same. (1,1) + (2,0) would give (3,1) in both systems. Its only when we start defining one vector in one system with respect to the basis of the other system that we need to worry about the difference between the bases.</p>
<p>In the same sense I would say, mathematically it is meaningless to draw some Euclidean geometry on paper without drawing in your standard basis. Without them everything is meaningless as you define vectors as coordinate vectors with respect to some basis. Just as the polynomial 3 - 2<span style="font-style:italic;">x</span> + <span style="font-style:italic;">x</span><sup>2</sup> is really just the vector (3, -2, 1) with a standard basis of {1, <span style="font-style:italic;">x</span>, <span style="font-style:italic;">x</span><sup>2</sup>}. I guess you would call them metrics of the vector space of $latex \mathbb{R}^2$, just like 1 is the metric of all subsets of the real numbers (is it?).</p>
<p>As a final note I think this is just the same as 2 is really means 2 × 1, and 3 means three lots of 1's. Any links to abstract algebra? Probably, I'm not sure.</p>
<p><span style="font-weight:bold;font-size:85%;">References:</span>
<sup>[1]</sup> MATH1231 Algebra [Online]. Angell D. 2005. Accessed July 2008. Ch 6, Pg 70. <a href="http://web.maths.unsw.edu.au/%7Eangell/1231alg/">http://web.maths.unsw.edu.au/~angell/1231alg/</a></p>
(x,y,z,w) in OpenGL/Direct3D (Homogeneous Coordinates)
/blog/archive/2008/09/_x_y_z_w__in_opengl_direct3d__homogeneous_coordinates_.html
/blog/archive/2008/09/_x_y_z_w__in_opengl_direct3d__homogeneous_coordinates_.htmlMon, 29 Sep 2008 09:33:12 +1000<p>I always wondered why 3D points in OpenGL, Direct3D and in general computer graphics were always represented as (<span style="font-style:italic;">x</span>,<span style="font-style:italic;">y</span>,<span style="font-style:italic;">z</span>,<span style="font-style:italic;">w</span>) (i.e. why do we use four dimensions to represent a 3D point, what's the <span style="font-style:italic;">w</span> for?). This representation of coordinates with the extra dimension is know as homogeneous coordinates. Now after finally getting formally taught linear algebra I know the answer, and its rather simple, but I'll start from the basics.</p>
<p>Points can be represented as vectors, eg. (1,1,1). Now a common thing we want to do in computer graphics is to move this point (translation). So we can do this by simply adding two vectors together,</p>
<p style="text-align:center;">$latex \begin{pmatrix}x'\\y'\\z'\end{pmatrix} = \begin{pmatrix}x\\y\\z\end{pmatrix} + \begin{pmatrix}a\\b\\c\end{pmatrix} = \begin{pmatrix}x + a\\y + b\\z + c\end{pmatrix}.$</p>
<p style="text-align:left;">If we wanted do some kind of linear transformation such as rotate about the origin, scale about the origin, etc, then we could just multiply a certain matrix with the point vector to obtain the image of the vector under that transformation. For example,</p>
<p style="text-align:center;">$latex \begin{pmatrix}x'\\ y'\\ z' \end{pmatrix} = \begin{pmatrix}\cos \theta &-\sin \theta &0\\ \sin \theta &\cos \theta &0\\ 0&0&1\end{pmatrix} \begin{pmatrix}x\\ y\\ z\end{pmatrix}$</p>
<p style="text-align:left;"></p>
<p style="text-align:left;">will rotate the vector (<span style="font-style:italic;">x</span>,<span style="font-style:italic;">y</span>,<span style="font-style:italic;">z</span>) by angle theta about the <span style="font-style:italic;">z</span> axis.</p>
<p>However as you may have seen you cannot do a 3D translation on a 3D point by just multiplying a 3 by 3 matrix by the vector. To fix this problem and allow all affine transformations (linear transformation followed by a translation) to be done by matrix multiplication we introduce an extra dimension to the point (denoted <span style="font-style:italic;">w</span> in this blog). Now we can perform the translation,</p>
<p style="text-align:center;">$latex \mathbb{R}^2 : (x,y) \to (x+a, y+b)$</p>
<p>by a matrix multiplication,</p>
<p style="text-align:center;">$latex \begin{pmatrix}1 & 0 & a\\ 0 & 1 & b\\ 0 & 0 & 1\end{pmatrix} \begin{pmatrix}x\\ y\\ 1\end{pmatrix} = \begin{pmatrix}x + a\\ y + b\\ 1 \end{pmatrix}.$</p>
<p>We need this extra dimension for the multiplication to make sense, and it allows us to represent all affine transformations as matrix multiplication.</p>
<p><span style="font-size:85%;">REFERENCES:
Homogeneous coordinates. (2008, September 29). In <em>Wikipedia, The Free Encyclopedia</em>. Retrieved 04:33, September 29, 2008, from <a class="external free" title="http://en.wikipedia.org/w/index.php?title=Homogeneous_coordinates&oldid=241693659" rel="nofollow" href="http://en.wikipedia.org/w/index.php?title=Homogeneous_coordinates&oldid=241693659">http://en.wikipedia.org/w/index.php?title=Homogeneous_coordinates&oldid=241693659</a></span></p>
Proof
/blog/archive/2008/08/proof.html
/blog/archive/2008/08/proof.htmlSat, 30 Aug 2008 15:52:00 +1000<p><span style="font-size:100%;">Many of the courses I have studied so far (such as HSC Mathematics and 1st year MATH1131 and MATH1231 [UNSW]) require some form of mathematical proofs to be used. However in these courses they don't really teach us about proof's, rather they tend to say here is the generic proof to use, memorise it and write it out in the exam. They don't always do this, but most of the time they have asked us to do a proof in an exam there is a similar example provided in the notes somewhere.</span></p>
<p>I have always found doing proof questions very hard and I think the main reason is that they never actually taught us them! Lucky for me I'm doing MATH1081 which has a section all about proof and I must say, I've learnt a lot of very important and interesting things from this course.</p>
<p>A lot of the time when I saw proofs I would think to myself, that is not a proof! Mainly either because it was so obvious that you can just see its true, or because the proof says its true because of such and such reason, with no explanation as to why such and such reason was also true.</p>
<p>However now that I've been taught proofs, things are starting to make sense. Proofs are actually quite simply, they are there just to convince the reader that some result is true based on some agreed upon facts. Proofs just build on things to provide new results based on those results already known. It is quite acceptable to not prove certain things in a proof because they themselves have proofs and if you were to include these proofs every time you find a new result you would have to publish a whole new book with a couple extra pages stuck on the back.</p>
<p>This whole idea of having proof's based on axioms/postulates is very interesting. In Euclid's <em>Elements</em>, Euclid first writes down a series of definitions so that he has something to base his postulates and theorems on. Without first accepting these basic facts nothing can be proved. Some people say that these axioms are obviously true, I tend to disagree. Rather than viewing them are true or false I think it would be more appropriate to not label them as either. They are merely axioms on which you base deductions. I also think you should not just consider things that are based on these axioms. It would of course be very interesting to investigate the mathematics if you have some very weird axioms that most would say are obviously false. Again I would say its not a matter of this fact being true and this being false, rather here is a statement and here is what you can deduce from that statement.</p>
<p>Back to the idea of what is considered a proof, I think my lecturer has explained it well. A proof is merely a argument, something which aims to convince the reader that the statement which you are proving is in fact true based on those agreed upon facts. You simply show how to obtain the result from simpler things which one also accepts to be true.</p>
<p>Another concept which came up was the use of diagrams in proofs. When we studied sets and we had a question which said prove A is a subset of B, I always thought that the easiest way to show this was to draw a Venn diagram and show that A is always inside B. Then again you could always argue that you are just drawing a diagram of the result you are trying to prove!</p>
<p>From an education perspective, I think the very lack of teaching mathematical proof all the way up until math1081 and yet expecting us to understand proofs is completely stupid. If we ever want to have a deeper understanding of the things we learn and know why they work, then we should be taught the fundamentals first!</p>
<p>Now, I'm sure I've said some things which are probably not entirely correct. I accept that, I'm not an expert in maths, so don't expect me to.</p>
<p><strong>Update (18th Oct 2008):</strong>
I just read this in a maths text book,</p>
<blockquote>If $latex x+3=5,$
then $latex (x+3) + (-3) = 5 + (-3);$
hence $latex x + (3 + (-3)) = 5 - 3 = 2;$
hence $latex x + 0 = 2$;
hence $latex x = 2.$</blockquote>
<p>They go on to say,</p>
<blockquote>"Naturally, such elaborate solutions are of interest only until you become convinced that they can always be supplied. In practice, it is usually just a waste of time to solve and equation by indicating so explicitly the reliance on (the laws of elementary algebra)."[1]</blockquote>
<p>I think this is the best example of what my troubles were in understanding the whole concept of proof. I guess the largest challenge that I face now is in examinations how do I know what level of maths I can assume the examiner agrees upon, and how much I actually have to prove.</p>
<p><strong>References:</strong>
[1] Spivak, M. (1973). Calculus. Addison-Wesley. pp 4-5.</p>