//This file is part of SECONDO. //Copyright (C) 2004, University in Hagen, Department of Computer Science, //Database Systems for New Applications. //SECONDO is free software; you can redistribute it and/or modify //it under the terms of the GNU General Public License as published by //the Free Software Foundation; either version 2 of the License, or //(at your option) any later version. //SECONDO is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU General Public License for more details. //You should have received a copy of the GNU General Public License //along with SECONDO; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package fuzzyobjects.basic; import fuzzyobjects.*; import java.util.Vector; /** * this class privides a BasicTriangle of the X-triangulation * @author Thomas Behr */ public class BasicTriangle implements BasicObject{ /** * creates a new basicTriangle from the given points * no check whether this is a valid triangle * @param CP_? a cornerpoint of the new Triangle */ public BasicTriangle(BasicPoint CP_1, BasicPoint CP_2, BasicPoint CP_3) { BasicPoint[] BPs = new BasicPoint[3]; BPs[0] = CP_1; BPs[1] = CP_2; BPs[2] = CP_3; BasicPoint.sort(BPs); this.CP_1 = BPs[0]; this.CP_2 = BPs[1]; this.CP_3 = BPs[2]; } /** * returns a copy of this * @return a new BasicTriangle on the same location as this */ public BasicTriangle copy(){ return new BasicTriangle( CP_1.copy(), CP_2.copy(), CP_3.copy()); } /** * check whether this is equal to BT * @param BT the another Triangle * @return true if BT is on the same location as this */ public boolean equals(BasicTriangle BT) { return ( CP_1.equals(BT.CP_1)) && ( CP_2.equals(BT.CP_2)) && ( CP_3.equals(BT.CP_3)); } /** * returns a readable form of this triangle * @return a String representing this triangle */ public String toString(){ return " BT : ( "+CP_1+","+CP_2+","+CP_3+")"; } /** * check whether this is a Triangle of the X-Triangulation * @return true if all cornerpoints are valid and connected */ public boolean isValid(){ boolean ok = CP_1.isValid() && CP_2.isValid() && CP_3.isValid(); if(ok) { ok = CP_1.neightbooring(CP_2) && CP_1.neightbooring(CP_3) && CP_2.neightbooring(CP_3); } return ok; } /** * returns the 3 cornerpoints in a array * @return a array containing the 3 cornerpoints */ public BasicPoint[] getBasicPoints(){ BasicPoint[] BPs = new BasicPoint[3]; BPs[0] = CP_1.copy(); BPs[1] = CP_2.copy(); BPs[2] = CP_3.copy(); return BPs; } /** * computes the number of common points * @param BO the another BasicObject * @return number of common BasicPoints */ private int commonPoints(BasicObject BO) { int n = 0; BasicPoint[] BPs = BO.getBasicPoints(); for (int i=0;i *
  • -1 if O not a BasicTriangle or this is smaller then O
  • *
  • 0 id O equals to this
  • *
  • 1 if 0 is a BasicTriangle and this is greater * then O
  • * */ public int compareTo(BasicObject O){ if(!(O instanceof BasicTriangle)) return -1; else { BasicTriangle BT = (BasicTriangle) O; int C = CP_1.compareTo(BT.CP_1); if (C==0) C = CP_2.compareTo(BT.CP_2); if (C==0) C = CP_3.compareTo(BT.CP_3); return C; } // else } // compareTo /** * returns a Cornerpoint of this * @return the smallest cornerpoint of this */ public BasicPoint getCP1(){ return CP_1; } /** * returns a Cornerpoint of this * @returns the middle cornerpoint of this */ public BasicPoint getCP2(){ return CP_2; } /** * returns a cornerpoint of this * @return the greatest cornerpoint of this */ public BasicPoint getCP3(){ return CP_3; } /* returns the 3 BasicTriangles which have a * common Side with this */ public BasicTriangle[] getRealNeightboors(){ BasicSegment[] Sides = new BasicSegment[3]; Sides[0] = new BasicSegment(CP_1,CP_2); Sides[1] = new BasicSegment(CP_2,CP_3); Sides[2] = new BasicSegment(CP_1,CP_3); BasicTriangle[] result = new BasicTriangle[3]; BasicTriangle[] BTs; for(int i=0;i<3;i++){ BTs = Sides[i].getTriangles(); if(BTs[0].equals(this)) result[i] = BTs[1]; else result[i] = BTs[0]; } return result; } /** * computes all (simple) connected Triangles * @return all Triangles having 1 or 2 common * BasicPoints whith this */ public BasicTriangle[] getNeightboors(){ Vector Tmp = new Vector(); BasicPoint[] NB1 = CP_1.getNeightboors(); BasicPoint[] NB2 = CP_2.getNeightboors(); BasicPoint[] NB3 = CP_3.getNeightboors(); for(int i=0;i0){ for(int i=0;i (b/a) ) { // left-top cases 1 and 2 if( b/a > (b-y)/x ){ // case 1 tmp.add( new BasicTriangle( new BasicPoint(xC+Aint/2,yC+Bint/2), new BasicPoint(xC+Aint,yC+Bint), new BasicPoint(xC,yC+Bint))); } else { // case 2 tmp.add( new BasicTriangle( new BasicPoint(xC,yC+Bint), new BasicPoint(xC+Aint/2,yC+Bint/2), new BasicPoint(xC,yC))); } } else{ // right-bottom cases 3 and 4 if( b/a > (b-y)/x ) { // case 4 tmp.add( new BasicTriangle( new BasicPoint(xC+Aint/2,yC+Bint/2), new BasicPoint(xC+Aint,yC+Bint), new BasicPoint(xC+Aint,yC) )); } else{ // case 3 tmp.add(new BasicTriangle( new BasicPoint(xC,yC), new BasicPoint(xC+Aint/2,yC+Bint/2), new BasicPoint(xC+Aint,yC))); } } } BasicTriangle[] result = new BasicTriangle[tmp.size()]; for(int l=0;l