?? polyhedralboundedsolidsetoperator.java
字號:
middle.normalize(); return middle; } /** Following program [MANT1988].15.8. */ private static ArrayList<_PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex> nbrpreproc(_PolyhedralBoundedSolidVertex v) { _PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex n, nold; Vector3D bisec; _PolyhedralBoundedSolidHalfEdge he; ArrayList<_PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex> nb; nb = new ArrayList<_PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex>(); he = v.emanatingHalfEdge; Vector3D oldref2; do { n = new _PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex(); n.he = he; n.wide = false; n.ref1 = he.previous().startingVertex.position.substract( he.startingVertex.position); n.ref2 = he.next().startingVertex.position.substract( he.startingVertex.position); n.ref12 = n.ref1.crossProduct(n.ref2); if ( (n.ref12.length() < VSDK.EPSILON) || (n.ref12.dotProduct(he.parentLoop.parentFace.containingPlane.getNormal()) > 0.0 ) ) { // Inside this conditional means: current vertex is a wide one if ( (n.ref12.length() < VSDK.EPSILON) ) { bisec = inside(he); } else { bisec = n.ref1.add(n.ref2); bisec = bisec.multiply(-1); } oldref2 = n.ref2; n.ref2 = bisec; n.ref12 = n.ref1.crossProduct(n.ref2); nold = n; nb.add(n); n = new _PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex(); n.he = he; n.ref2 = oldref2; n.ref1 = bisec; n.ref12 = n.ref1.crossProduct(n.ref2); n.wide = true; } nb.add(n); he = (he.mirrorHalfEdge()).next(); } while( he != v.emanatingHalfEdge ); return nb; } private static double angleFromVectors(Vector3D u, Vector3D v, Vector3D a) { double x, y; double an; x = a.dotProduct(u); y = a.dotProduct(v); an = Math.acos(x); if ( y < 0 ) an *= -1; return an; } /** Given two coplanar sectors that share a common edge, this method determine if the sectors are edge neighbors (this case returs false) or overlaping sectors (this case returns true). */ private static boolean sectorOverSector( _PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex na, _PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex nb, Vector3D commonEdge ) { Vector3D boundingEdgeA = null; Vector3D boundingEdgeB = null; if ( colinearVectorsWithDirection(na.ref1, commonEdge) ) { boundingEdgeA = na.ref2; } else { boundingEdgeA = na.ref1; } if ( colinearVectorsWithDirection(nb.ref1, commonEdge) ) { boundingEdgeB = nb.ref2; } else { boundingEdgeB = nb.ref1; } if ( colinearVectorsWithDirection(boundingEdgeA, boundingEdgeB) ) { return true; } return false; } /** Checks if two coplanar sectors overlaps, by doing a "sector within" test for coplanar sectors: If the two given sectors are coplanar and with overlaping faces: - If sectors only intersects in one point returns false. - If sectors intersects on a line or area returns true. Following section [MANT1988].15.6.2. Note that this operation is not elaborated on [MANT1988], but left as an excercise. PRE: Given sectors are "coplanar". */ private static boolean sectoroverlap( _PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex na, _PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex nb) { //- Convert side vectors of sectors into angles ------------------- double a1, a2; double b1, b2; Vector3D u, v, a, b, c, n; n = na.he.parentLoop.parentFace.containingPlane.getNormal(); u = new Vector3D(na.ref1); u.normalize(); v = n.crossProduct(u); v.normalize(); a = new Vector3D(na.ref2); a.normalize(); b = new Vector3D(nb.ref1); b.normalize(); c = new Vector3D(nb.ref2); c.normalize(); a1 = angleFromVectors(u, v, u); a2 = angleFromVectors(u, v, a); b1 = angleFromVectors(u, v, b); b2 = angleFromVectors(u, v, c); //- Order the angles in ascending order angle intervals ----------- // Given angles are between -180 and 180 degrees double t; if ( a1 > a2 ) { t = a1; a1 = a2; a2 = t; } if ( b1 > b2 ) { t = b1; b1 = b2; b2 = t; } //- Calculate interval intersection ------------------------------- if ( a2 + VSDK.EPSILON > b1 - VSDK.EPSILON ) { if ( (debugFlags & DEBUG_04_VERTEXVERTEXCLASIFFIER) != 0 ) { System.out.print(" <TRUE>"); } return true; } if ( (debugFlags & DEBUG_04_VERTEXVERTEXCLASIFFIER) != 0 ) { System.out.print(" <FALSE>"); } return false; } /** Following program [MANT1988].15.9. According to the sector intersection test from section [MANT1988].15.6.2, the variables (with respect to the central vertex on a given sector) are: - dir is the vector from the starting vertex of the sector, pointing on the direction of the intersection line with another sector, or `int` in figure [MANT1988].15.8. and equation [MANT1988].15.5. - ref1 and ref2 are the same as in figure [MANT1988].15.8. and equation [MANT1988].15.5. - ref12 is the cross product of ref1 and ref2, or `ref` in figure [MANT1988].15.8. and equation [MANT1988].15.5. - c1 is the cross product of ref1 and dir, or `test1` in figure [MANT1988].15.8. and equation [MANT1988].15.5. - c2 is the cross product of dir and ref2, or `test2` in figure [MANT1988].15.8. and equation [MANT1988].15.5. */ private static boolean sctrwitthin(Vector3D dir, Vector3D ref1, Vector3D ref2, Vector3D ref12) { Vector3D c1, c2; int t1, t2; c1 = dir.crossProduct(ref1); if ( c1.length() < VSDK.EPSILON ) { return (ref1.dotProduct(dir) > 0.0); } c2 = ref2.crossProduct(dir); if ( c2.length() < VSDK.EPSILON ) { return (ref2.dotProduct(dir) > 0.0); } t1 = PolyhedralBoundedSolid.compareValue(c1.dotProduct(ref12), 0.0, VSDK.EPSILON); t2 = PolyhedralBoundedSolid.compareValue(c2.dotProduct(ref12), 0.0, VSDK.EPSILON); return ( t1 < 0.0 && t2 < 0.0 ); } private static boolean sctrwitthinProper(Vector3D dir, Vector3D ref1, Vector3D ref2, Vector3D ref12) { if ( colinearVectors(dir, ref1) || colinearVectors(dir, ref2) ) { return false; } return sctrwitthin(dir, ref1, ref2, ref12); } /** Sector intersection test. Following program [MANT1988].15.9. and section [MANT1988].15.6.2. */ private static boolean vertexVertexSectorIntersectionTest(int i, int j) { //----------------------------------------------------------------- _PolyhedralBoundedSolidHalfEdge h1, h2; boolean c1, c2; _PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex na, nb; na = nba.get(i); nb = nbb.get(j); h1 = na.he; h2 = nb.he; //----------------------------------------------------------------- // Here, n1 and n2 are the plane normals for containing faces of // sectors i and j, as in figure [MANT1988].15.7. Vector3D n1, n2; Vector3D intrs; n1 = h1.parentLoop.parentFace.containingPlane.getNormal(); n2 = h2.parentLoop.parentFace.containingPlane.getNormal(); intrs = n1.crossProduct(n2); //----------------------------------------------------------------- if ( intrs.length() < VSDK.EPSILON ) { if ( (debugFlags & DEBUG_04_VERTEXVERTEXCLASIFFIER) != 0 ) { System.out.print(" <coplanar>"); } return sectoroverlap(na, nb); } //----------------------------------------------------------------- c1 = sctrwitthin(intrs, na.ref1, na.ref2, na.ref12); c2 = sctrwitthin(intrs, nb.ref1, nb.ref2, nb.ref12); if ( c1 && c2 ) { if ( (debugFlags & DEBUG_04_VERTEXVERTEXCLASIFFIER) != 0 ) { System.out.print(" <TRUE>"); } return true; } else { intrs = intrs.multiply(-1); c1 = sctrwitthin(intrs, na.ref1, na.ref2, na.ref12); c2 = sctrwitthin(intrs, nb.ref1, nb.ref2, nb.ref12); if ( c1 && c2 ) { if ( (debugFlags & DEBUG_04_VERTEXVERTEXCLASIFFIER) != 0 ) { System.out.print(" <TRUE>"); } return true; } } if ( (debugFlags & DEBUG_04_VERTEXVERTEXCLASIFFIER) != 0 ) { System.out.print(" <FALSE>"); } return false; } /** Given a pair of coincident vertices `va` (on solid A) and `vb` (on solid B), this method creates the lists `nba`, `nbb` and `sectors`, as explained in section [MANT1988].15.6.2. and program [MANT1988].15.7. Note that from all possible sector pairs, this method does not include in the `sectors` set any sector pair that touches just in one point. */ private static void vertexVertexGetNeighborhood( _PolyhedralBoundedSolidVertex va, _PolyhedralBoundedSolidVertex vb) { //----------------------------------------------------------------- int i; nba = nbrpreproc(va); nbb = nbrpreproc(vb); sectors = new ArrayList<_PolyhedralBoundedSolidSetOperatorSectorClassificationOnSector>(); if ( (debugFlags & DEBUG_04_VERTEXVERTEXCLASIFFIER) != 0 ) { System.out.println(" - NBA list of neighbor sectors for vertex on {A}:"); for ( i = 0; i < nba.size(); i++ ) { System.out.println(" . A[" + (i+1) + "]: " + nba.get(i)); } System.out.println(" - NBB list of neighbor sectors for vertex on {B}:"); for ( i = 0; i < nbb.size(); i++ ) { System.out.println(" . B[" + (i+1) + "]: " + nbb.get(i)); } } //----------------------------------------------------------------- _PolyhedralBoundedSolidHalfEdge ha, hb; double d1, d2, d3, d4; int j; _PolyhedralBoundedSolidSetOperatorSectorClassificationOnSector s; Vector3D na, nb; _PolyhedralBoundedSolidSetOperatorSectorClassificationOnVertex xa, xb; if ( (debugFlags & DEBUG_04_VERTEXVERTEXCLASIFFIER) != 0 ) { System.out.println(" - Initial intersection tests between sectors (false intersections are sectors touching on a single point):"); } for ( i = 0; i < nba.size(); i++ ) { for ( j = 0; j < nbb.size(); j++ ) { if ( (debugFlags & DEBUG_04_VERTEXVERTEXCLASIFFIER) != 0 ) { System.out.print(" . A[" + (i+1) + "] / B[" + (j+1) + "]:"); } if ( vertexVertexSectorIntersectionTest(i, j) ) { s = new _PolyhedralBoundedSolidSetOperatorSectorClassificationOnSector(); s.secta = i; s.sectb = j; xa = nba.get(i); xb = nbb.get(j); s.hea = xa.he; s.heb = xb.he; s.wa = xa.wide; s.wb = xb.wide; na = xa.he.parentLoop.parentFace.containingPlane.getNormal(); nb = xb.he.parentLoop.parentFace.containingPlane.getNormal(); d1 = nb.dotProduct(xa.ref1); d2 = nb.dotProduct(xa.ref2); d3 = na.dotProduct(xb.ref1); d4 = na.dotProduct(xb.ref2); s.s1a = PolyhedralBoundedSolid.compareValue(d1, 0.0, VSDK.EPSILON); s.s2a = PolyhedralBoundedSolid.compareValue(d2, 0.0, VSDK.EPSILON); s.s1b = PolyhedralBoundedSolid.comp
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -