Exemplo 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;
  }
Exemplo 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);
 }
Exemplo n.º 3
0
 static OrderedTriple[] sectSphereLine(double r, OrderedTriple a, OrderedTriple b) {
   // Find the intersection(s) of the sphere with radius length r and center at
   // the origin and the line containing points a and b
   OrderedTriple v = b.minus(a);
   try {
     double[] k = solveQuadratic(v.lengthSquared(), 2 * a.dot(v), a.lengthSquared() - r * r);
     OrderedTriple[] answer = {v.times(k[0]).plus(a), v.times(k[1]).plus(a)};
     return answer;
   } catch (Exception e) {
     return null;
   }
 }
Exemplo n.º 4
0
 static double[] planeFromNormalAndPoint(OrderedTriple n, OrderedTriple p) {
   double[] answer = {n.x, n.y, n.z, n.dot(p)};
   return answer;
 }
Exemplo n.º 5
0
  public static OrderedTriple findThirdVector(
      OrderedTriple v1, OrderedTriple v2, double a1, double a2, OrderedTriple testv)
      throws Exception {
    // v1 and v2 must be equal lengths N. returns the vector a1 rad from v1, a2
    // rad from v2 and N length. if there are two such vectors
    // it returns the one with positive component of testv
    // System.out.println( "angle between v1 & v2: " + v1.degBetween( v2 ) );
    double epsilon = 0.0001;
    if (isApprox(a1, 0, epsilon)) return new OrderedTriple(v1);
    if (isApprox(a1, Math.PI, epsilon)) return v1.negative();
    if (isApprox(a2, 0, epsilon)) return new OrderedTriple(v2);
    if (isApprox(a2, Math.PI, epsilon)) return v2.negative();
    OrderedTriple v3 = null;
    double a = v1.x;
    double b = v1.y;
    double c = v1.z;
    double d = v2.x;
    double e = v2.y;
    double f = v2.z;
    double g, h, i;
    double roots[] = null;
    double N = v1.length();
    double A = N * N * Math.cos(a1);
    double B = N * N * Math.cos(a2);

    double x12 = a * e - b * d;
    double x23 = b * f - c * e;
    double x31 = c * d - a * f;

    double P, Q, R, S;
    P = Q = R = S = 0;

    if (!isApprox(x12, 0, epsilon)) {
      // System.out.println( "route 1" );
      P = x23 / x12;
      Q = (e * A - b * B) / x12;
      R = x31 / x12;
      S = (a * B - d * A) / x12;
      roots = solveQuadratic(1 + P * P + R * R, 2 * P * Q + 2 * R * S, Q * Q + S * S - N * N);

      i = roots[0];
      v3 = new OrderedTriple(P * i + Q, R * i + S, i);
      if (testv != null && v3.dot(testv) < 0) {
        i = roots[1];
        v3.become(P * i + Q, R * i + S, i);
      }
    } else if (!isApprox(x23, 0, epsilon)) {
      // System.out.println( "route 2" );
      P = x31 / x23;
      Q = (f * A - c * B) / x23;
      R = x12 / x23;
      S = (b * B - e * A) / x23;
      roots = solveQuadratic(1 + P * P + R * R, 2 * P * Q + 2 * R * S, Q * Q + S * S - N * N);

      g = roots[0];
      v3 = new OrderedTriple(g, P * g + Q, R * g + S);
      if (testv != null && v3.dot(testv) < 0) {
        g = roots[1];
        v3.become(g, P * g + Q, R * g + S);
      }
    } else if (!isApprox(x31, 0, epsilon)) {
      // System.out.println( "route 3" );
      P = x23 / x31;
      Q = (c * B - f * A) / x31;
      R = x12 / x31;
      S = (d * A - a * B) / x31;
      roots = solveQuadratic(1 + P * P + R * R, 2 * P * Q + 2 * R * S, Q * Q + S * S - N * N);

      h = roots[0];
      v3 = new OrderedTriple(P * h + Q, h, R * h + S);
      if (testv != null && v3.dot(testv) < 0) {
        h = roots[1];
        v3.become(P * h + Q, h, R * h + S);
      }
    } else {
      throw new Exception("EXCEPTION: no route found in findThirdVector");
    }
    // if( ! isApprox( v3.radBetween( v1 ), a1, 0.1 ) ) System.out.println(
    // "error v1" );
    // if( ! isApprox( v3.radBetween( v2 ), a2, 0.1 ) ) System.out.println(
    // "error v2" );
    return v3;
  }