<?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> Triangulating a Monotone Polygon </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 2005-03-24 &nbsp; Modified 
<!--UPDATE_DATE_MODIFIED-->
<!--UPDATE_DATE_BEGIN-->
2007-01-19
<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>
Triangulating a Monotone Polygon
<a href="../../../../index.html">
<img alt="home" src="../../../comsci/images/Frame.gif" /> </a>
</h1>


<div class="float25">

<p>
<a href="#Intro"> Intro </a> <br/>
<a href="#Algorithms_Tessellation">  Algorithms Tessellation </a> <br/>
<a href="#Algorithm"> Algorithm </a> <br/>
<a href="#Algorithm_from_Computational_Geometry_in_C"> Algorithm from Computational Geometry in C </a> <br/>
<a href="g023.html"> Monotone Polygons </a> <br/>
<a href="../../../misc/proj/polytrimon/doc.xml"> C++ Implementation </a> <br/>
<a href="#References">References</a><br/>
<a href="#&lt;TODO&gt;">&lt;TODO&gt;</a>
</p>

</div>

<div>
<img alt="diagg02502.png" src="diagg02502.png" />
</div>

<div class="spacer" />

<div class="float25">
<a id="Intro"> </a>
<h2> Intro </h2>

<p>
I really had a tough time with this algorithm.
 Firstly whenever I see someone talking about acute angles in algorithms
 I feel like puking. "interior cusps", "reflex chain", ...
 If you ever pull out an old geometry book and spend many hours reasoning
 in that stuff you may know where I am coming from, but as I spend a lot
 of time in algebra I came to the conclusion that often this geometric
 reasoning is humbug.
</p>

<p>
What I have done is implement the same algorithm from
 a more approachable and visually simpler perspective. 
I have verified that its the same algorithm by comparing my
 tessellation with the know algorithm tessellation of the same
 monotone polygon and they are an exact match, so I am confident
 that they are the same algorithm.
</p>

<p>
I did the algorithm tessellation by hand for the example polygon 
 and produced the given table, which is viewed as columns of points
 which describe the algorithms tessellation state. When points
 are popped off the stack is where the triangles are being tessellated.
</p>

</div>

<div class="float25">

<p>
The &uparrow; and &downarrow; are the two ways the stack is processed.
 When a new point is added it is pushed to the front of the stack.
 The two previous points define a line. Choices are made on how to 
 connect the new point depending 
 whether the new point is visible to a previous line segment.
</p>

<p>
The coloring goes some way to explaining the computation because
 whenever two opposite are pushed onto the stack they are visible
 and then the greedy tessellation begins - the &uparrow; operation.
</p>

<p>
However you could have two points added on the same side(having the
 same color).  5o4o3* was an example where the last two points added
 where white. Again from the table the processing of the stack was 
 in a certain way which I called &downarrow;. What triggers this is
 a concept of a point being visible to the previous line segment.
</p>

<p>
For a line segment with two points the same color visibility
 is a vector pointing into the tessellation body. ie for
 a line on the right its the normal to that line pointing
 in the left direction. for a line on the left side its
 its normal pointing in the right direction.
</p>


</div>

<div class="spacer" />



<div class="float25">

<a id="Algorithms_Tessellation"> </a>
<h2> Algorithms Tessellation </h2>

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

</div>


<div class="float25">

<table>

<tr>
<td>0*</td>
<td>0*</td>
<td>0*</td>
<td>0*</td>
<td>3*</td>
<td>3*</td>
<td>3*</td>
<td>3*</td>
<td>5o</td>
<td>5o</td>
<td>6*</td>
<td>6*</td>
<td>7o</td>
<td>7o</td>
<td>8*</td>
<td>8*</td>
</tr>

<tr>
<td>1*</td>
<td>1*</td>
<td>1*</td>
<td>1*</td>
<td>4o</td>
<td>4o</td>
<td>5o</td>
<td>5o</td>
<td>6*</td>
<td>6*</td>
<td>7o</td>
<td>7o</td>
<td>8*</td>
<td>8*</td>
<td>9o</td>
<td>9o</td>
</tr>

<tr>
<td>  </td>
<td>2*</td>
<td>2*</td>
<td>2*</td>
<td>  </td>
<td>5o&downarrow;</td>
<td>  </td>
<td>6*&uparrow;</td>
<td>  </td>
<td>7o&uparrow;</td>
<td>  </td>
<td>8*&uparrow;</td>
<td>  </td>
<td>9o&uparrow;</td>
<td>  </td>
<td>10*&uparrow;</td>
</tr>

<tr>
<td>  </td>
<td>  </td>
<td>3*</td>
<td>3*</td>
<td>  </td>
<td>5,4,3 </td>
<td>  </td>
<td>6,5,3  </td>
<td>  </td>
<td>7,6,5  </td>
<td>  </td>
<td>8,7,6  </td>
<td>  </td>
<td>9,8,7  </td>
<td>  </td>
<td>10,9,8  </td>
</tr>

<tr>
<td>  </td>
<td>  </td>
<td>  </td>
<td>4o&uparrow;</td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
</tr>

<tr>
<td>  </td>
<td>  </td>
<td>  </td>
<td>4,3,2</td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
</tr>

<tr>
<td>  </td>
<td>  </td>
<td>  </td>
<td>4,2,1</td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
</tr>

<tr>
<td>  </td>
<td>  </td>
<td>  </td>
<td>4,1,0</td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
</tr>
</table>


<table>

<tr>

<td>9o</td>
<td>9o</td>
<td>9o</td>
<td>9o</td>
<td>9o</td>

<td>12*</td>
<td>12*</td>
<td>13o</td>
<td>13o</td>
<td>13o</td>

<td>13o</td>

</tr>
<tr>

<td>10*</td>
<td>10*</td>
<td>10*</td>
<td>12*</td>
<td>12*</td>

<td>13o</td>
<td>13o</td>
<td>14*</td>
<td>14*</td>
<td>14*</td>

<td>16*</td>

</tr>
<tr>

<td></td>
<td>11*</td>
<td>11*</td>
<td></td>
<td>13o&uparrow;</td>

<td></td>
<td>14*&uparrow;</td>
<td></td>
<td>15*</td>
<td>15*</td>

<td></td>

</tr>
<tr>

<td></td>
<td></td>
<td>12*&downarrow;</td>
<td></td>
<td>13,12,9</td>

<td></td>
<td>14,13,12</td>
<td></td>
<td></td>
<td>16*&downarrow;</td>

<td></td>

</tr>
<tr>

<td></td>
<td></td>
<td>12,11,9</td>
<td></td>
<td></td>

<td></td>
<td></td>
<td></td>
<td></td>
<td>16,15,14</td>

<td></td>

</tr>
<tr>

<td></td>
<td></td>
<td></td>
<td></td>
<td></td>

<td></td>
<td></td>
<td></td>
<td></td>
<td>16,14,13</td>

<td></td>

</tr>

</table>




<table>

<tr>
<td>13o</td>
<td>16*</td>
<td>16*</td>
<td>16*</td>
<td>16*</td>

<td>18o</td>
<td>18o</td>
<td>18o</td>
<td>18o</td>

</tr>
<tr>

<td>16*</td>
<td>17o</td>
<td>17o</td>
<td>18o</td>
<td>18o</td>

<td>19*</td>
<td>19*</td>
<td>20*</td>
<td>20*</td>

</tr>
<tr>

<td>17o&uparrow;</td>
<td></td>
<td>18o&downarrow;</td>
<td></td>
<td>19*&uparrow;</td>

<td></td>
<td>20*&downarrow;</td>
<td></td>
<td>21o&uparrow;</td>

</tr>
<tr>

<td>17,16,13</td>
<td></td>
<td>18,17,16</td>
<td></td>
<td>19,18,16</td>

<td></td>
<td>20,19,18</td>
<td></td>
<td>21,20,18</td>

</tr>


</table>

<p>...</p>

<h3> Table Key </h3>

<p>
Points on the right are colored black and have a star
 operator on the right. eg 15* says the point 15 is black
 colored. o indicates the point is white in color, and these
 points are on the left hand side.
</p>

<p>4,3,2 represents a triangle tessellation, and occur
 below the arrow event. </p>



</div>

<div class="spacer" />

<div class="float25">

<a id="Algorithm"> </a>
<h2> Algorithm </h2>


<p class="alg0">
Sort vertexes by y-coordinate. <br/>
Let v iterate from the highest point to the lowest point. <br/>
Initialize the stack p by pushing v twice to the front of the stack.

</p>

<p class="alg0">
while 
<math xmlns="&mathml;">
  <mi>v</mi>
  <mo>&NotEqual;</mo>
</math>
 lowest vertex do 
</p>

<p class="alg1">
push point 
<math xmlns="&mathml;">
  <mi>v</mi>
</math>
 to front of stack
<math xmlns="&mathml;">
  <mi>p</mi>
</math>.
</p>


<p class="alg1">
Case 1:
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
</math>
 has the opposite color to  
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
</math>
</p>

<p class="alg2">
Triangle fan about 
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
</math>
 clearing and returning by
 pushing to the front of the stack

<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
</math>
 and 
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
</math>.

</p>

<p class="alg1">
Case 2:
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
</math>
 has the same color as  
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
</math>
</p>

<p class="alg2">
while
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
</math>
 is visible to 


<math xmlns="&mathml;">
  <mi>line</mi>
  <mo>(</mo>
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
  <mo>,</mo>
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>
  <mo>)</mo>
</math>
 do 

</p>

<p class="alg3">
 Tessellate a 
 triangle from 
 <math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
</math>,
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
</math>,
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msub>
</math>.
<br/>
 Delete 
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
</math>

</p>

<p>
You will notice that there are two nested loops in the algorithm,
 yet the algorithm is known to be O(n).
 This is because the inner loop is constant in the sense that it iterates
 only as much as the outer loop. Since this multiplies by two its just
 a constant, and the complexity is still that of the outer loop O(n).
</p>


</div>




<div class="float25">

<a id="Algorithm_from_Computational_Geometry_in_C"> </a>
<h2>Algorithm from Computational Geometry in C</h2>

<p class="alg0">
Sort vertexes by y-coordinate. <br/>
Initialize reflex chain to be two top vertexes. <br/>
Let 
<math xmlns="&mathml;">
  <mi>v</mi>
</math>
be the third-highest vertex.
</p>

<p class="alg0">
while 
<math xmlns="&mathml;">
  <mi>v</mi>
  <mo>&NotEqual;</mo>
</math>
 lowest vertex do 
</p>

<p class="alg1">
Case 1:
<math xmlns="&mathml;">
  <mi>v</mi>
</math>
 is on chain opposite to reflex chain.
</p>

<p class="alg2">
 Draw diagonal from 

<math xmlns="&mathml;">
  <mi>v</mi>
</math>
 to top of reflex chain 
<math xmlns="&mathml;">
  <mi>v</mi>
  <msub>
    <mi></mi>
    <mrow><mi>+</mi></mrow>
  </msub>
</math>,
 and remove top of chain.
 If reflex chain is empty then advance 
<math xmlns="&mathml;">
  <mi>v</mi>
</math>.
</p>

<p class="alg1">
Case 2: 
<math xmlns="&mathml;">
  <mi>v</mi>
</math> 
 is adjacent to bottom of reflex chain.
</p>

<p class="alg2">
Case 2a:

<math xmlns="&mathml;">
  <mi>v</mi>
  <msub>
    <mi></mi>
    <mrow><mi>+</mi></mrow>
  </msub>
</math> is strictly convex.
</p>

<p class="alg3">
Draw diagonal from 
<math xmlns="&mathml;">
  <mi>v</mi>
</math>
 to bottom of reflex chain, and remove bottom of chain.
  If reflex chain is empty then advance 

<math xmlns="&mathml;">
  <mi>v</mi>
</math>.
</p>

<p class="alg2">
Case 2b:  

<math xmlns="&mathml;">
  <mi>v</mi>
  <msub>
    <mi></mi>
    <mrow><mi>+</mi></mrow>
  </msub>
</math>
 is reflex or flat.
</p>

<p class="alg3">
Add 
<math xmlns="&mathml;">
  <mi>v</mi>
</math>
 to bottom of reflex chain. Advance 
<math xmlns="&mathml;">
  <mi>v</mi>
</math>.
</p>

<div class="spacer" />


<p> See O'Rourke[1].
</p>

<p> I have included this algorithm for the purposes of comparing
 it with my own. 
 Two people can witness the same event but have very different
 perspectives about just what went on. What is reality?
</p>

<p> I do not understand the above algorithm as given, and
 I do not think that I ever will. This lead me to an investigation
 which looked at the tessellation from the point of view of stacks.
</p>


</div>

<div class="spacer" />


<div class="float25">
<a id="References"></a>
<h2>References</h2>

<ol>
<li>O'Rourke Joseph (1994). Computational Geometry in C.
 ISBN 0-521-445922.  Page 57.
</li>

</ol>



</div>

<div class="float25">

<a id="&lt;TODO&gt;"></a>
<h2>&lt;TODO&gt;</h2>

<ul>
<li>
Redocument the algorithm and replace the line sees with
 the half space.<br/>
</li>

<li>Generalize the algorithm to 3D where the girth is
 a triangle. Compare with 2D where the girth is a straight line.
</li>



</ul>



</div>



</body>
</html>



