double SurfaceOverlapFacet::projected_overlap( SurfaceOverlapFacet &other_facet, CubitBoolean draw_overlap ) { double tmp_double = agt->ProjectedOverlap( t, other_facet.t, draw_overlap ); if( tmp_double > 0.00 ) { CubitVector edge0(t.e0.x, t.e0.y, t.e0.z); CubitVector edge1(t.e1.x, t.e1.y, t.e1.z); CubitVector normal = edge0 * edge1; double area_facet1 = normal.length() / 2; edge0.set(other_facet.t.e0.x, other_facet.t.e0.y, other_facet.t.e0.z); edge1.set(other_facet.t.e1.x, other_facet.t.e1.y, other_facet.t.e1.z); normal = edge0 * edge1; double area_facet2 = normal.length() / 2; //don't report overlapping area between facets unless it is greater //than one hundredth of the area of the smaller facet if( area_facet1 < area_facet2 ) { if( tmp_double < (area_facet1*0.01)) tmp_double = 0.0; } else if( tmp_double < (area_facet2*0.01 )) tmp_double = 0.0; } return tmp_double; }
double CurveOverlapFacet::facet_to_facet_distance( CurveOverlapFacet *other_facet ) { CubitVector u = p1 - p0; CubitVector v = other_facet->p1 - other_facet->p0; CubitVector w = p0 - other_facet->p0; double a = u%u; double b = u%v; double c = v%v; double d = u%w; double e = v%w; double D = a*c - b*b; double sc, sN, sD = D; double tc, tN, tD = D; // compute the line parameters of the two closest points if( D < GEOMETRY_RESABS ) ///the lines are almost parallel { sN = 0.0; // force using point P0 on segment S1 sD = 1.0; // to prevent possible division by 0.0 later tN = e; tD = c; } else // get the closest points on the infinite lines { sN = (b*e - c*d); tN = (a*e - b*d); if (sN < 0.0) { // sc < 0 => the s=0 edge is visible sN = 0.0; tN = e; tD = c; } else if (sN > sD) { // sc > 1 => the s=1 edge is visible sN = sD; tN = e + b; tD = c; } } if (tN < 0.0) { // tc < 0 => the t=0 edge is visible tN = 0.0; // recompute sc for this edge if (-d < 0.0) sN = 0.0; else if (-d > a) sN = sD; else { sN = -d; sD = a; } } else if (tN > tD) { // tc > 1 => the t=1 edge is visible tN = tD; // recompute sc for this edge if ((-d + b) < 0.0) sN = 0; else if ((-d + b) > a) sN = sD; else { sN = (-d + b); sD = a; } } // finally do the division to get sc and tc sc = (fabs(sN) < GEOMETRY_RESABS ? 0.0 : sN / sD); tc = (fabs(tN) < GEOMETRY_RESABS ? 0.0 : tN / tD); // get the difference of the two closest points CubitVector dP = w + (sc * u) - (tc * v); // = S1(sc) - S2(tc) return dP.length(); // return the closest distance }