// 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; } }
// TODO Unify the result to same type for lpProject protected GeomObj2 intersectPlane(Line that) { if ((type == CohoDouble.type || that.type() == CohoDouble.type) && (type instanceof ScaleType && that.type() instanceof ScaleType)) { try { GeomObj2 obj = this.specifyType(DoubleInterval.type) .baseIntersectPlane(that.specifyType(DoubleInterval.type)); // make sure the error is not large when conver to double // System.out.println(obj.maxError()); if (obj.maxError() > eps) throw new ArithmeticException(); return obj; } catch (ArithmeticException e) { // System.out.println("here"); return this.specifyType(CohoAPR.type).baseIntersectPlane(that.specifyType(CohoAPR.type)); } } else { // NOTICE: don't use double and interval. the result may contain error. return baseIntersectPlane(that); } }