Triangle::Triangle(Vertice & a, Vertice & b, Vertice & c) { //criar um triangulo pelos vertices, cria de 3 novas edges e0 = new Edge(a,b); e1 = new Edge(b,c); e2 = new Edge(c,a); setCircumCircle(); m_Centroid.x = (a.x + b.x + c.x) / 3; m_Centroid.y = (a.y + b.y + c.y) / 3; }
Triangle::Triangle(Edge & e, Vertice & a) { //criar um triangulo apartir de uma edge e um vertice, atualiza o vertice passado e cria 2 novos Vertice b = e.getV0(); Vertice c = e.getV1(); TriangleList stub; this->e0 = &e; this->e1 = new Edge(c,a); this->e2 = new Edge(a,b); setCircumCircle(); m_Centroid.x = (a.x + b.x + c.x) / 3; m_Centroid.y = (a.y + b.y + c.y) / 3; }
Triangle::Triangle(Edge & _e0, Edge & _e1, Edge & _e2) { //criar um triangulo apartir das edges a funcao pai deve chamar o setAdjancency //normalmente as edges jah vao conter triangulos setados this->e0 = &_e0; this->e1 = &_e1; this->e2 = &_e2; setCircumCircle(); Vertice a = Edge::CommonVertice(*this->e2,*this->e0); //CA AB Vertice b = Edge::CommonVertice(*this->e0,*this->e1); //AB BC Vertice c = Edge::CommonVertice(*this->e1,*this->e2); //BC CA m_Centroid.x = (a.x + b.x + c.x) / 3; m_Centroid.y = (a.y + b.y + c.y) / 3; }
void DelaunayTriangle :: computeCircumcircle() { double x1, x2, x3; double y1, y2, y3; double a, bx, by, c; DofManager *dmanA, *dmanB, *dmanC; dmanA = domain->giveDofManager( giveNode(1) ); x1 = dmanA->giveCoordinate(1); y1 = dmanA->giveCoordinate(2); dmanB = domain->giveDofManager( giveNode(2) ); x2 = dmanB->giveCoordinate(1); y2 = dmanB->giveCoordinate(2); dmanC = domain->giveDofManager( giveNode(3) ); x3 = dmanC->giveCoordinate(1); y3 = dmanC->giveCoordinate(2); a = x1 * y2 + y1 * x3 + x2 * y3 - 1.0 * ( x1 * y3 + y1 * x2 + y2 * x3 ); bx = -1.0 * ( ( ( x1 * x1 + y1 * y1 ) * y2 + y1 * ( x3 * x3 + y3 * y3 ) + ( x2 * x2 + y2 * y2 ) * y3 ) - 1.0 * ( ( x1 * x1 + y1 * y1 ) * y3 + y1 * ( x2 * x2 + y2 * y2 ) + y2 * ( x3 * x3 + y3 * y3 ) ) ); by = ( ( ( x1 * x1 + y1 * y1 ) * x2 + x1 * ( x3 * x3 + y3 * y3 ) + ( x2 * x2 + y2 * y2 ) * x3 ) - 1.0 * ( ( x1 * x1 + y1 * y1 ) * x3 + x1 * ( x2 * x2 + y2 * y2 ) + x2 * ( x3 * x3 + y3 * y3 ) ) ); c = ( ( ( x1 * x1 + y1 * y1 ) * x2 * y3 + x1 * y2 * ( x3 * x3 + y3 * y3 ) + y1 * ( x2 * x2 + y2 * y2 ) * x3 ) - 1.0 * ( ( x1 * x1 + y1 * y1 ) * y2 * x3 + x1 * ( x2 * x2 + y2 * y2 ) * y3 + y1 * x2 * ( x3 * x3 + y3 * y3 ) ) ); double xCenterCoordinate = ( -1.0 * bx / ( 2 * a ) ); double yCenterCoordinate = ( -1.0 * by / ( 2 * a ) ); double absA = a < 0 ? -1.0 * a : a; double radius = ( ( sqrt(bx * bx + by * by + 4.0 * a * c) ) / ( 2.0 * absA ) ); setCircumCircle(xCenterCoordinate, yCenterCoordinate, radius); }