Exemplo n.º 1
0
 public Line(CohoNumber A, CohoNumber B, CohoNumber C) {
   if (A.type() != B.type() || A.type() != C.type())
     throw new GeomException("Data type used for A,B,C of Line are not the same");
   this.A = A;
   this.B = B;
   this.C = C;
   this.type = A.type();
 }
Exemplo n.º 2
0
  // for interval lp-project
  public boolean similar(Line p) {
    double theta = Math.atan2(B.doubleValue(), A.doubleValue());
    double angle = theta >= 0 ? theta : 2 * Math.PI + theta;
    double ptheta = Math.atan2(p.B.doubleValue(), p.A.doubleValue());
    double pangle = ptheta >= 0 ? ptheta : 2 * Math.PI + ptheta;

    double norm = Math.sqrt(A.mult(A).add(B.mult(B)).doubleValue());
    double pnorm = Math.sqrt(p.A.mult(p.A).add(p.B.mult(p.B)).doubleValue());

    return (Math.abs(angle - pangle) < eps)
        && (Math.abs(C.doubleValue() / norm - p.C.doubleValue() / pnorm) < eps);
  }
Exemplo n.º 3
0
  // The intersection of line not plane
  // same with segment intersection
  private GeomObj2 baseIntersectPlane(Line that) {
    CohoNumber A1 = A(); // Ax+By=C
    CohoNumber B1 = B();
    CohoNumber C1 = C();

    CohoNumber A2 = that.A();
    CohoNumber B2 = that.B();
    CohoNumber C2 = that.C();

    CohoNumber denom = A1.mult(B2).sub(B1.mult(A2));
    //		System.out.println(denom);
    //		System.out.println(A1.sub(A2).doubleValue());
    //		System.out.println(A1.doubleValue()-(A2.doubleValue()));
    CohoNumber num1 = B1.mult(C2).sub(B2.mult(C1));
    CohoNumber num2 = C1.mult(A2).sub(C2.mult(A1));
    if (denom.compareTo(denom.zero()) == 0) {
      if (num1.compareTo(num1.zero()) != 0 || num2.compareTo(num2.zero()) != 0) { // no intersection
        return Empty.instance();
      } else { // intersection is segment
        return this; // same line
      }
    } else {
      Point pt = Point.create(num1.div(denom), num2.div(denom));
      // System.out.println(pt+""+type);
      return pt;
    }
  }
Exemplo n.º 4
0
 public GeomObj2 negate() {
   return new Line(A.negate(), B.negate(), C.negate());
 }
Exemplo n.º 5
0
 public double maxError() {
   if (type instanceof ScaleType) return 0;
   else return Math.max(A.error().max(B.error()).doubleValue(), C.error().doubleValue());
 }