<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" 
               "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" [
  <!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
]>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<link rel="stylesheet" type="text/css" href="../../../comsci/css/s011.css"/>
<link rel='SHORTCUT ICON' href='../../../comsci/images/FrameHome.ico' />
<style type="text/css">
</style>
<title> Grids </title>
</head>

<body>


<div class="message_right">
  <a href="http://validator.w3.org/check/referer">
    <img src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid
	XHTML 1.1!" height="31" width="88" />
  </a>

  <a href="http://jigsaw.w3.org/css-validator/">
    <img style="width:88px;height:31px"
       src="http://jigsaw.w3.org/css-validator/images/vcss" 
       alt="Valid CSS!" />
  </a>
  <br/>
  Created 2004-07-06 &nbsp; Modified 
<!--UPDATE_DATE_MODIFIED-->
<!--UPDATE_DATE_BEGIN-->
2007-01-01
<br/>
<a href="mailto:chelton.evans@yahoo.com">Chelton Evans</a>
<!--UPDATE_DATE_END-->
</div>






<h1> 
<a href="geom.html"> <img alt="proj" src="../../../comsci/images/compgeom.png" /></a>
Grids
<a href="../../../../index.html">
<img alt="home" src="../../../comsci/images/Frame.gif" /> </a>
</h1>


<p>
<a href="#Rectangular_Grid"> Rectangular Grid </a> <br/>
<a href="#Square_Spiral_Grid"> Square Spiral Grid </a> <br/>
<a href="#Hex_Grid"> Hex Grid </a> <br/>
<a href="#Linked_List_Grids"> Linked List Grids </a> <br/>
</p>



<div class="float25">
<a id="Rectangular_Grid"> </a>
<h2> Rectangular Grid </h2>

<p>
A rectangular grid is a matrix in 2 dimensions. Consider mappings 
 or functions between a vector and a matrix. The vanilla matrix 
 can be extended in one direction with positive indexes, two directions
 with negative indexes.
</p>

<p class="equ">
<math xmlns="&mathml;">
<mfenced open='[' close=']'>
  <mtable>
    <mtr>
       <mtd><mi>20</mi></mtd>
       <mtd><mi>...</mi></mtd>
       <mtd><mi></mi></mtd>
       <mtd><mi></mi></mtd>
    </mtr>
    <mtr>
       <mtd><mi>16</mi></mtd>
       <mtd><mi>17</mi></mtd>
       <mtd><mi>18</mi></mtd>
       <mtd><mi>19</mi></mtd>
    </mtr>
    <mtr>
       <mtd><mi>12</mi></mtd>
       <mtd><mi>13</mi></mtd>
       <mtd><mi>14</mi></mtd>
       <mtd><mi>15</mi></mtd>
    </mtr>
    <mtr>
       <mtd><mi>8</mi></mtd>
       <mtd><mi>9</mi></mtd>
       <mtd><mi>10</mi></mtd>
       <mtd><mi>11</mi></mtd>
    </mtr>
    <mtr>
       <mtd><mi>4</mi></mtd>
       <mtd><mi>5</mi></mtd>
       <mtd><mi>6</mi></mtd>

       <mtd><mi>7</mi></mtd>
    </mtr>
    <mtr>
       <mtd><mi>0</mi></mtd>
       <mtd><mi>1</mi></mtd>
       <mtd><mi>2</mi></mtd>

       <mtd><mi>3</mi></mtd>
    </mtr>
  </mtable>
</mfenced>
</math>

</p>

<p> I found a method for generating the formula for iterating over 
 vanilla grids, see <a href="../number/n027.xml"> 
  Matrix Orientation Iteration </a>.
</p>

</div>

<div class="spacer" />


<div class="float25">

<a id="Square_Spiral_Grid"> </a>
<h2> Square Spiral Grid </h2>


<img src="diagg01401.png" alt="diagg01401.png" />

<h3> &lt;TODO&gt;</h3>

<ul>
<li> Given n find (i,j). And inverse.
</li>
<li> Given n and direction k={0,1,2,3}, find n' after moving 1 square 
 in k direction. </li>
<li> Investigate whether this can be used for general rectangles. eg
 are there &gt; and &lt; operators which can bound the edges in this space?
</li>

</ul>


</div>

<div class="float25">

<p>
It is called the spiral function and defined differently such that 1 goes up instead
 of left. I did the problem this way before finding a reference in 
 "Concrete Mathematics" page 99, which is a better definition because 
 the numbers are rotated -90 degrees from mine. 
 The 4 regions which the numbers are partitioned
 into now are in line with the axes and correspond to the 4 quadrants. This
 simplifies the formula.
</p>

<p>
Problem : given (i,j) as normal grid points find (i,j+1) ie move up.
 Process: (i,j) corresponds to n, n -> n' where (i,j+1) corresponds to n'.
</p>

<p>
By looking at the grid the patterns can be found by considering
 horizontal and vertical number sequences. Divide the grid into
 4 regions about the origin. Consider the bottom triangle.
</p>



<p class="equ">

<math xmlns="&mathml;">
  <mi>2</mi>
  <mo>=</mo>
  <mi>1</mi>
  <mo>+</mo>
  <mi>1</mi>
  <mo>+</mo>
  <mi>0</mi>
</math> <br/>


<math xmlns="&mathml;">
  <mi>13</mi>
  <mo>=</mo>
  <mi>9</mi>
  <mo>+</mo>
  <mi>3</mi>
  <mo>+</mo>
  <mi>1</mi>
</math> <br/>

<math xmlns="&mathml;">
  <mi>32</mi>
  <mo>=</mo>
  <mi>25</mi>
  <mo>+</mo>
  <mi>5</mi>
  <mo>+</mo>
  <mi>2</mi>
</math> <br/>

<math xmlns="&mathml;">
  <mi>59</mi>
  <mo>=</mo>
  <mi>49</mi>
  <mo>+</mo>
  <mi>7</mi>
  <mo>+</mo>
  <mi>3</mi>
</math> <br/>

<math xmlns="&mathml;">
  <mi>n</mi>
  <mo>=</mo>
  <mi>j</mi>
  <msup>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msup>
  <mo>+</mo>
  <mi>j</mi>
  <mo>+</mo>
  <mi>k</mi>
</math> <br/>
 where
<math xmlns="&mathml;">
  <mo>&lt;</mo>
  <mi>n</mi>
  <mo>,</mo>
  <mi>k</mi>
  <mo>&gt;</mo>
</math> 
 &nbsp; forms its own natural coordinate system.
</p>

<p>
Formula for the other regions can be constructed and joined together
 for a solution.

</p>

</div>

<div class="spacer" />

<div class="float25">

<a id="Hex_Grid"> </a>
<h2> Hex Grid </h2>

<p>
Introducing the 
 hex grid coordinate system.

</p>

<p>
"C++ Math Class Library - Permutations, Partitions, Calculators &amp; Gaming" 
 by Scott N. Gerard provides a chapter on the hex grid.  The midpoint
 of a hexagon grid is essentially a rectangular array of points.

</p>


<img alt="Hex coordinates." src="diagg01402.png" />
</div>

<div class="float25">
<img alt="Triangle lattice is hex dual." src="diagg01403.png" />
<img alt="Mapping hex coords to 2D grid." src="diagg01404.png" />

</div>

<div class="float25">

<p> Taking the midpoint of a hexagon grid produces a grid of triangles
 which can be bent to a rectangular array.  For the reverse take the
 midpoints of 5 triangles about a vertex and join them to form a hexagon,
 repeating generates the hexagon grid. The representations are equivalent
 and I believe are called each others duals.
</p>

<p>
Scott Gerard explains the importance in games and explains the 
 natural 3D hex coordinate system. The coordinate system is non-unique
 because 

<math xmlns="&mathml;">
  <mi>i</mi>
  <mo>+</mo>
  <mi>j</mi>
  <mo>+</mo>
  <mi>k</mi>
  <mo>=</mo>
  <mi>0</mi> 
</math>
.
</p>

<p class="equ">
<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>u</mi>
  <mo>,</mo>
  <mi>v</mi>
  <mo>,</mo>
  <mi>w</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mo>(</mo>
  <mi>u</mi>
  <mo>+</mo>
  <mi>k</mi>
  <mo>,</mo>
  <mi>v</mi>
  <mo>+</mo>
  <mi>k</mi>
  <mo>,</mo>
  <mi>w</mi>
  <mo>+</mo>
  <mi>k</mi>
  <mo>)</mo>
</math>
</p>

<p>
To make the coordinate system unique again an algorithm is employed
 that simply subtracts the middle value of i,j,k.
</p>

<p>
I have also found a way of mapping this coordinate system to a rectangular
 array. 
</p>

<p class="equ">
<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>i</mi>
  <mo>,</mo>
  <mi>j</mi>
  <mo>,</mo>
  <mi>k</mi>
  <mo>)</mo>
  <mo>&map;</mo>
  <mo>(</mo>
  <mi>i</mi>
  <mo>-</mo>
  <mi>k</mi>
  <mo>+</mo>
  <mo>(</mo>
  <mi>j</mi>
  <mo>-</mo>
  <mi>k</mi>
  <mo>&lt;</mo>
  <mo>-</mo>
  <mi>1</mi>
  <mo>)</mo>
  <mo>-</mo>
  <mo>(</mo>
  <mi>j</mi>
  <mo>-</mo>
  <mi>k</mi>
  <mo>&gt;</mo>
  <mi>0</mi>
  <mo>)</mo>
  <mo>,</mo>
  <mi>j</mi>
  <mo>-</mo>
  <mi>k</mi>
  <mo>)</mo>
</math>
</p>

</div>


<div class="spacer" />

<div class="float25">
<a id="Linked_List_Grids"> </a>
<h2> Linked List Grids </h2>

<img src="diagg01405.png" alt="diagg01405.png" />

</div>

<div class="float25">

<p>
The cost of these date structures is obvious - many links per element.
 This can be offset by hierarchical structures where one of the elements
 can be a pointer to a regular grid with many points and much more memory
 efficient data structure.
</p>

<p>
Their generality is less well known. From one of these elements you can
 choose a direction or path independent of the underlying memory structure.
 This allows transversal algorithms to be written. So surfaces can be
 more easily transversed - an alternative to the maths group theory approach.
 Its often much harder to analyze a surface than it is to describe it. By
 describing it you can write something to transverse it....
</p>

<p> Writing algorithms using the natural data structure (eg triangle has 3 links
  for triangulated surface)
 is good. I hope to explore this much further.</p>


<h2> Higher Dimensions </h2>

<p>
You may have noticed that all these examples are in two dimensions.
  It turns out almost always solving in a lower dimension is required
 to solve higher dimensions, further its often easier to abstract or jump
 up to the higher dimension when the lower one is well understood. I see
 writing about these as an investment. 
</p>

</div>



</body>
</html>


