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; }
/* * 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); }
void towardsEquals(OrderedTriple p, double distance) { OrderedTriple v = p.minus(this); plus(v.times(distance / v.length())); }