<?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> Convexity and Polygon Representation with Algebra </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-12 &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>
Convexity and Polygon Representation with Algebra
<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="#What_is_Convexity"> What is Convexity?</a><br/>
<a href="#Convexity_and_Polygon_Representation_in_Algebra"> Convexity and Polygon Representation in Algebra </a> <br/>
 &nbsp; &nbsp; &nbsp; <a href="#Mathematical_Representations_of_Polygons">Mathematical Representations of Polygons</a><br/>
 &nbsp; &nbsp; &nbsp; <a href="#Simple_Polygon_Examples">Simple Polygon Examples</a><br/>
 &nbsp; &nbsp; &nbsp; <a href="#Complex_Polygon_Examples">Complex Polygon Examples</a><br/>
<a href="#Non-Unique_Polygon_Algebra"> Non-Unique Polygon Algebra </a> <br/>
<a href="#Maths_Polygon_Algorithm">Maths Polygon Algorithm</a><br/>
<a href="#Subtraction">Subtraction</a><br/>
<a href="../../../misc/proj/tri/doc.html"> 
  C++ shape rep implementation </a> <br/>
<a href="#Complexity">Complexity</a>



</p>
</div>

<div class="float25">

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

<p> Is a point inside or outside a polygon?  
 This is part of a general problem called 
 <a href="g033.xml">Inclusion in a Polygon</a>.
</p>

<p>

An algorithm to determine
 this for a general polygon will be constructed. By using partitions
 a point can be tested if it is within the partition. 
</p>

<p>
What goes for 2D is also true for 3D as well. Non-convex 2D and 3D shapes  
 can be fully described by algebra operations of addition(+) and
 multiplication(.) .
</p>

</div>

<div class="spacer" />

<div class="float25">

<a id="Convexity_and_Polygon_Representation_in_Algebra"> </a>
<h2> Convexity and Polygon Representation in Algebra </h2>

<p>
 Polygons can be represented generally as non-convex shapes.
  Convex shapes are closed regions where a line between any two 
    points in the region is made up of other points in the region.
</p>
   
<p>
    While this is the definition it does not tell the full story.
    Indeed its better to view convexity as multiplication 
    and non-convexity as addition. Since this unfortunately not well
    known (although authors such as Addler have written layman's books
    on mathematics and group theory which are outstanding) the general 
    communities have a limited view of these areas and so generally do the
    practitioners!!!  AND is multiplication and OR is addition.
</p>


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

</div>

<div class="float25">
<a id="Simple_Polygon_Examples"></a>
<h3>Simple Polygon Examples</h3>

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

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


</div>

<div class="spacer" />

<div class="float25">

<a id="Mathematical_Representations_of_Polygons"> </a>
<h3> Mathematical Representations of Polygons </h3>

<p>
By far the simplest representation of how to compose the shapes is with
 the diagrams and algebra where a number corresponds with the line. Whats
 represented by the number is tested. eg given test point does it satisfy
 the numbers test. If so return numeric 1 else return numeric 0 corresponding
 to true or false.
</p>

<p>
 Notice that the lines have the
 same anti-clockwise winding independent of 
 whether the AND(.)
 operator is being used or the OR(+) operator 
 is being used. This is good as it further
 simplifies describing the shape.

</p>

</div>

<div class="float25">
<img src="diagg02208.png" alt="diagg02208.png" />
</div>

<div class="spacer" />

<div class="float25"> 
<a id="Complex_Polygon_Examples"></a>
<h3> Complex Polygon Examples </h3>

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

<div class="float25">

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

</div>

<div class="spacer" />


<div class="float25">
<a id="Non-Unique_Polygon_Algebra"> </a>
<h2> Non-Unique Polygon Algebra  </h2>

<p>
The maths formula + for or and . for convexity is relatively
 easily found for static geometry where the programmer determines
 the expression by looking at the geometry. However can this
 be done by an algorithm?
</p>

<p>
Here is an example of a section of the shape having its
 formula found. Both expressions are equivalent and were
 formed by transversal of the line from one end to the other
 from opposite ends.
</p>

<p>
The current line segment partitioned points as being inside
 or not. If they were inside they had to be in the nested
 algebra expression.
</p>

</div>

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

<div class="spacer" />


<div class="float25">

<a id="Maths_Polygon_Algorithm"> </a>
<h2> Maths Polygon Algorithm </h2>

<p>
Each of the lines as a direction. Consider all the
 lines and subtract the lines which when partitioning
 the plane include all points. ie subtract all convex lines.
</p>

<p> Here is what remains of the initial example.
</p>

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

</div>

<div class="float25">

<p> Now transverse the line separating the line : 
 convex regions and non convex regions which intersect no 
 other lines, and other lines which do intersect other
 lines.
 The non-intersecting lines are expressed as algebra.
 If they are convex the lines are a product, if non-convex
 they are a sum. All these are summed.
 The non-intersecting lines are subtracted leaving
 the intersected ones remaining.
</p>

<p> The subtracted initial convex regions are multiplied
 with the non-intersecting line sum.
</p>

<p>Now what to do with the remaining lines is where the
 algorithm becomes recursive. Firstly in this simple
 example nothing remains and terminate. Assuming a more
 complicated shape, take the remaining points and
 apply the same algorithm to generate the algebra expression,
 then add it to the non-intersecting line sum.
 Repeat till no more points.
</p>

<p> Thus the algorithm is complete. Although simple
 I have not implemented it because there is a lot
 to do. For example classifying the line segment into
 convex and non convex pieces is from a programming point
 of view some work. Thats why I cheated, creating the
 algorithm and placing in my notes without implementing
 it. Cheers.
</p>


</div>

<div class="float25">
<a id="What_is_Convexity"></a>
<h2>What is Convexity?</h2>

<p>
A circle is always convex, and so is a triangle, and so is a sphere.
 But a donut is not. In maths it is a set of points where if we construct
 a straight line between the points, all the points are in the set too.
 In geometry if we take any two points in the shape then a line between
 these two points must also be in the shape for the shape to be convex.
</p>

<p>
Convex shapes provide a guarantee or completely define the shape.
 Algorithms that need to know if they are inside the shape often break
 down shapes into convex regions. Drawing and collision detection are two
 areas where these most work.
</p>

<p>
If an object is not convex then it is concave. A convex object is also
 a partition of two states: you are either inside it or not.
</p>

</div>

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

<p>The mathematics of partitions defined by two operators
 does not express the idea of subtraction. This is because
 the partiton can be defined to include this operation. 
 However for a maths system to be explict the not operator 
 needs to be introduced. Then we can define subtraction.
</p>

<p class="equ">
<math xmlns="&mathml;">
  <mi>A</mi>
  <mo>-</mo>
  <mi>B</mi>
  <mo>=</mo>
  <mi>A</mi>
  <mo>.</mo>
  <mo>~</mo>
  <mi>B</mi>
</math>


</p>


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

</div>



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

<p>
Technically its probably 

<math xmlns="&mathml;">
  <mi>O</mi>
  <mo>(</mo>
  <mi>N</mi>
  <mo>)</mo>
</math>
 complexity as the worst case would require computation
 of every half space.  However the implementation can
 take advantage of boolean algebra so that if say a sum
 is being summed and a one is added stop summing because
 the result is true and return the result.
</p>

<p>Further simplifying algebra reduces the computational
 cost by factoring like terms. Since this results in trees
 of expressions which may or may not need to be evaluated,
 the expected complexity may be dependent on the geometry
 and the sample points being tested.
</p>



<p>
Since this in part uses a layered approach (there is an outer
 layer and then inner layers for more detail) and the points 
 must first pass the outer layer tests, the algorithm can
 achieve constant time for all points that are rejected by
 the outer layer.
</p>

<p>
A direct analogy is in graphics the use of LOD where from
 far away a much less detailed model is used for the graphics.
 So while linear complexity is not appealing, if this can be
 minimized so constant complexity dominates then the technique
 could be useful. 
</p>

<p>The 
<a href="#Complex_Polygon_Examples">Complex Polygon Examples</a>
 give examples of the outer layer
 in 1.2.3.4 .
</p>


</div>



</body>
</html>


