<?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> Simplex Meshes with State
</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-05-15 &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>
Simplex Meshes with State
<a href="../../../../index.html">
<img alt="home" src="../../../comsci/images/Frame.gif" /> </a>
</h1>



<p>
<a href="#Intro">Intro</a><br/>
  &nbsp; &nbsp;
<a href="#Politics_and_Motivation">
  Politics and Motivation</a><br/>
  &nbsp; &nbsp;
<a href="#Axiomatic_Systems_and_Defining_Operators">
  Axiomatic Systems and Defining Operators</a><br/>
<a href="#Definitions">Definitions</a><br/>
  &nbsp; &nbsp;
  <a href="#Simplex_Representation">Simplex Representation</a><br/>

<a href="#Simplex_Operations">Simplex Operations</a><br/>

  &nbsp; &nbsp;
  <a href="#piRandomAccess">pi[]</a><br/>
  &nbsp; &nbsp;
  <a href="#piInverse_and_piInverseHas">piInverse and piInverseHas</a><br/>
  &nbsp; &nbsp;
  <a href="#niRandomAccess">ni[]</a><br/>
  &nbsp; &nbsp;
  <a href="#niInverse_and_niInverseHas">niInverse and niInverseHas</a><br/>
  &nbsp; &nbsp;
  <a href="#isnull_and_setnull">isnull and setnull</a><br/>
  &nbsp; &nbsp;
  <a href="#isonboundary">isonboundary</a><br/>
  &nbsp; &nbsp;
  <a href="#getanticlockwiseface">getanticlockwiseface</a><br/>
  &nbsp; &nbsp;
  <a href="#changelink">changelink</a><br/>

<a href="#Mesh_Operators">Mesh Operators</a><br/>
  &nbsp; &nbsp;
  <a href="#simplexdelete">simplexdelete</a><br/>
  &nbsp; &nbsp;
  <a href="#simplexswap">simplexswap</a><br/>
  &nbsp; &nbsp;
  <a href="#removenullsimplexes">removenullsimplexes</a><br/>
  &nbsp; &nbsp;
  <a href="#searchminimizetowardspoint">
    searchminimizetowardspoint</a><br/>
  &nbsp; &nbsp;
  <a href="#Recursion_with_a_User_Defined_Binary_Mesh_Operator">
    Recursion with a User Defined Binary Mesh Operator</a><br/>
  &nbsp; &nbsp;
  <a href="#Rotation_about_a_Point">Rotation about a Point</a><br/>
  &nbsp; &nbsp;
  &nbsp; &nbsp;
  <a href="#One_Dimensional_Rotation">One Dimensional Rotation</a><br/>
  &nbsp; &nbsp;
  &nbsp; &nbsp;
  <a href="#Two_Dimensional_Rotation">Two Dimensional Rotation</a><br/>
  &nbsp; &nbsp;
  &nbsp; &nbsp;
  <a href="#Generalized_Rotation_about_a_Point">
    Generalized Rotation about a Point</a><br/>

<a href="#Searching_in_a_Convex_Mesh">
  Searching in a Convex Mesh</a><br/>
<a href="#Edge_Representation">Edge Representation</a><br/>
  &nbsp; &nbsp;
<a href="#Edge_Tables_Generalized">Edge Tables Generalized</a><br/>
<a href="#Decimation">Decimation</a><br/>

  &nbsp; &nbsp;
  <a href="#Deleting_a_Point_Within_a_Mesh">
    Deleting a Point Within a Mesh</a><br/>
  &nbsp; &nbsp;
  <a href="#Deleting_a_Point_within_a_Convex_Mesh">
    Deleting a Point within a Convex Mesh</a><br/>
  &nbsp; &nbsp;
  <a href="#Infinite_Data">Infinite Data</a><br/>
  &nbsp; &nbsp;
  <a href="#Model_Extraction">Model Extraction</a><br/>

<a href="#Merging_Convex_Hulls">
  Merging Convex Hulls</a><br/>


<a href="#Convex_Meshes_with_Hull_or_Boundary_Points_Only">
  Convex Meshes with Hull or Boundary Points Only</a><br/>

<a href="#Splitting_a_Simplex_Generalized"> 
  Splitting a Simplex Generalized </a> <br/>
  &nbsp; &nbsp;
  <a href="#Cutting_a_Mesh_with_the_Point_Cut">
    Cutting a Mesh with the Point Cut</a><br/>
  &nbsp; &nbsp;
  <a href="#Operators_in_2D">Operators in 2D</a><br/>
  &nbsp; &nbsp; &nbsp; &nbsp;
  <a href="#In_2D_Split1D_Operator">In 2D Split1D Operator </a><br/>
  &nbsp; &nbsp; &nbsp; &nbsp;
  <a href="#Cutting_a_Triangle_with_a_Line">
    Cutting a Triangle with a Line</a><br/>
  &nbsp; &nbsp;
  <a href="#Operators_in_3D">Operators in 3D</a><br/>
  &nbsp; &nbsp; &nbsp; &nbsp;
  <a href="#In_3D_Split1D_Operator">In 3D Split1D Operator </a><br/>


<a href="#Collision_Detection_between_Convex_Tessellations">
  Collision Detection between Convex Tessellations</a><br/>
 &nbsp; &nbsp;
<a href="#Minimize_Towards_Points"> Minimize Towards Points</a><br/>
 &nbsp; &nbsp;
<a href="#Finding_the_Axis_of_Separation">
  Finding the Axis of Separation</a><br/>
 &nbsp; &nbsp;
<a href="#All_Viewable_Points">
  All Viewable Points</a><br/>

<a href="#Visible_Surface_Generation">
  Visible Surface Generation</a><br/>
  &nbsp; &nbsp;
  <a href="#Convex_Simplex_Mesh"> Convex Simplex Mesh</a><br/> 
  <a href="#Separate_Graphics_Objects">
    Separate Graphics Objects</a><br/>

<a href="#References">References</a>
</p>


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

<p> I have been using these meshes and writing algorithms on them, 
 however there is no definition of what I am doing in
 the literature that I have come across. Since they have
 been my building blocks for tessellation algorithms, I will
 describe them and talk about the doubly connected simplex meshes and operations on them.
</p>

<p> Let <b>simplex meshes</b> be meshes with the simplest
 polygon in that dimension.  In 2D its a triangle, in 3D a tetrahedron.
 Let the meshes be doubly linked to their neighbors by their faces.
 The face is one dimension less than the simplex.
</p>

<p>
The simplex mesh is a mesh with a current pointer to one of
 the simplexes in the mesh, variables containing a 
 orientation of a virtual shape at the current pointer, a vector of points pi and
 a vector of simplexes vi.
</p>

<p>There are two main data structures - the simplexes themselves and the meshes.
 Each data structure has its own operators, usually designed from the operators own perspective. 
 These operators have an instance of the data structure themselves.
</p>


</div>

<div class="float25">

<a id="Politics_and_Motivation"></a>
<h3>Politics and Motivation</h3>

<p>Predominately all the algorithms in computational geometry have
 a points and lines perspective. The simplex perspective
 which I am pursuing is a new direction in that
 now the perspective is the simplex.
</p>

<p>Reasons for this work were because algorithms on simplex data
 structures were superior.  For example marching cubes leaves
 surfaces with holes where as marching tetrahedrons does not.
</p>

<p>
Processing of graphics can be done on simplexes.  For example
 I have been building a general clipping algorithm on simplexes.
</p>

<p>These examples are about processing in algorithms. It is clear
 that not only can simplexes be used in a vast majority of
 graphics algorithms, they may possibly be used for any
 computational geometry task.
</p>

<p>The other reason for their importance is how intuitive they
 are.  Operators can be written for simplexes.  The basic operators
 generally can have inverses which makes them really good for use
 in algorithms.
</p>

<p>Ideas such as transversing of the mesh in linear time can also
 be solved.  See <a href="g039.html">
  Tessellation Transversing in a Linked Simplex Mesh</a>.
</p>

</div>

<div class="float25">

<p>In situations were I have found the data structure wanting there
 always seems to be a natural solution.  For example imagine a tessellation
 algorithm which used merging of convex hulls to do the tessellation.
 Initially I implemented the mesh where it owned the points and simplexes.
 But this merging algorithm could not afford to do this as the shear volume
 of copying of points and simplexes kills the complexity.  By making the
 points and simplexes global which the mesh sees this copying is entirely
 eliminated and hence the complexity of the algorithm being implemented
 is not changed by the simplex or mesh representation.
</p>

<p>In short if I encounter a problem then I dream up an operator or
 solution on the mesh or simplex. Because the data structures have operators  
 this is not only possible but easy to do.
</p>

<p>
The other major feature of simplexes is that their boundaries are half spaces.
 This is a very powerful data structure.  For some reason it too was neglected
 in the literature.  Consider the incremental algorithm and the computation
 of whether a point is outside the simplex or not.  They use the determinant
 and then talk about negative volume if the point is outside the simplex.
</p>

</div>

<div class="float25">

<p>This is a rather negative way of looking at the problem.  Yes what they
 are saying is true.  But a better explanation is that the point is visible
 to the half space on the boundary.  The user no longer needs to imagine
 negative volume but rather can the point be seen from the face.
</p>

<p>The other really interesting thing about meshes is that their logical
 consistency needs to be maintained.  This separates some of the 
 numerical issues from the logic of the mesh as a whole, something
 which other algorithms may choose to consider or ignore.
 This separation is really important.  It effects processing.  Much
 of the operators using processing with integers to transversing and
 other operations.  Once points are interpreted the mesh is formed. 
 For example I defined simplexes to contain their boundary as well
 as their inside.  While on first glance this may have been an arbitrary
 or theoretical thing it mattered when transversing a convex mesh
 looking for somewhere to insert a new point. When faced with this
 situation I look for what is simplest to implement.  The loss of
 uniqueness on the simplex boundary in the representation was a small
 price to pay for a stable algorithm.
</p>



</div>

<div class="spacer" />

<div class="float25">

<a id="Axiomatic_Systems_and_Defining_Operators"></a>
<h2>Axiomatic Systems and Defining Operators</h2>

<p>
Knuth has been very successful at finding the axioms of a system
 - usually minimal and then using these for usually more efficient
 computation. Not only can he build a whole system of mathematics
 but analyze and attack problems with new sets of tools.
</p>

<p>While this is also a classical approach - for example mathematics
 has a rich history of doing such things it is not the only way.
 What I have done is to create operators for the simplex mesh.
 This is similar to finding new axioms but my focus is not on
 being minimal but on achieving a computational task.
</p>

<p>
If the operator is general it should find uses in more than one
 algorithm.  For example splitting a simplex on a boundary seems
 to be very useful in algorithms.
</p>

<p>So my interest is targeted towards processing in algorithms.
 I do not deny the power of the axiomatic approach and there are
 probably situations where it is needed, however their operators
 are not always intuitive.  Sometimes they are of such a low level
 that you need to be a logician just to know what is going on.
</p>

<p>The operators which I described for simplex and mesh structures
 are diverse. They generally have a perspective relative to their
 data structure and are hopefully simple.  Many have been designed
 for stack processing which I believe is a characteristic of my style
 to solving these issues and while not so popular know stack processing
 is very powerful and efficient.  
</p>

<p>From the stacks point of view it does not differentiate between
 operators, it only sees the difference of the stack after an operator
 has been evaluated.
</p>

<p>To summarize the way that the simplex data structure theory is being
 developed is a mix of theory and practice.  While I do dream up theory
 it is not until I find it in practice that it becomes important.
 So I am going to implement many different algorithms with this data
 structure.  Then I will be in a better position to write about it
 and hopefully make it appear so simple that you will wonder why
 you had not thought of it yourself in the first place.
 My aim is to make it accessible to anyone who has the time.
</p>




</div>

<div class="float25">

<a id="Edge_Representation"></a>
<h2>Edge Representation</h2>

<p>
The most general way of identifying an edge is by
 the two points which define it.  In 2D an edge can also 
 be identified as opposite a vertex because edges are
 the simplex boundaries.
</p>

<p>For implementation purposes in 2D it is easier to refer to an
 edge by the opposite point. So the implementation can be different
 from the general operator.  eg <br/>
 The general operator split1D(p<sub>0</sub>,p<sub>1</sub>,z<sub>0</sub>) 
 could be implemented in 2D as
 split1D(s,p<sub>2</sub>,z<sub>0</sub>) where s points to the simplex,
 and p<sub>2</sub> is the point opposite the edge.
</p>

<p>If two simplexes share an edge then the edge is defined 
 in both the simplexes. So while the edge is unique its representation
 is not.
</p>

<p>Points can also be accessed by local indexes and the 
 <a href="#piRandomAccess">pi[]</a> operator.  While this is slightly more 
 efficient it produced problems when I implemented it in other algorithms.
 For example the geometry must be known and it is more fiddly to read pi[0] 
 and pi[1] and harder to debug the errors or change the code.
 For this reason I recommend using <a href="#piInverse_and_piInverseHas">
 piInverse and piInverseHas</a>.
</p>

<p>The simplex representation itself is at issue with accessing points locally.
  My first implementations defined the points in a particular order so that
 local point access was normal.  However because I found it to be error prone
 and I believed people do not have the patience for it (rightly so) I looked
 at the simplex representation and realized it could have been implemented 
 without ordering and that the ordering was necessary for the graphics
 to output the correct winding and for meaningful left and right movements.
 So I have identified the simplex as having two separate representations where
 ordering is a realization of the more abstract representation of a simplex
 which is just concerned with the links.
</p>
 
<p>So until I have resolved these issues edge representation can not be fully 
 addressed.  However in my diagrams I will use the general global point
 edge representation and in the implementation use a more efficient way.
</p>


</div>

<div class="spacer" />

<div class="float25">
<a id="Edge_Tables_Generalized"></a>
<h3>Edge Tables Generalized</h3>

<p>
The edge table is a very well known data structure so it is a natural
 question to ask how it is implemented in linked simplex meshes.
</p>

<p>When we are talking about edges what we really mean is the
 simplex boundaries hence the data structure needs a way
 of identifying or looking up the simplex from face on the boundary.
 In 2D the face is an edge, in 3D the face is a triangle.
</p>

<p>As previously mentioned faces are not uniquely represented as two simplexes
 that are neighbors share a face.  The following is an algorithm
 to find a simplex on a face if it exists.  The client can then
 further query the simplex to find the other simplex on the boundary if
 it exists or slightly modify the algorithm to do the look up for both
 simplexes.
</p>

<p class="alg1">
 Construct a vector of bucket lists in one to one correspondence with
 the meshes points. <br/>
 Iterate over the meshes simplexes. <br/>
 &nbsp; &nbsp; 
   for each simplex add a reference to itself to the end of each
 bucket list associated with the corresponding point.
</p>

<p class="alg1">To find a simplex on the boundary of a face take an
 arbitrary point on the face and iterate over its bucket list. <br/>
 for each simplex in the list <br/>
 &nbsp; &nbsp; 
 if all the remaining points on the face are also points in the current
 simplex then this simplex is on the face.  Return true for a simplex
 on the face was found. <br/>
</p>

<p>This provides constant look up time if the mesh is
 balanced.  
</p>



</div>

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

<p>Removing primitive shapes from the mesh. For example simplifying
 the mesh where the mesh covering is the same but there are 
 fewer shapes doing the covering.
</p>

<a id="Deleting_a_Point_Within_a_Mesh"></a>
<h3>Deleting a Point Within a Mesh</h3>

<p>
 Iterating around the point and identifying the simplexes.
 Divide the boundary of the point into convex shapes, re tessellate
 the convex shapes, connect everything together and re balance the
 mesh.
</p>

<p>For 3 or more dimensions iterating around a point becomes 
 non-trivial. The easiest way is to check if any of a simplexes neighbors
 share the point in question.  However for badly tessellated meshes
 the could be an arbitrary number of simplexes about a point. In general
 deleting with balanced meshes is best as unbalanced meshes could kill
 algorithm complexity. Iteration can be included within the simplexes
 data structure with a variable that asks whether the simplex has
 been transversed, and hence remove the need for some stack data
 structure that remembered which simplexes had been iterated over.
 The variable approach also guarantees constant access time for
 the question have I been iterated over (when implemented properly) so 
 it will not change a client algorithms complexity. 
</p>

<p>&lt;TODO&gt;Link with simplex iteration theory</p>

<p>If a point is on the surface it can not be deleted. 
 Determining this also seems to require iterating about the
 point. If the simplex has a face which is a boundary (its 
 neighbor is 0) and that face also shares the point then
 the point can not be deleted.
</p>


<a id="Deleting_a_Point_within_a_Convex_Mesh"></a>
<h3>Deleting a Point within a Convex Mesh</h3>

<p>Iterate around the boundary deleting the inner simplexes.
 Then retesselate using some convex hull algorithm. Alternatively
 retesellate with a fan algorithm and then use mesh re balancing.
 For example if you delete inside a balanced mesh you should refill
 the hole with a balanced mesh too.
</p>

<p>Here is an example in 2D. </p>

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



</div>

<div class="spacer" />

<div class="float25">
<a id="Infinite_Data"></a>
<h3> Infinite Data </h3>

<p>
I do not often think about the data stream where there is so much
 information that the computer can not process it, but in reality
 any engineering simulation usually produces gigs of data.  And the better
 that our equipment gets the much more information can be generated
 it is clear that our computers can not keep up.
</p>

<p>For these reasons data reduction algorithms and techniques are
 needed.  For example in marching methods on inserting a point in
 the mesh first test if the change in gradient with the surrounding
 points is significant.  If it is not then loose the information
 by throwing the point away.  This is a technique to reduce
 the volume of input points.
</p>

<p>Another situation is when you want a mesh for real time animation
 so you want to optimize an existing mesh by reducing its
 number of simplexes.  I really would like the opportunity to write
 and implement some of these algorithms on the linked simplex mesh.
 An interesting feature of linked simplexes is that you could choose
 to work on the surface of the mesh or the simplexes making the
 mesh.  Again I can see a very positive future for linked simplexes
 in this area.
</p> 

</div>

<div class="spacer" />

<div class="float25">
<a id="Model_Extraction"></a>
<h3>Model Extraction</h3>

<p>Think of an ideal or perfect model where if we so choose we could
 know every point within the model and on the model's surface.
 Then by taking points and tessellating we could approximate the model.
</p>

<p>Choices of points to be tessellated is interesting.  For example certain
 points must be added.  A finer grain of points around key areas of 
 complexity, ... The general idea being to extract points from the ideal model
 and use these to produce a new model.
</p>

<p>The basic problem with point representations is ambiguity.  How
 is a corner with 90 degree edges represented.  With smooth interpolation
 the boundary is made to curve around such a corner and the discontinuity
 in the first derivative is ignored.
 The other possibility is to model the boundary not as a smooth surface
 but two right faces.
</p>

<p>I am not going to solve these issues, but instead acknowledge their 
 existence in any algorithms constructed.  For example a first order
 smooth surface requires derivative information to be extracted from
 the points. By default the simplex mesh is faceted or non-continuous
 in the first derivative. Although the points of the mesh are on the
 surface/volume, we know nothing in between.  
</p>

</div>

<div class="float25">

<p>Interpolation between points is critical for model and mesh accuracy.
 For example taking a known object we can sample it and calculate its
 volume. Through interpolation between points the surface is made much
 closer to the actual surface and hence the volume calculation becomes
 more accurate.  As higher order interpolators are possible the 
 interpolation becomes more accurate - assuming a continuous surface
 between the points.
</p>

<p>A major property of the simplex mesh becomes solving derivative
 information at the points, then using interpolation between the points.
</p>

<p>The increase in interpolation order is still limited by the points
 being sampled.  Appart from being very difficult in 3D to do.  The position
 of the sampled point effects the model and there are many algorithms
 that discuss this, I am just starting to look at it.
</p>


<p>From the simplex meshes perspective how can it be used for model
 decimation.  Are their algorithms which are naturally suited to
 it - for example transversing the surface is one the the linked
 simplexes strengths, can this be used be a model decimation algorithm?
</p>






</div>


<div class="spacer" />

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

<p>A <b>simplex</b>is the simplest bounded object 
 in that dimension.  The object is convex in the sense that 
 any point inside itself can be connected to another point inside
 itself, and the line of points connecting the two points is
 also inside the object too.
</p>

<p>
  For example 
  a triangle is a 2-simplex in 
<math xmlns="&mathml;">

  <mi>R</mi>
  <msup>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msup>
</math>, 

  a tetrahedron is a 3-simplex in 
<math xmlns="&mathml;">
  <mi>R</mi>

  <msup>
    <mi></mi>
    <mrow><mi>3</mi></mrow>
  </msup>
</math>
.
</p>

<p> And you can see that this can be generalized
 for any dimension.  Not that a N-simplex has
 
<math xmlns="&mathml;">
  <mi>N</mi>
  <mo>+</mo>
  <mi>1</mi>
</math>

 sides for

<math xmlns="&mathml;">
  <mi>R</mi>
  <msup>
    <mi></mi>
    <mrow><mi>N</mi></mrow>
  </msup>
</math>
 space.

 So a line segment is a simplex in 1D.
</p>

</div>

<div class="float25">


<a id="Simplex_Representation"></a>
<h3>Simplex Representation</h3>

<p>I have implemented the simplexes as an ordered set
 of points and an ordered set of neighbors.  The order of
 the points defines a fixed orientation.
</p>

<p>The neighbors are pointers opposite the vertex of the
 point with the same local index.  The simplex has a property
 that the sides of boundary of the simplex are in one to one correspondence
 with the number of points the simplex has.
</p>

<p>The points and neighbors have integer indexes as both the points 
 and simplexes are stored in a vector data structure.
</p>

<p>The simplex representation is not unique.  If the simplex is N dimensional
 there are N such representations, just shift the point and neighbors along.
</p>

<p>For two dimensional space the simplex is a triangle and the order of points
 is defined to be anti clockwise in direction.  For 3 or more dimensions
 I choose an arbitrary ordering of points.  There could be a more general
 pattern but I have not investigated higher dimensions.  
</p>



</div>

<div class="float25">

<a id="Simplex_Operations"></a>
<h2>Simplex Operations</h2>

<p>
These are functions which are defined on the local data
 structure.  For example given the point p, does it
 belong to the simplex s?
</p>

<p>These operations act on an instance of a simplex data structure.
  The dot operator is also a membership operator, so if x is 
 a simplex the following calls the pi[] operator on x assigning the
 index to a point to y.
</p>

<pre>
y = x.pi[2]
</pre>

<p>Programmers will feel very much at home with this notation.  It is 
 incredibly concise and very useful.
</p>
 

<a id="piRandomAccess"></a>
<h3>pi[]</h3>

<p>Return an index to a point.  The local index argument 
 is anywhere from 0 to N-1 where N is the simplex dimension
 and the argument is an integer.
</p>

<a id="piInverse_and_piInverseHas"></a>
<h3>piInverse and piInverseHas</h3>

<p>These functions are very similar and are essentially the reverse of pi[].  
 For efficiency <code>piInverse(gpt)</code> assumes
 that the point exists and returns its local index.</p>

<p>
 Alternatively <code>piInverseHas(gpt)</code> does not return the local index but
 queries whether the point is belongs to the data structure and returns a boolean value. 
</p>

<a id="niRandomAccess"></a>
<h3>ni[]</h3>

<p>Return an index to the simplex that is opposite the
 point with the same local index. A zero is returned if
 the simplex has no neighbor.
</p>

<p>When two simplexes are connected and share a border they
 both point to each other.  While this is part of the mesh
 and has nothing to do with the simplex data structure I mentioned
 it only that you should expect a two way link.  However someone 
 could always implement one way links as another type of mesh.
</p>

<a id="niInverse_and_niInverseHas"></a>
<h3>niInverse and niInverseHas</h3>

<p>These functions are very similar and are essentially the reverse of ni[].  
 For efficiency <code>niInverse(nieb)</code> assumes
 that the neighbor exists and returns its local index.</p>

<p>
 Alternatively <code>niInverseHas(neib)</code> does not return the local index but
 queries whether the neighbor is pointed to by this data structure and returns a boolean value. 
</p>



<a id="isnull_and_setnull"></a>
<h3>isnull and setnull</h3>

<p>A simplex can become non existent within a mesh.  To support this the concept
 of a zero point and a zero neighbor were introduced to indicate no point or neighbor.
 It naturally follows that a simplex with all of its point and neighbor fields
 set to zero is a non existent simplex.
</p>

<p>The functions <code>setnull()</code> set all the simplexes fields to zero.</p>
<p>The function <code>isnull()</code> queries whether this simplex exists or not.</p>

<a id="isonboundary"></a>
<h3>isonboundary</h3>

<p>A zero neighbor is interpreted as a surface boundary. I use surface loosely to refer to
 a connected mesh or simplex one dimension less than this simplex.  Often we want to identify
 the surface or boundary and testing whether one of its links is zero does this, provided this
 simplex exists.
</p>

<a id="getanticlockwiseface"></a>
<h3>getanticlockwiseface</h3>

<p>This function returns a simplex as an ordered series of points opposite a point on this simplex.</p>

<p>For a n dimensional simplex <code>getanticlockwiseface(n-1)</code> returns the same ordering of 
 points which defined this simplex.  So you can see that this function really returns valid
 permutations of this simplex and ties in with what I said earlier in that the way the simplex is
 defined it is not a unique data structure.  The different permutations represent simplex orientations
 and in this sense it is unique.
</p>


<a id="changelink"></a>
<h3>changelink</h3>

<p>This is a very simple operation.  It takes a valid link and points it to somewhere else.
 While it appears simple it is very useful, here is the definition.  For efficiency I assume
 that the references are valid.
</p>

<pre>
  // Change the link to point to another simplex.
  void changelink( uintc from, uintc to )
    { ni[ niInverse(from) ] = to; }
</pre>









</div>


<div class="float25">
<a id="Mesh_Minimization"></a>
<h2>Mesh Minimization</h2>

<h3>Simplex Minimization</h3>

<p>TODO - vast topic.</p>

<h3>Insertion of new Point into a Continuous Convex Mesh</h3>
<p> Let a Continuous mesh be one where all the shapes are 
 connected. </p>

<h3>Insertion of a Simplex into a Non-Continuous Mesh</h3>

<p>
Let a Non-Continuous mesh be a mesh which may have unconnected
 shapes.
</p>






</div>

<div class="float25">
<a id="Mesh_Operators"></a>
<h2>Mesh Operators</h2>


<a id="simplexdelete"></a>
<h3>simplexdelete</h3>

<p>
<code>simplexdelete(s)</code> deletes the simplex pointed to by s.
 If the neighbors are not null then they are transversed and their
 links to s are set to 0.  All the fields in s are set to 0.
</p>

<a id="simplexswap"></a>
<h3>simplexswap</h3>

<p>This swaps two arbitrary simplexes in the mesh.  This requires
 any simplexes which point to either of s0 or s1 to also be changed.
 The call to this function looks like this. <code>simplexswap(s0,s1)</code>.
</p>

<p>Here is the pseudo code for a two n dimensional simplexes to be swapped. </p>

<p class="alg1">
simplexswap( s0, s1) 
</p>

<p class="alg2">
Copy the old links.<br/>
for i=0..n-1<br/>
 &nbsp; &nbsp; a<sub>i</sub> = vi[s0].ni[i] <br/>
 &nbsp; &nbsp; b<sub>i</sub> = vi[s1].ni[i] 
</p>

<p class="alg2">
Update the new links.<br/>
for i=0..n-1<br/>
 &nbsp; &nbsp; if (a<sub>i</sub>
<math xmlns="&mathml;">
  <m0>&NotEqual;</m0>
</math>0) <br/>
 &nbsp; &nbsp; &nbsp; &nbsp;
    if (vi[a<sub>i</sub>].niInverseHas(s1)==false) <br/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
      vi[a<sub>i</sub>].changelink(s0,s1); <br/>
 &nbsp; &nbsp; &nbsp; &nbsp;
    else <br/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
      Swap the neighbors s0 and s1. <br/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
      c = vi[a<sub>i</sub>].niInverse(s1) <br/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
      vi[a<sub>i</sub>].ni[ vi[a<sub>i</sub>].niInverse(s0) ] = s1 <br/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
      vi[a<sub>i</sub>].ni[c] = s0 <br/>
     

 &nbsp; &nbsp; if (b<sub>i</sub>
<math xmlns="&mathml;">
  <m0>&NotEqual;</m0>
</math>0) <br/>
 &nbsp; &nbsp; &nbsp; &nbsp;
    if (vi[b<sub>i</sub>].niInverseHas(s0)==false) <br/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    vi[b<sub>i</sub>].changelink(s1,s0);
</p>

<p class="alg2">
Finally swap the simplexes position in the vector vi. <br/>
  &nbsp; &nbsp; 
  simplex s = vi[s0]; <br/>
  &nbsp; &nbsp; 
  vi[s0] = vi[s1]; <br/>
  &nbsp; &nbsp; 
  vi[s1] = s
</p>

<p>This code can be optimized further.  For example from treating one of the simplexes 
 the case of neighbors sharing a border between the two simplexes s0 and s1 can be identified
 and need not be tested a second time for the second simplex.  As it is the code is bordering on
 a reader ignoring it because it already looks too complicated so I did not wish to further
 screw with the code.
</p>


<a id="removenullsimplexes"></a>
<h3>removenullsimplexes</h3>

<p>Simplify the mesh by removing dead or null simplexes.  The list of simplexes is transversed
 once and null simplexes are swapped out and deleted.
</p>

<p class="alg1">
Remove any null simplexes at the end of vi so the last simplex is non null or there is no tessellation.
</p>

<p class="alg1">
Iterate through the simplexes. Swap any null simplexes with the last non null simplex. <br/>
</p>

<p class="alg2">
Remove any null simplexes at the end of vi so the last simplex is non null or there is no tessellation.
</p>

</div>

<div class="spacer" />

<div class="float25">
<a id="Recursion_with_a_User_Defined_Binary_Mesh_Operator"></a>
<h3>Recursion with a User Defined Binary Mesh Operator</h3>

<p>
This is about separating recursively processing a mesh from
 the operator which is applied to an individual mesh element.
</p>

<p>
 For example consider the problem of having a maximum edge
 length in a mesh.  The mesh has to be transversed and any
 simplex that is found with an edge length exceeding the maximum
 edge length has to be split and the resulting simplexes reprocessed.
 This is an instance of adaptive tessellation.
</p>

<p>
Another example can be found with Delaunay Triangulation where
 any simplex which is not minimal needs to be re tessilated with
 the flip operators.
</p>

<p>
What is common here is that the mesh needs to be changed until
 some condition is met. In maths that is until the mesh becomes
 invariant (does not change) under some operation.
</p>

</div>

<div class="float25">

<p>What is also apparent is that the interaction with the operator
 can be generalized to considering the interaction between two
 adjacent simplexes which share a border.  Let this be defined
 by the user and call it a binary simplex operation.
</p>

<p>While two simplexes are involved I implemented this generalization
 in different ways.  Having an operator which takes two simplexes
 referenced globally.  The problem with this is that the mesh can
 change and the user has to consider that a pair of simplexes
 are invalid because the mesh has changed. See 
<a href="../../../misc/proj/triangle/cetess.html#Minimize_the_Whole_Mesh"> 
 Minimize the Whole Mesh </a> for an example.  There is nothing
 wrong with this type of processing there are just several different ways
 of doing things.
</p>

<p>The following recursion algorithm takes takes the perspective of
 a single simplex.  It implements the binary operator by refering to
 the neighbor with its own local index.  A boolean value is returned
 to indicate whether the mesh was changed. 
</p>

</div>

<div class="spacer" />

<div class="float25">
<a id="Rotation_about_a_Point"></a>

<h3>Rotation about a Point</h3>

<p>Rotating about a point is a fundamental operation. For example
 in the surface operator the current simplex is rotated about a point
 on the surface 
 till the current simplex is on the next surface simplex.
 Another application is determining if a point is inside the mesh and
 not on the surface.
</p>


<p>Rotation is not uniquely defined.
 In 2D rotation about a point is deterministic or more specifically
 in one dimension. But in 3D rotation about a point is a 2 dimension
 operation. However it is 1D if rotation is about a line.
</p>

<p>Often an algorithm needs to rotate about a point to do something.
 Here a list of simplexes may be generated and processed, or as
 each simplex is found it is processed. This is iteration within the mesh.
</p>

<p>The complexity of rotation about a point depends on the mesh.
 For example consider a unit cube with points on the surface and
 all the tetraherons have a common point. This is a fan tessellation.
 Iterating about a point is O(N) where N is the number of simplexes(tetrahedrons).
</p>

<p>Balanced meshes turn the rotation from an O(N) to an O(1) operation.
 This is so important because if you use the rotation operators in
 an algorithm with an unbalanced mesh it kills the performance.
</p>

<p>While this may sound obvious I designed a tessellation algorithm
 which used points outside the tessellated object and hit this problem
 after implementing it.  Looking back it was silly. So generally use
 balanced meshes.
</p>

</div>

<div class="float25">
<a id="One_Dimensional_Rotation"></a>
<h4>One Dimensional Rotation</h4>

<p>In 2D rotation about a point is one dimensional.  In 3D rotation about
 a line is one dimensional.  I guess in 4D rotation about a 3D object is
 one dimensional too.  
</p>

<p>The common property of rotating in one dimension is that you only need
 to know two simplexes - the two end simplexes. 
</p>

<p class="alg1">
Orient the current simplex about the axis of rotation so that the
 movement operators m<sub>left</sub> and m<sub>right</sub> rotate about
 the rotation axis. In 2D the axis is a point. In 3D it is a line.
</p>

<p class="alg1">
Let x<sub>0</sub> be the intial simplex. <br/>
Let x be the current simplex.<br/>
repeat<br/>
  &nbsp; &nbsp;
  m<sub>left</sub><br/>
  &nbsp; &nbsp;
until x==x<sub>0</sub> or a surface is hit and m<sub>left</sub> does
 not change the state.<br/>
If (x==x<sub>0</sub>)<br/>
  &nbsp; &nbsp;
  A loop has been generated<br/>
  &nbsp; &nbsp;
  return<br/>
Let x<sub>1</sub>=x<br/>
Let x=x<sub>0</sub><br/>
repeat<br/>
  &nbsp; &nbsp;
  m<sub>right</sub><br/>
until x==x<sub>1</sub><br/>
The rotation is not a loop.
</p>

</div>

<div class="spacer" />

<div class="float25">

<a id="Two_Dimensional_Rotation"></a>
<h4>Two Dimensional Rotation</h4>

<p>Consider rotating about a point in 3D. If backwards movement
 is restricted then there are 3 possible movements m<sub>0</sub>,
 m<sub>1</sub>, m<sub>2</sub>.</p> 

<p class="alg1">
Let v be a list of simplexes to be processed.<br/>
Let dead be processed simplexes.<br/>
Let m<sub>0</sub>, m<sub>1</sub>, m<sub>2</sub> be move operators
 that are not backwards.<br/>
Let r be a list of simplexes that are rotated about the point.<br/>
Let p be the point being rotated about.<br/>
Assume x.piInverseHas(p)==true
</p>

<p class="alg1">
Push x the current simplex to v and r<br/>
while v is not empty<br/>
  &nbsp; &nbsp;
  u = last simplex of v <br/>
  &nbsp; &nbsp;
  pop the last simplex of v <br/>
  &nbsp; &nbsp;
  for k=0..2 <br/>
    &nbsp; &nbsp; &nbsp; &nbsp;
    x = u <br/>
    &nbsp; &nbsp; &nbsp; &nbsp;  
    m<sub>k</sub><br/>
    &nbsp; &nbsp; &nbsp; &nbsp;  
    if (x is in dead) <br/>
      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
      continue<br/>
    &nbsp; &nbsp; &nbsp; &nbsp;  
    if (x.piInverseHas(p))<br/>
      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
      Push x to v and r<br/>
    &nbsp; &nbsp; &nbsp; &nbsp;  
    else<br/>
      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
      Insert x in dead<br/>
  &nbsp; &nbsp;
  Insert u in dead<br/>
</p>

<p>A variation is when the boundary is to be extracted.
 Then two dead lists could be used one for those in r and the other
 for those not in r.
</p>

<p>This algorithm is not limited to rotating about a point.
 The condtition test x.piInversHas(p) can be replaced, for example
 detecting a region of great gradient change, or perhaps finding
 a contour region.
</p>

<p>The operators m<sub>i</sub> change the orientation.
 It could be useful to define a backward operator and some means
 of restoring the orientation.
</p>


<a id="Generalized_Rotation_about_a_Point"></a>
<h4> Generalized Rotation about a Point</h4>

<p>The idea of connectedness of the mesh can be partially
 captured with a necessary but not sufficient condition.
 That being that all the simplexes moved to have a point in common.
</p>

<p>This assumes that the mesh is logically connected so that
 a neighbor is actuall next to another simplex.  Assuming that
 this is true then I believe that the following is also a 
 sufficient condition.
</p>

<p class="alg1">
Let Z be a list of simplexes that have a point p
 as one of there vertexes.<br/>
Let Z<sub>i</sub> be any one of the simplexes in Z.<br/>
Z<sub>i</sub>.piInverse(p) != 0<br/>
Let D be the dimension.<br/>
  &nbsp; &nbsp;
  a = Z<sub>i</sub>.piInverse(p)<br/>
  &nbsp; &nbsp;
  k=1..D<br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    Z<sub>i</sub>.ni(a+k mod D) == 0 or is a simplex in Z.<br/>
</p>

<p class="alg1">
If Z satsifies these conditions then Z is the list of simplexes
 about the point p which are connected to each other so you can
 move from any one simplex to another in Z.  This is a convex
 relationship not with a continuous space but a discrete space.
 Since convexity is so important in a continuous space you would
 expect it to be equally as important in a discrete space,
 perhaps a few more people should be writing about this.
 And you wonder why I hate other mathematicians so much! They are just
 not interested.  
</p>

<p>Clearly this is also an algorithm for rotating about a point in
 any dimension.
</p>

<p>If we implement it with stacks then this list of simplexes is
 not known and grows.  For a container this may have problems
 with changing its size but this can be avoided by having a large
 container and a balanced mesh so resizing should not occure.
</p>

<p>It is possibly not efficent or an overkill if rotating in 1D.
 However for a balanced mesh this should also have an O(1) complexity.
</p>

<p>How to get from this to using operators for transversal is not
 clear.  For example movement operators are used to generate Z the set of
 simplexes about a point as the algorithm iterates. 
 This is a theory question.  How do we link the operators to connectedness.
</p>


<p>
Having a stack
 that keeps a list of visited simplexes needs to do a lookup to see
 if a new simplex has previously been visited. In an array the
 lookup could be linear, binary or use hash tables for a constant
 lookup.  
</p>

<p>
Alternatively each simplex could have a boolean value to
 say if it has been visited or not, which is used and reset after
 the algorithm terminates.  Hash tables seem more attractive because
 they do not require any addition to the data structure but these
 need to be carefully written and are(in my opinion) not good for the cache.
 So for extreme performance I suggest having the boolean value in
 the simplex data structure. Realistically hash tables are practical and
 should be used.
</p>

<p>The idea of a ball about a point in continuous space is a pillar
 in functional analysis.  The ball is used to determine connectedness
 of a space with a metric and the comparision operators. So the
 local perspective is the ball and the global perspective is the space.
</p>

<p>The linked simplex mesh has a surface, outside the surface and inside.
 The surface has a simplex with a 0 neighbor. The mesh is the space.
 The metric is discrete and perhaps this number of simplexes in the 
 connection.
</p>

<p>A ball in the simplex mesh is interesting. Where as the ball in
 functional analysis vanishes to achieve continuity, the ball in
 a simplex mesh has a smallest state that is a mesh with one
 central point. Further these are not equal as the smallest ball
 at one point of the mesh is different from the smallest ball in
 another part of the mesh because they have different number of simplexes.
</p>


<p>Topology uses functional analysis to define a topological space.
 So it would be of interest if the mesh can be defined as a functional
 space (with meaning) or is it different?
</p>

<p>I apologize for my lack of understanding about these matters, but
 it apears to me that discrete spaces are completely different from
 continuous spaces and yet they share many properties.  It would be
 fair of me to say that I am completely dissatisfied with the general
 literature.  In my maths degree almost no effort was made to look
 at discrete mathematics as they assumed the classical approach was
 enough, I had to unlearn so much. Consequently I stoped reading
 functional analysis.  So even if this satisfies a metric space
 where is the literature that applies it to discrete spaces?
 It can be argued that discrete methods are not well known and yet 
 historically they have always been used.
</p>

<p>Even if the discrete space is completely different with the mathematics
 it is still applicable to continuous space because it can approximate it.
 For example all the shifting of limits and integration tricks have
 discrete conterparts which is why Knuths Concrete Mathematics is
 interesting.  And while this is a beginning most of the analysists that
 I know do not even read this literature let alone apply and extend
 it to their fields.  Knuth's work is not taught at RMIT in 1st year,
 second year or third year. In private conversations I gather that
 some do read it, may I suggest that they teach it too.  But then
 I would not want to be taught it from them so I am glad that they
 don't have another thing to stuff up.  However as I am always
 believe in people there may be hope(for the next, next,
 next, and then next generation). Fossiles, but then again there is
 always some maverick in the past who was totally ignored and
 did so really impressive work - so I have hope. A possible candadite
 is Charles Baggage why while rewarded for working towards the computer
 was ignored for his work on functional analysis, I hope he gets them
 back and more tools are made available to the general public.
</p>

</div>

<div class="spacer" />

<div class="float25">

<p class="alg1">
Let <code>op</code> be a user defined operator which returns
 true if the operator changed the mesh else false is returned. <br/>
<code> bool op.eval(uint s, uint k)</code> <br/>
k is the local index with 
<code>0 &leq; k &lt; N &nbsp; </code> where 
 <code>N</code> is the simplexes dimension,
 <code>s</code> is the reference to the simplex.
</p>

<p class="alg1">
Let <code>process</code> be a stack of integers refering to simplexes to
 be processed.  
 Initially a single simplex or simplexes are pushed onto the 
 <code>process</code> stack. <br/>
Let <code>vi</code> be the stack of simplexes which are refered to.
</p>

<p class="alg1">
while process is not empty <br/>
  &nbsp; &nbsp;
  k = last element of process <br/>
  &nbsp; &nbsp;
  pop this element from the stack <br/>
  &nbsp; &nbsp;
  Let x be the simplex refered to by k ie vi[k]  <br/>
  &nbsp; &nbsp;
  for i = 0..n-1<br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    nb = x.ni[i]; <br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    Get the initial size of the simplex stack before processing the operator.<br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
      visz = vi.size(); <br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
      if op.eval(k,i) <br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
        if (nb!=0) <br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
          process.push_back(nb); <br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
        process.push_back(k); <br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    If the vi stack has grown reprocess the new simplexes <br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;

        for (uint j=visz; j&lt;vi.size(); ++j) <br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
          process.push_back(j);<br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
        Stop processing the current simplex and exit the loop <br/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
        i=10; // kill loop
</p>

</div>

<div class="float25">

<p>
This little algorithm may look unfriendly or even why waste my time
 but it has the beauty of write once forever use again. In simple
 language it is general.  The user defines the operator for it
 and plugs it in.  So while initially it is of little interest
 the more times you write mesh iterators the more times you will 
 appreciate the separtion of the problem of mesh iteration
 from the operators that change the mesh.
</p>

<p>This is not a general mesh operator, rather one of many. I use other
 generalized operators and I will further document these later.
</p>

<p>
The mesh operators are assumed to change the mesh in a certain way.
 Either they overwrite a simplex or push it to the end of
 the simplex stack vi.  So the change in the mesh after the operator
 has been applied is predicatble.  We may not know how many simplexes
 are created or deleted, but by examining the stack afterwards any
 new simplexes can be processed. Which is what the algorithm does.
</p>


<p>Here is an example in C++ of the maxEdgeLength operator which solves
 the initial problem posed of adaptive tessellation in 2D.  
 If an edge
 is to long its midpoint is found and the simplex is split on that
 edge.
</p>

<pre>
class maxEdgeLength
{
  d3tess &amp; tess;
  vector&lt;d3tri&gt; &amp; vi;
  vector&lt;pt3&gt; &amp; pt;
  double const delta;
public:

  maxEdgeLength(d3tess &amp; _tess, double const _delta)
    : tess(_tess), vi(tess.vi), pt(tess.pt), delta(_delta) {}

  bool const eval(uintc s, uintc j)
  {
    assert(j&lt;3);

    d3tri * x = &amp; vi[s];
    pt3c &amp; A(pt[ x-&gt;pi[(j+1)%3] ]);
    pt3c &amp; B(pt[ x-&gt;pi[(j+2)%3] ]);
    if ( (A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y) &gt; delta )
    {
      tess.splitmidpoint1D(s,x->pi[j]);
      return true;
    }

    return false;
  }
};
</pre>


</div>


<div class="spacer" />

<div class="float25">

<a id="searchminimizetowardspoint"></a>
<h3>searchminimizetowardspoint</h3>

<p>If the mesh is convex then it is possible to search the mesh from
 any point in the mesh towards another point as a property of convex
 objects is that any two points in a convex object have all the points
 joining the two points by a straight line also in the convex mesh.
</p>

<p>The mesh has a current simplex cp. The current simplex cp is tested to see
 if the search point is outside or not.  If false then the point is assumed
 to be either on the boundary or inside the simplex and hence found.
 Else the first face that can see the point is transversed.  If this
 face has no neighbor and is a boundary then the search is terminated.
</p>

<p>The search is greedy as it takes any move which further minimizes towards
 termination.  There is no weighing of whether one move is better than another,
 the first possible move is taken.
</p>

<p>Half spaces are used to test if the point p is visible to a face on the
 current simplex.
</p>

<p>Here is the search described as an algorithm.</p>

</div>

<div class="float25">

<p class="alg1">
Let p be the target point being minimized towards. <br/>
Let H<sub>i</sub> be the half spaces pointing outside the simplex cp. <br/>
Let n be the number of dimensions of the simplex.<br/>
Let nb be a pointer to a neighbor.<br/>
Let vi be a vector of simplexes and cp be the current simplex.
</p>

<p class="alg1">
bool searchminimizetowardspoint(p)
</p>

<p class="alg2">
for i = 0 .. n-1 <br/>
  &nbsp; &nbsp; 
  if ( p is viewable to H<sub>i</sub> )  <br/>
  &nbsp; &nbsp; &nbsp; &nbsp;
  nb = vi[cp].ni[i] <br/>
  &nbsp; &nbsp; &nbsp; &nbsp;
  if (nb==0)<br/>
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  return false <br/>
  &nbsp; &nbsp; &nbsp; &nbsp;
  Move the cp towards p and continue <br/>
  &nbsp; &nbsp; &nbsp; &nbsp;
  cp = nb <br/>
  &nbsp; &nbsp; &nbsp; &nbsp;
  i = 0
</p>

<p class="alg2">
If control reaches here then p is not outside the simplex. <br/>
return true
</p>


<p class="alg1">
The algorithm returns true if the point p is not outside the convex
 mesh.  In this case the current simplex cp contains point p on its
 boundary or inside itself. 
</p>

<p class="alg1">
If the algorithm returns false then the point p is viewable to one
 of the simplexes on the boundary of the convex mesh.
 For convenience align the virtual simplex to have its base on
 the face viewable to point p.
</p>

</div>

   


<div class="float25">



<p> TODO. movement.  Take from cetess.html and place the notes here.
</p>


<h3>Iterating around a Boundary</h3>

<h3>Iterating about a Vertex</h3>

<a id="Searching_in_a_Convex_Mesh"></a>
<h3>Searching in a Convex Mesh</h3>

<p class="alg0">
boolean search(p)
</p>



<p class="alg1">
Repeat forever
</p>

<p class="alg2">
if (p inside virtual simplex)
</p>

<p class="alg3">
return true
</p>

<p class="alg2">
Assume all faces point outside the
 simplex. 
</p>

<p class="alg2">
Dimension N simplex has N+1 faces. Iterate over the faces.
<br/>
hasmoved=false <br/>
i=0..N-1
</p>

<p class="alg3">
if (p is visible to a face)
</p>

<p class="alg4">
if (the face has no neighbor)
</p>

<p class="alg5">
  return false
</p>

<p class="alg4">
Move the virtual simplex to the
 neighbor.
<br/>
hasmoved=true
</p>

<p class="alg2">
if (hasmoved==false)
</p>

<p class="alg3">
Force a move.  If unable return false.<br/>
</p>

<p>The meshes virtual simplex is minimized
 towards the point.  If the point is within the 
 mesh the point will be inside the virtual simplex.
 Else the virtual simplex will be left on the
 convex boundary and the point will be visible to it.
</p> 


</div>

<div class="float25">
<a id="Merging_Convex_Hulls"></a>
<h2>Merging Convex Hulls</h2>

<p>TODO. see [1] O'Rourke p.126 and my notes.</p>


</div>

<div class="float25">



</div>

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



<h3>Cutting a Mesh</h3>

<p>
Iterate over the cutting meshes boundary, adding points and
 applying the constraint along the points faces. Finally 
 subtract the mesh.
</p>

<h3>Constrained Meshes</h3>

<p>
Create the mesh normally. Then apply constraints. Delete
 unwanted meshes generated by the constraint. A constraint
 has no neighbor along the constraint face so the pointer/s
 is/are set to null.

</p>

<h3>Merging Meshes</h3>

<h3>Chain Reaction Shape Deletion</h3>

<p> Delete a shape and all its neighbours.</p>


</div>

<div class="spacer" />


<div class="float25">


</div>

<div class="spacer" />

<div class="float25">
<a id="Convex_Meshes_with_Hull_or_Boundary_Points_Only"></a>
<h2>Convex Meshes with Hull or Boundary Points Only</h2>

<p>
Restricting meshes to convex meshes with all points
 on the boundary, searching
 the mesh is really the  
<a href="g033.xml#Inclusion_in_a_Convex_Polygon">
 Inclusion in a Convex Polygon</a> problem.
 The following diagram demonstrates an inefficient
 linear search.
</p>

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



<p>
Here the inner mesh is a spiral.
  Searching is possibly 
<math xmlns="&mathml;">
  <mi>O</mi>
  <mo>(</mo>
  <mi>log</mi>
  <mi>n</mi>
  <mo>)</mo>
</math>
.
</p>

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

</div>

<div class="float25">

<p> Finally consider a balanced mesh. Again
 the search time is possibly 
<math xmlns="&mathml;">
  <mi>O</mi>
  <mo>(</mo>
  <mi>log</mi>
  <mi>n</mi>
  <mo>)</mo>
</math>,
 I just do not know.
</p>


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

<p>
If the balanced mesh has a log search time then
 its really useful because balanced meshes are
 a natural data structure for other problems.
</p>

<p>
However the algorithm that Shamos gave and its 
 variation that I thought up (probably already known) 
 where you include a center point and order
 the hull points around it is logarithmic and
 adaptable to constant time which these
 meshes that I know of will not achieve .
</p>

</div>

<div class="spacer" />


<div class="float25">
<a id="Splitting_a_Simplex_Generalized"></a>
<h2>Splitting a Simplex Generalized</h2>

<p>
This problem arises in key algorithms.  For example
 <a href="g037.html">Clipping in a Linked Simplex Mesh</a>,
 incremental algorithm for mesh tessellation and subtracting one
 mesh from another.
</p>

<p>
When a new point is added to a mesh it is either added outside the
 mesh or inside.  When it is added inside the mesh one or more existing
 simplexes must be split and the mesh reformed.
</p>

<p>For example in 2D splitting a triangle with a point inside the triangle
 forms three new triangles about the point and the old triangle is deleted,
 and existing links to it must be updated to point to the new triangles
 so that the mesh is logically consistent.
</p>

<p>When a simplex is split it gets deleted and the new simplexes are
 connected.
</p>

<p>After looking in both 2D and 3D and writing a few split operations
 I noticed the following - that the split operations can be categorized
 on the geometric object that they split.  For example in 2D splitting
 inside the triangle is one form of splitting on a plane.  Splitting 
 on the boundary of a triangle is splitting on a line and is a separate 
 operation.
</p>

</div>

<div class="float25">
 
<p>A simplex of n dimensions can be split with a 
 point in n ways corresponding to the simplex and its boundaries.  
 For example in 3D consider the ways a tetrahedron can be split.
 The tetrahedron can be split in 3D space if the
 point is inside the tetrahedron. 
 It can be split on the 2D boundary if the point is on a face.
 It can be split on 1D boundary if the point is on an edge.   
</p>



<p>Let s be an index to the simplex, w be an index to the
 point and s<sub>i</sub> be indexes to the new simplexes generated.
 
 
 s is generally overwritten after the 
 operation and the remaining new simplexes are added by pushing
 them to the back of a simplex stack which I called vi.
</p>

<p class="alg2">
split&lt;n&gt;D splits a space in n dimensions with a point w.
</p>


<p class="alg2">
2D Split Operations <br/>
split2D(s,w) -&gt; s<sub>0</sub> s<sub>1</sub> s<sub>2</sub> <br/>
split1D(s,p<sub>0</sub>,p<sub>1</sub>,w) or
split1D(s,p<sub>2</sub>,w) 
 -&gt; s<sub>0</sub> s<sub>1</sub> or   
  s<sub>0</sub> s<sub>1</sub> s<sub>2</sub> s<sub>3</sub> <br/>
</p>

<p class="alg2">
3D Split Operations<br/>
split3D(s,w) -&gt;  s<sub>0</sub> s<sub>1</sub> s<sub>2</sub> s<sub>3</sub><br/>
split2D(s,p<sub>0</sub>,w) -&gt; s<sub>0</sub> s<sub>1</sub> s<sub>2</sub> or s<sub>0</sub> s<sub>1</sub> s<sub>2</sub> s<sub>3</sub> s<sub>4</sub> s<sub>5</sub> <br/>
split1D(s,p<sub>0</sub>,p<sub>1</sub>,w) -&gt; variable s<sub>i</sub><br/>
</p>

</div>

<div class="spacer" />

<div class="float25">

<p>When splitting on a line the general point w can be identified as
 between two existing points p<sub>0</sub> and p<sub>1</sub>.
 In 2D it can also be identified as opposite another point hence
 <code>split1D</code> in 2D has two options. With similar reasoning 
 a point which splits a face in 3D could be indexed by a single
 point opposite the face or three surrounding points.
</p>

<p>
Splitting a simplex with a point is a fundamental operation for 
 cutting simplexes.
 So I am describing the operations as algorithms.
</p>

<p>The operators are evaluated on the simplex stack and leave
 the stack in a different state afterwards.  By querying the
 stack you can find out which case the operator performed.
</p>

<p>Often algorithms need to query the stack afterwards to find
 out the order of simplexes created.  For examlpe if I know
 both indexes of two newly formed simplexes and I know the possible
 geometries, by querying
 both simplexes you can determine the geometry exactly.
</p>

</div>

<div class="float25">

<p>This means that the order of the operators need not be memorized
 but after the operator has been evaluated then determine the 
 geometry.  Using the operators this way is much easier than
 knowing the operators inner workings and using local indexes.
 So algorithms can be written easier and more reliably, this
 is a significant saving to the client.
</p>  

<p>Splitting on the boundaries is more complicated than splitting
 inside the simplex as a different number of simplexes can be
 formed depending on whether or not the boundary has a neighbor.
</p>

<p> From the operations point of view it is harder to reverse these 
 operations.  For example the split1D operator you would
 have to determine if two adjacent simplexes have a face or boundary that
 is aligned and that together the simplexes form another simplex in the
 same space.
</p>

<p>The consequences of this is that the operator can easily be implemented
 but its inverse can not.  For example consider the numerical instabilities
 caused by roundoff, testing if three points are in the same line could fail.
 Although I am sure other people have studied these issues from my maths
 degree we never looked at such problems.  Please shoot me an email and
 I will do some reading.
</p>

</div>

<div class="float25">

<a id="Cutting_a_Mesh_with_the_Point_Cut"></a>
<h3>Cutting a Mesh with the Point Cut</h3>

<p>
The idea of cutting a mesh can be interpreted as adding points
 to the mesh.  The points are grouped n at a time to cut
 n dimensional space.  In n dimensions the cutter is really a 
 connected mesh of n-1 simplexes.
</p>

<p>This can be achieved by adding points to the mesh and flipping the
 simplexes so that any of the two successive points share a simplex.
</p>


<p>The idea is really much simpler than I just described.
 Consider an example in 2D where a square is being cut
 by a sphere.  The sphere is going to be interpreted as
 a sequence of points.
</p>

<p>&lt;TODO&gt;Link this up.  Is the example done here or
 in clipping.  Where is the description of the line and plane
 cut using the point cut documented.  And where are
 the images documenting the point cut anyway.  ie 
 the generality between two ordered points and comparing 
 it with the more efficient case where the opposite index
 is used and a winding (ordering) is assumed.  Show how
 rather than being exclusive these can both be implemented -
 and give reasons why - namely one is faster than the other and
 secondly that the more general can use the lower level one
 in its implementation anyway!</p>

<ul>

<li>point cut generality in building other operators.</li>

<li>can a general plane cutter be written solely on the
 point cut.  ie handle different cases of white and 
 black.
</li>

<li>Describe how the point cut can be used to get any
 configuration of simplexes with the points it cuts
 based on the order on which the cutting points are
 used to cut the simplex up.
</li>

<li>Comment on cutting a mesh to include 3D where a curve
 is swept through 3D space. This is naturally a quadratic
 problem.
</li>

<li>While the goal is to use linear methods, comment on
 splines and higher order approximations.  The generality
 of implementing it with linear methods is that if they
 work higher order methods can always be used to extend
 the technique.  Also a possible solution to integration
 issues with triangles being larger than the others
 is already solved by having balanced meshes.  If in
 general the triangles are of the same size or rather 
 the largest is of a certain size, reducing the largest
 should get a limiting effect : the more the largest 
 simplex is reduced the greater the accuracy of the model.
 (in a limit sense).
</li>

<li>
Insert the pics and document.
</li>


</ul>


<p>Cutting is a pre stage to clipping where 
 clipping is removing the simplexes on one side of the
  polyline or cut.
</p>

<p>The cutting can also be thought of as an operator.
 This is where the idea of a point cut comes to play.  Consider
 cutting a tetrahedron with a plane.  
</p>



</div>

<div class="spacer" />

<div class="float25">

<a id="Operators_in_2D"></a>
<h3>Operators in 2D</h3>

<p>See 
 <a href="g037.html#Ambiguitiy_Resolution_in_2D">
 Ambiguity Resolution in 2D</a> to see an example of where
 the split1D operator is used.
</p>

<a id="In_2D_Split1D_Operator"></a>
<h4> In 2D Split1D Operator</h4>

<p>
Extract the information from the mesh.  Then build the new simplexes.
 From a functional point of view the client supplies the id of the
 simplex to be split, a local index pointing to a vertex and an index
 to a point which is assumed to exist opposite the vertex on the boundary.
 eg
</p>

<pre>
  // s is the simplex, j is the local index indicating which side 
  //   the point w is on.
  void splitonboundary( uintc s, uintc j, uintc w );
</pre>

<p>
The local index j also governs the order of which simplexes are
 created.  I implemented a clockwise ordering where s will point
 to the first simplex created about the point over riding the previous
 simplex and v.size() (prior to this function being called which would
 alter the stack state) will point to the second simplex.
</p>

<p>Firstly this was a mistake however I have to edit the algorithm
 and redo the documentation - the ordering should be anticlockwise
 so that when ever the client needs to consider orderings the default
 is anticlockwise.&lt;TODO&gt;  Both no neighbor and neighbor have
 to be changed.  Alternatively have two implementations clockwise and
 anticlockwise.
</p>


<p>
The operation itself either growths the number of triangles by 1 or 3,
 depending on whether or not the boundary split has a neighbor as
 2 and 4 triangles are created and 1 triangle deleted.
</p>

<p>If i is the target triangle and the stack size of triangles is n
 then the first two new triangles are indexed at i and n correspond
 to k<sub>0</sub> and k<sub>1</sub>. This guarantees that you know
 where to find the two triangles which partitioned the original triangle.
</p>

<p>This operator performs no minimization as if it did there would be
 no guarantee of the mesh state after the operation.  
</p>

<p>Consider the case where the simplex has no neighbor on the boundary.</p>

<img src="diagg02805.png" alt="diagg02805.png" />
<img src="diagg02806.png" alt="diagg02806.png" />
<img src="diagg02807.png" alt="diagg02807.png" />

</div>

<div class="float25">

<p>Now consider the case where the simplex has a neighbor.</p>

<img src="diagg02808.png" alt="diagg02808.png" />
<img src="diagg02809.png" alt="diagg02809.png" />
<img src="diagg02810.png" alt="diagg02810.png" />

</div>

<div class="spacer" />

<div class="float25">


<a id="Cutting_a_Triangle_with_a_Line"></a>
<h4>Cutting a Triangle with a Line</h4>

<p>Generally when a triangle is cut it is not through one
 of its vertexes but through two points on two different
 sides.
</p>

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

<p>The split1D operator was used to implement this operator. Here
 the diagram shows the process however it is not as simple
 as it looks.  The simplex s' needs to be identified from
 the previous split simplexes.  As the order of how the simplexes
 were produced should not matter then all the new simplexes have
 to be identified to find the s' simplex.
</p>

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

</div>

<div class="float25">

<p>This is one of those times when describing the way s' is found
 is harder than viewing the code so here is the code.
</p>

<pre>
  uintc n0 = vi.size();

  // Neighboring triangle opposite p0
  uintc neib = vi[s].nifrom(p0);

  // If the first splitting point has no neighbor on the given 
  //   boundary then handle this case. 
  if (neib==0)
  {
    split1D(s,p0,w0);
    if ( vi[s].piInverseHas(p1) )
      split1D(n0,w0,w1);
    else
      split1D(s,w0,w1);

    return;
  }

  // The first split will create 4 new triangles and delete two.
  split1D(s,p0,w0);

  //  The second triangle to be split contains the point p0 but
  //    does not contain the point p1 as one of its points.

  uint k[4];
  k[0] = s;
  k[1] = neib;
  k[2] = n0;
  k[3] = n0+1;

  d3tri *t;
  uint ki;
  for ( uint i=0; i&lt;4; ++i )
  {
    ki=k[i];
    t = &amp; vi[ki];
    if ( t-&gt;piInverseHas(p1) == true )
      continue;
    if ( t-&gt;piInverseHas(p0) == false )
      continue;

    split1D(ki,w0,w1);

    return;
  }
</pre>

<p>
The new simplexes are added to the end of the simplex stack and
 overwrite the simplex itself and any neighbors on the boundary of
 the split.  So while the operation may produce a variable number
 of simplexes these can be iterated over by other clients using
 this operator for further processing. For example mesh clipping
 uses this to cull simplexes after the mesh has been cut.
</p>



</div>

<div class="spacer" />

<div class="float25">

<a id="Operators_in_3D"></a>
<h3>Operators in 3D</h3>

<a id="In_3D_Split1D_Operator"></a>
<h4>In 3D Split1D Operator</h4>

<p>Two of the tetrahedrons points are used to identify the edge of 
 the point where the tetrahedron is being split.  The number of tetrahedrons 
 which are created and deleted is variable as all the tetrahedrons
 sharing the axis must be split too.  For a balanced mesh this is finite or
 constant in complexity
 but for an unbalanced mesh this is not the case.
</p>

<p>So the problem is broken down into two parts.  Rotate around the
 axis finding which simplexes are to be split and splitting each in two,
 and re connecting with their neighbors.
</p> 





</div>

<div class="spacer" />


<div class="float25">
<a id="Collision_Detection_between_Convex_Tessellations"></a>
<h2>Collision Detection between Convex Tessellations</h2>

<p>Collision detection is a huge topic, perhaps the most popular.
  I am interested in how the linked data structure both performs
 with collision detection.  From an algorithmic point of
 view it is exciting because there are many tools to use build 
 the algorithms.
</p>


<a id="Minimize_Towards_Points"></a>
<h3>Minimize Towards Points</h3>

<p>
 I am going to introduce a collision detection
 algorithm in theory and will later implement.  I believe it to
 be efficient.
</p>

<p>The meshes are assumed to be balanced. </p>

<p>Essentially the state of object A is minimized to some point in object B
 and vice versa.</p>


<p class="alg1">
Let A and B be two convex tessellations.<br/>
Let A.cp<sub>i</sub> and B.cp<sub>i</sub> be successive
 values recording the movement of the cp of A and B respectively.<br/>
Define this sequence as an ordered pair &lt; A.cp<sub>i</sub>, B.cp<sub>i</sub> &gt; .
</p>

<p class="alg1">
bool collisiondetection(A,B)
</p>

<p class="alg2">
repeat <br/>
 &nbsp; &nbsp; 
    if ( A.searchminimizetowardspoint( vi[ B.cp ].pi[0] ) ) <br/>
 &nbsp; &nbsp; &nbsp; &nbsp; 
      return true <br/>

 &nbsp; &nbsp; 
    if ( B.searchminimizetowardspoint( vi[ A.cp ].pi[0] ) ) <br/>
 &nbsp; &nbsp; &nbsp; &nbsp; 
      return true <br/>

 &nbsp; &nbsp; 
    if ( &lt; A.cp<sub>i</sub>, B.cp<sub>i</sub> &gt; is cyclic ) <br/>
 &nbsp; &nbsp; &nbsp; &nbsp; 
      return false <br/>
</p>

<p class="alg1">
The algorithm returns true if a collision occurs.  The algorithm returns
 false if there is no collision.
</p>

<p>There are some possible variations.  For example a counter could be used inside the loop
 that if it is reached tests for the cyclic situation.  Another could be to minimize one move at
 a time and alternate.  Another is to restrict the direction of movement so that only forward
 moves are possible and use this with alternating one move at a time. This is interesting
 for a few reasons. Does does it always work? The idea is to guarantee non-cyclic movement.
</p> 

<p>
Alternatively algorithms are possible.  For example minimizing the points to the each others boundaries
 and then use surface transversal to determine if they intersect or not.  This is related to
 merging convex hulls.
</p>

</div>

<div class="float25">

<a id="Finding_the_Axis_of_Separation"></a>

<h3>Finding the Axis of Separation</h3>

<p>This is a traditional problem. That is its processing
 is points orientated.  Find a half space such that
 all the points of one object are visible to the
 half space of the other object.
</p>

<p>There is some theorem which states that this must always
 be true for two convex objects that do not intersect.
 So I will assume you like me know the theorem because
 I do not wish to prove it - everybody else has so why
 bother? (actually if I am incorrect then this is not
 a result of not proving the theorem but of not reading the
 literature properly)
</p>

<p>The point is that if two objects fail to find this
 axis of separation or more correctly find the half
 space that can see the other object then
 the two objects are intersecting.
</p>

<p>While this is a vanilla flavored algorithm
 it is interesting because its embedded in other
 algorithms.  For example divide and conquer for
 tessellation.
</p>


<p>The other interest is that the algorithm uses
 surface transversal to move the half space which
 points away from its base.
</p>


</div>

<div class="float25">

<p class="alg1">
Let A.H<sub>i</sub> be a half space on the surface of A. <br/>
Let B.H<sub>k</sub> be a half space on the surface of B. <br/>
Let A.p<sub>j</sub> be a point of A.<br/>
Let B.p<sub>l</sub> be a point of B.<br/>
Let A have q sides and points. <br/>
Let B have r sides and points.
</p>


<p class="alg1">
<code>
bool intersect(A,B)<br/>
 &nbsp; &nbsp; 
  for i = 0..q-1 <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
    flag = true<br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
    k = 0 <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
    while ((k&lt;r) &amp;&amp; flag) <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
      if ( A.H<sub>i</sub> . B.p<sub>k</sub>  &lt; 0 ) <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
        flag = false <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
    if (flag) <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
      return false<br/>

<br/>

 &nbsp; &nbsp; 
  for i = 0..r-1 <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
    flag = true<br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
    k = 0 <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
    while ((k&lt;q) &amp;&amp; flag) <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
      if ( B.H<sub>i</sub> . A.p<sub>k</sub>  &lt; 0 ) <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
        flag = false <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
    if (flag) <br/>
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
      return false<br/>
    

 &nbsp; &nbsp; 
  return true

</code>
</p>

</div>

<div class="float25">

<p>Here are some separation examples. </p>

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

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

</div>

<div class="float25">

<p> As an aside consider how competitive bounded simplexes could be.
 While bounded boxes are recalculated and as the coordinate
 system is Cartesian and uses boxes this is efficient,
 but can using half spaces be made efficient too.
</p>

<p>For example if the half space is initially calculated, then
 the half space goes through the same transformation as the
 object itself so does not need to be re-calculated only
 transformed. 
</p>

<p>For collision between tets there are 4 half spaces against 
 four points so an ideal collision detection is 8 dot product
 tests. For no collision in the worst case 31 dot products.
 Plus there is a transform before the dot product. There probably
 is an average on a guess of 20 dot products.
</p>

<p>So perhaps using bounded simplexes for the first 
 stage of collision detection can be efficient.
 Consider two robots with 100 point meshes . Having 
 their bounding boxes calculated together is say 200 operations.
 I am only guessing but it looks like the bounded tets wins.
 &lt;TODO&gt; implement and test.
</p>




</div>

<div class="spacer" />


<div class="float25">

<a id="All_Viewable_Points"></a>
<h3>All Viewable Points</h3>

<p>I have no idea what the actual name of this algorithm is
 because I made it up.  Of course someone has already done this
 but I do not know where.
</p>

<p>Where separating on the axis looks for one boundary half space  
 this algorithm iterates over the boundary until all of the
 other objects points are visible or there is no more boundary
 to iterate over. If this happens then the two objects intersect
 because one object can not see all the points of the other hence they
 must be in the interior which by definition is a collision.
</p>

<p>If all the points of one object are visible to another, the test is 
 swapped around and the other object asks if it can see the others
 points.
</p>

<p>If both can see all of each others points then there is no collision.
</p>

<p>Here is a counter example showing why it is not enough that one object can see
 all the points of the other object and collision still occurs.
</p>

</div>

<div class="float25">

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

<p>Here is when there is no collision because each object can
 see the others points.
</p>

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

<div class="spacer" />

<div class="float25">
<a id="Visible_Surface_Generation"></a>
<h2>Visible Surface Generation</h2>

<p><a href="g029.xml#Visible_Surface_Generation">BSP trees</a>
 solve the visible surface problem by tessellating and iterating.
 Linked simplexes can also be used to solve the visible surface problem
 for static geometry.
</p>

<a id="Convex_Simplex_Mesh"></a>
<h3>Convex Simplex Mesh</h3>

<p>This is the simplest case.  Here the geometry is convex.
 The viewers position is found by minimizing to the nearest simplex.
 Then the simplex is iterated from the simplex. 
</p>

<p class="alg1">
Let dead be a list of processed simplexes.<br/>

Let dv be a deque list of simplexes being processed.<br/>
 &nbsp; &nbsp; Deques have the property of being able to be both
 inserted and deleted at both ends.<br/>
Let w be the list of ordered simplexes.<br/>
Let u be the initial simplex minimized to the viewers position.<br/>
Let dim be the simplex dimension
</p>

<p class="alg1">
Push u on to dv<br/>
while dv is not empty<br/>
  &nbsp; &nbsp; 
  x = the first simplex of dv<br/>
  &nbsp; &nbsp; 

    if (x in dead)<br/>
      &nbsp; &nbsp; &nbsp; &nbsp; 
      Pop/delete the first simplex of dv.<br/>
      &nbsp; &nbsp; &nbsp; &nbsp; 
      continue<br/>


  &nbsp; &nbsp; 
  for i=0..dim-1<br/>
    &nbsp; &nbsp; &nbsp; &nbsp; 
    if (x.ni[i] in dead)<br/>
      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
      Pop/delete the first simplex of dv.<br/>
      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
      continue<br/>
    &nbsp; &nbsp; &nbsp; &nbsp; 
    Insert x.ni[i] at the end of dv<br/>
  &nbsp; &nbsp; 
  Push and insert x into w and dead.<br/>
  &nbsp; &nbsp; 
  Pop/delete the first simplex of dv.<br/>
<br/>
Iterate over w in the reverse order drawing
 the simplexes. 
</p>

<p>Viewing volumes can be implemented with clipping half spaces
 so a simplex could be tested to be on the correct side of the 
 half space - if it is not it is added to the dead list.
 Since the simplexes are connected adding a simplex on the boundary
 to the dead list stops simplexes outside the boundary from being
 iterated over and therefor culls the simplexes.
</p>

</div>

<div class="float25">

<a id="Separate_Graphics_Objects"></a>
<h3>Separate Graphics Objects</h3>

<p>
When all the graphics objects are separate -
 and do not intersect each other then a mesh
 can be made where each point is representative
 of the geometric object in space.  ie find the
 centroid of the geometric object and use this
 as a representative point for the geometric 
 object.
</p>

<p>
Build a convex mesh with these representative
 points. Have a function that given the point
 the associated graphics object can be found.
</p>

<p>Minimize to the simplex the viewers position.
</p>

<p class="alg1">
Iterate around the simplex in a similar way
 to the convex simplex case but this time
 push the points and not the simplexes to w.
</p>

<p>
This algorithm is completely general.  
</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
</li>

</ol>


</div>





</body>
</html>



