import java.awt.*; import java.awt.event.*; import java.util.*; public class Dtriangle implements java.io.Serializable{ InsertionP p1; InsertionP p2; InsertionP p3; Vedge vedge; DoubleVector circum; double radius; public Dtriangle(Vedge e1, Vedge e2, Vedge e3){ Update(e1,e2,e3); } public Dtriangle(Vector edges, Vedge e[]){ Update(e[0],e[1],e[2]); for(int tn=0;tn<3;tn++) edges.addElement(e[tn]); } public Dtriangle(Vector edges, Vedge e1, Vedge e2, Vedge e3){ Update(e1,e2,e3); edges.addElement(e1); edges.addElement(e2); edges.addElement(e3); } public void Update(Vedge e1, Vedge e2, Vedge e3){ vedge = e1; e1.enext = e2; e2.enext = e3; e3.enext = e1; e1.tri = this; e2.tri = this; e3.tri = this; p1 = vedge.p1; p2 = vedge.p2; p3 = next(vedge).p2; this.setCircumCircle(); } public boolean inCircumCircle(InsertionP ds){ if(ds.Distance(circum.x,circum.y) < radius){ return true; }else{ return false; } } public void RemoveEdges(Vector edges){ edges.removeElement(vedge); edges.removeElement(next(vedge)); edges.removeElement(next(next(vedge))); } private void setCircumCircle(){ /* see http://mathworld.wolfram.com/Circumcircle.html */ double a = (p2.y-p3.y)*(p2.x-p1.x)-(p2.y-p1.y)*(p2.x-p3.x); double dd = (p1.x+p2.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p1.y+p2.y); double df = (p2.x+p3.x)*(p2.x-p3.x)+(p2.y-p3.y)*(p2.y+p3.y); circum = new DoubleVector(0.0,0.0); if(a==0.0){ circum.x = 0.0; circum.y = 0.0; radius = 0.0; System.out.println("Error !! in setCircumCircle"); } circum.x = ((dd*(p2.y-p3.y)-df*(p2.y-p1.y))/a/2.0); circum.y = ((df*(p2.x-p1.x)-dd*(p2.x-p3.x))/a/2.0); radius = (vedge.p1).Distance(circum.x,circum.y); } private Vedge next(Vedge dv){ return (dv.enext); } }