Ejemplo n.º 1
0
  static OrderedTriple[] sectPlanes(
      OrderedTriple p11,
      OrderedTriple p12,
      OrderedTriple p13,
      OrderedTriple p21,
      OrderedTriple p22,
      OrderedTriple p23) {
    OrderedTriple n1 = p11.minus(p12).cross(p12.minus(p13));
    OrderedTriple n2 = p21.minus(p22).cross(p22.minus(p23));
    OrderedTriple n3 = n1.cross(n2);

    double[] m1 = {n1.x, n1.y, n1.z};
    double[] m2 = {n2.x, n2.y, n2.z};
    double[] m3 = {n3.x, n3.y, n3.z};
    double[][] m = {m1, m2, m3};
    Matrix M = new Matrix(m);
    double[] b1 = {n1.dot(p11)};
    double[] b2 = {n2.dot(p21)};
    double[] b3 = {0};
    double[][] b = {b1, b2, b3};
    Matrix B = new Matrix(b);
    Matrix S = M.inverse().times(B);
    // OrderedTriple s1 = new OrderedTriple( S.mat[0][0], S.mat[1][0],
    // S.mat[2][0] );
    OrderedTriple s1 = new OrderedTriple(S.mat[0][0], S.mat[1][0], S.mat[2][0]);
    OrderedTriple s2 = s1.plus(n3);
    OrderedTriple[] answer = {s1, s2};
    return answer;
  }
Ejemplo n.º 2
0
 public static OrderedTriple sectPlaneLine(
     OrderedTriple P1, OrderedTriple P2, OrderedTriple P3, OrderedTriple L1, OrderedTriple L2) {
   // Find the 3D coordinates of the intersection of the plane containing
   // points P1, P2, P3 and the line containing L1, L2
   OrderedTriple n = P2.minus(P1).cross(P3.minus(P2));
   OrderedTriple l = L2.minus(L1);
   double A = n.dot(l);
   if (A == 0) return null;
   double B = n.dot(P1);
   double C = n.dot(L1);
   double K = (B - C) / A;
   return l.times(K).plus(L1);
 }
Ejemplo n.º 3
0
 public static OrderedTriple[] sectSphereLine(
     OrderedTriple c, double r, OrderedTriple a, OrderedTriple b) {
   // Find the intersection(s) of the sphere with radius length r and center at
   // point c and the line containing points a and b
   OrderedTriple v = b.minus(a);
   OrderedTriple d = a.minus(c);
   try {
     double[] k = solveQuadratic(v.lengthSquared(), 2 * d.dot(v), d.lengthSquared() - r * r);
     OrderedTriple[] answer = {v.times(k[0]).plus(a), v.times(k[1]).plus(a)};
     return answer;
   } catch (Exception e) {
     return null;
   }
 }
Ejemplo n.º 4
0
 public static OrderedTriple sectLines(
     OrderedTriple p1, OrderedTriple p2, OrderedTriple p3, OrderedTriple p4) {
   // line from p1 through p2 and line from p3 through p4
   OrderedTriple A = p2.minus(p1);
   OrderedTriple B = p4.minus(p3);
   OrderedTriple C = p3.minus(p1);
   OrderedDouble KT1 = OrderedDouble.solveEquations(A.x, -B.x, C.x, A.y, -B.y, C.y);
   OrderedDouble KT2 = OrderedDouble.solveEquations(A.y, -B.y, C.y, A.z, -B.z, C.z);
   OrderedDouble KT3 = OrderedDouble.solveEquations(A.z, -B.z, C.z, A.x, -B.x, C.x);
   double K = 0;
   if (KT1 == null && KT2 == null && KT3 == null) {
     return LineLineIntersect(p1, p2, p3, p4);
     // return null;
   } else if (KT1 != null) {
     K = KT1.x;
   } else if (KT2 != null) {
     K = KT2.x;
   } else if (KT3 != null) {
     K = KT3.x;
   }
   return A.times(K).plus(p1);
 }
Ejemplo n.º 5
0
 public OrderedTriple(OrderedTriple t1, OrderedTriple t2) {
   this(t2.minus(t1));
 }
Ejemplo n.º 6
0
 static double[] planeFrom3Points(OrderedTriple p1, OrderedTriple p2, OrderedTriple p3) {
   return planeFromNormalAndPoint(p1.minus(p2).cross(p2.minus(p3)), p1);
 }
Ejemplo n.º 7
0
 /*
  * static OrderedTriple sectPlaneLine( OrderedTriple P1, OrderedTriple P2,
  * OrderedTriple P3, OrderedTriple L1, OrderedTriple L2 ){ OrderedTriple n =
  * P2.minus( P1 ).cross( P3.minus( P2 ) ); OrderedTriple l = L2.minus( L1 );
  * double A = n.dot( l ); if( A == 0 ) return null; double B = n.dot( P1 );
  * double C = n.dot( L1 ); double K = ( B - C )/A; return l.times( K ).plus(
  * L1 ); }
  */
 public static double pointPlaneDistance(
     OrderedTriple p, OrderedTriple P1, OrderedTriple P2, OrderedTriple P3) {
   OrderedTriple n = P2.minus(P1).cross(P3.minus(P2));
   return sectPlaneLine(P1, P2, P3, p, p.plus(n)).distance(p);
 }
Ejemplo n.º 8
0
 void towardsEquals(OrderedTriple p, double distance) {
   OrderedTriple v = p.minus(this);
   plus(v.times(distance / v.length()));
 }
Ejemplo n.º 9
0
 OrderedTriple towards(OrderedTriple p, double distance) {
   OrderedTriple v = p.minus(this);
   return plus(v.times(distance / v.length()));
 }
Ejemplo n.º 10
0
 public OrderedTriple mid(OrderedTriple p, double percent) {
   percent /= 100;
   return plus(p.minus(this).times(percent));
 }
Ejemplo n.º 11
0
 public double distance(OrderedTriple p1, OrderedTriple p2) {
   // distance to line through p1 and p2
   OrderedTriple v1 = p2.minus(p1);
   OrderedTriple v2 = minus(p1);
   return v2.length() * v2.sin(v1);
 }