Пример #1
0
  public static boolean isFaceDirectionOnEdgeCorrect(IVec2 edgePt1, IVec2 edgePt2, IVec2 vertexPt) {
    // this is under assumption of outer trim loop goes counter-clockwise and
    // inner trim hole loop goes clockwise always.
    // return edgePt2.diff(edgePt1).cross(vertexPt.diff(edgePt1)).z > 0;
    double z = edgePt2.diff(edgePt1).cross(vertexPt.diff(edgePt1)).z;

    // IOut.p("edge1 = "+edgePt1 +", edge2 = "+edgePt2+", vertexPt = "+vertexPt);
    // if(z>0) IOut.p("correct direction"); //
    // else IOut.p("wrong direction"); //

    // return z > 0;
    return z >= 0; // changed 2011/07/11
  }
Пример #2
0
  public static boolean isPointInsideEdge(IVec2 pt, IVec2 edgePt1, IVec2 edgePt2, IVec2 edgePt3) {
    // inside of edge is left side of the edge formed by edgePt1, edgePt2, edgePt3
    IVec2 diff1 = edgePt2.diff(edgePt1);
    IVec2 diff2 = edgePt3.diff(edgePt2);

    // edge bent inward
    if (diff1.cross(diff2).z >= 0) {
      if (!isFaceDirectionOnEdgeCorrect(edgePt1, edgePt2, pt)
          || !isFaceDirectionOnEdgeCorrect(edgePt2, edgePt3, pt)) return false;
      return true;
    }
    if (!isFaceDirectionOnEdgeCorrect(edgePt1, edgePt2, pt)
        && !isFaceDirectionOnEdgeCorrect(edgePt2, edgePt3, pt)) return false;
    return true;
  }
Пример #3
0
  public static boolean isPointsIntersectiongWithEdge(
      IVec2 pt1, IVec2 pt2, IVec2 edgePt1, IVec2 edgePt2, IVec2 edgePt3) {
    IVec2 diff1 = edgePt2.diff(edgePt1);
    IVec2 diff2 = edgePt3.diff(edgePt2);

    // edge bent inward; no intersection
    if (diff1.cross(diff2).z >= 0) return false;

    // edge bent outward
    if (isFaceDirectionOnEdgeCorrect(edgePt1, edgePt2, pt1)
        && isFaceDirectionOnEdgeCorrect(edgePt1, edgePt2, pt2)) return false;
    if (isFaceDirectionOnEdgeCorrect(edgePt2, edgePt3, pt1)
        && isFaceDirectionOnEdgeCorrect(edgePt2, edgePt3, pt2)) return false;

    IVec2 bisector1 = diff1.neg().bisect(diff2);
    IVec2 bisector2 = pt1.diff(edgePt2).bisect(pt2.diff(edgePt2));

    if (bisector1.dot(bisector2) > 0) return true;

    return false;
  }
Пример #4
0
 public static boolean isVertexOnSameSide(
     IVec2 edgePt1, IVec2 edgePt2, IVec2 vertexPt1, IVec2 vertexPt2) {
   IVec2 diff = edgePt2.diff(edgePt1);
   return diff.cross(vertexPt1.diff(edgePt1)).z * diff.cross(vertexPt2.diff(edgePt1)).z >= 0;
 }
Пример #5
0
 public static boolean isClockwise(IVec2 pt1, IVec2 pt2, IVec2 pt3) {
   return pt2.diff(pt1).cross(pt3.diff(pt2)).z < 0;
 }