Esempio n. 1
0
  public Point2D projectOnAC(Point2D q) {
    Vector2D r = a.sub(c);
    Vector2D s = r.rightNormal();
    double t = ((q.sub(c)).cross(r) / (r.cross(s)));

    return q.add(s.scale(t));
  }
Esempio n. 2
0
  public Point2D projectOnAB(Point2D q) {
    Vector2D r = a.sub(b);
    Vector2D s = r.rightNormal();
    double t = ((q.sub(b)).cross(r) / (r.cross(s)));
    //		System.out.println(t);

    return q.add(s.scale(t));
  }
Esempio n. 3
0
  public boolean contains(Point2D p) {
    // Compute vectors
    Vector2D v0 = ac;
    Vector2D v1 = ab;
    Vector2D v2 = p.sub(a);

    // Compute dot products
    double dot00 = v0.dot(v0); // dot(v0, v0);
    double dot01 = v0.dot(v1); // dot(v0, v1);
    double dot02 = v0.dot(v2); // dot(v0, v2);
    double dot11 = v1.dot(v1); // dot(v1, v1);
    double dot12 = v1.dot(v2); // dot(v1, v2);

    // Compute barycentric coordinates
    double invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
    double u = (dot11 * dot02 - dot01 * dot12) * invDenom;
    double v = (dot00 * dot12 - dot01 * dot02) * invDenom;

    // Check if point is in triangle
    return (u >= 0) && (v >= 0) && (u + v < 1);
  }
Esempio n. 4
0
 public Point2D sub(Vector2D p2) {
   return new Point2D(x - p2.getX(), y - p2.getY());
 }
Esempio n. 5
0
 public Point2D add(Vector2D p2) {
   return new Point2D(x + p2.getX(), y + p2.getY());
 }