Example #1
0
 public static OrderedTriple round(OrderedTriple ot, int mantissaLength) {
   ot = new OrderedTriple(ot);
   ot.x = Misc.round(ot.x, mantissaLength);
   ot.y = Misc.round(ot.y, mantissaLength);
   ot.z = Misc.round(ot.z, mantissaLength);
   return ot;
 }
Example #2
0
 public OrderedTriple arbitraryPerpendicular() {
   OrderedTriple perp = new OrderedTriple(1, 1, 1);
   if (x != 0) perp.x = (y + z) / -x;
   else if (y != 0) perp.y = (x + z) / -y;
   else if (z != 0) perp.z = (x + y) / -z;
   else return null;
   return perp;
 }
Example #3
0
  private static OrderedTriple LineLineIntersect(
      OrderedTriple p1, OrderedTriple p2, OrderedTriple p3, OrderedTriple p4) {
    double EPS = 1e-12;
    OrderedTriple p13 = new OrderedTriple(),
        p43 = new OrderedTriple(),
        p21 = new OrderedTriple(),
        pa = new OrderedTriple(),
        pb = new OrderedTriple();
    double d1343, d4321, d1321, d4343, d2121;
    double numer, denom, mua, mub;

    p13.x = p1.x - p3.x;
    p13.y = p1.y - p3.y;
    p13.z = p1.z - p3.z;
    p43.x = p4.x - p3.x;
    p43.y = p4.y - p3.y;
    p43.z = p4.z - p3.z;
    if (Math.abs(p43.x) < EPS && Math.abs(p43.y) < EPS && Math.abs(p43.z) < EPS) return (null);
    p21.x = p2.x - p1.x;
    p21.y = p2.y - p1.y;
    p21.z = p2.z - p1.z;
    if (Math.abs(p21.x) < EPS && Math.abs(p21.y) < EPS && Math.abs(p21.z) < EPS) return (null);

    d1343 = p13.x * p43.x + p13.y * p43.y + p13.z * p43.z;
    d4321 = p43.x * p21.x + p43.y * p21.y + p43.z * p21.z;
    d1321 = p13.x * p21.x + p13.y * p21.y + p13.z * p21.z;
    d4343 = p43.x * p43.x + p43.y * p43.y + p43.z * p43.z;
    d2121 = p21.x * p21.x + p21.y * p21.y + p21.z * p21.z;

    denom = d2121 * d4343 - d4321 * d4321;
    if (Math.abs(denom) < EPS) return (null);
    numer = d1343 * d4321 - d1321 * d4343;

    mua = numer / denom;
    mub = (d1343 + d4321 * (mua)) / d4343;

    pa.x = p1.x + mua * p21.x;
    pa.y = p1.y + mua * p21.y;
    pa.z = p1.z + mua * p21.z;
    pb.x = p3.x + mub * p43.x;
    pb.y = p3.y + mub * p43.y;
    pb.z = p3.z + mub * p43.z;

    return pa.mid(pb);
  }