package { //Credit to Paul Bourke (pbourke@swin.edu.au) for the original Fortran 77 Program :)) //Converted to a standalone C# 2.0 library by Morten Nielsen (www.iter.dk) //Check out: http://astronomy.swin.edu.au/~pbourke/terrain/triangulate/ //You can use this code however you like providing the above credits remain in tact /** * @author nicoptere * http://en.nicoptere.net/ */ import Point; public class Triangle { //points of the triangle public var p1:Point; public var p2:Point; public var p3:Point; //gravity center public var center:Point; //middle of the sides public var mid0:Point;//p0 > p1 public var mid1:Point;//p1 > p2 public var mid2:Point;//p2 > p0 public function Triangle( p1:Point, p2:Point, p3:Point ) { this.p1 = p1; this.p2 = p2; this.p3 = p3; } /** * retrieves the gravity center of the triangle */ public function getCenter():void { if( center == null ) center = new Point( 0,0 ); center.x = ( p1.x + p2.x + p3.x ) / 3; center.y = ( p1.y + p2.y + p3.y ) / 3; } /** * retrieves the midPoint of the triangle's sides. might be useful in some cases */ public function getSidesCenters():void { if( mid0 == null || mid1 == null || mid2 == null ) { mid0 = new Point( 0, 0 ); mid1 = new Point( 0, 0 ); mid2 = new Point( 0, 0 ); } mid0.x = p1.x + ( p2.x - p1.x )/2; mid0.y = p1.y + ( p2.y - p1.y )/2; mid1.x = p2.x + ( p3.x - p2.x )/2; mid1.y = p2.y + ( p3.y - p2.y )/2; mid2.x = p3.x + ( p1.x - p3.x )/2; mid2.y = p3.y + ( p1.y - p3.y )/2; } } }