Tom Higgins (as of September 5, 2006 I no longer work at Adobe)
Product Manager
Director and the Shockwave Player
 
     
 

poppy.thiggins / articles / finding a triangle's incenter

Finding a Triangle's Incenter
While developing Director content it may at times be useful to determine the "center" of three coordinates in space (2D or 3D). Given that any three points in space can be used to define a triangle we can then rely on standard geometric equations in order to determine precisely where the triangle's center is located. The trouble here is that there are a few ways in which one can define where the center of a triangle should be found, in this case I'm going to focus on determining the position of the traingle's "incenter" in particular . For a definition of "incenter" and some extra background on this point within a triangle, please view the following URL (or go deeper by searching on the web as there are many sources for this type of information):

http://faculty.evansville.edu/ck6/tcenters/class/incenter.html

For information on the equation needed to determine the incenter's location given three points in space (the three vertices of the triangle) then please view the following (or again, do a web search for more information like the proof steps involved in deriving the equation):

http://www.ilovemaths.com/3centroid.htm

Worth noting is that the above page only shows the needed equation while considering triangles within a plane (only using x and y coordinates), it is rather simple to extend the equation into three dimensions. Using the notation found on the page above, the location of the incenter can be determined as follows (assume the vector I is the position of the triangle's incenter):

Ix = ( (a * Ax) + (b * Bx) + (c * Cx) ) / ( a + b + c )
Iy = ( (a * Ay) + (b * By) + (c * Cy) ) / ( a + b + c )
Iz = ( (a * Az) + (b * Bz) + (c * Cz) ) / ( a + b + c )

 

Demo
Below you will see a simple demonstration file in which I use a simple mesh primitive to create a two-sided, flat triangle model of random dimensions. Then I use the incenter equations to determine the incenter position for that triangle and at the location I place a simple red sphere model. Click anywhere on the 3D sprite and it will generate a new triangle at random and place the sphere at the new triangle's incenter. Please also realize that the red ball stays in place while the triangle rotates by calculating the incenter position each frame, thus hoping to show that while the triangle starts by being in the x-y plane that's not in any way a limitation so much as a starting point for simplicity.

 

 

Downloads
IncenterDemo.dir (~21Kb)

 
     
 
24.May.2005