public class Plane extends Surface{ Vector extNormal;//the normal pointing *out* of the surface Plane(double[] coeffs){ m=new material(); coefficients=new double[4]; origCoeff=new double[4]; extNormal=new Vector(new double[] {coeffs[0], coeffs[1], coeffs[2]}); double norm=extNormal.norm; extNormal.normalize(); if (norm==0) norm=1; origCoeff[0]=coefficients[0]=coeffs[0]/norm; origCoeff[1]=coefficients[1]=coeffs[1]/norm; origCoeff[2]=coefficients[2]=coeffs[2]/norm; origCoeff[3]=coefficients[3]=coeffs[3]/norm; } Plane(double[] coeffs, material ms){ m=new material(); coefficients=new double[4]; origCoeff=new double[4]; extNormal=new Vector(new double[] {coeffs[0], coeffs[1], coeffs[2]}); double norm=extNormal.norm; extNormal.normalize(); if (norm==0) norm=1; origCoeff[0]=coefficients[0]=coeffs[0]/norm; origCoeff[1]=coefficients[1]=coeffs[1]/norm; origCoeff[2]=coefficients[2]=coeffs[2]/norm; origCoeff[3]=coefficients[3]=coeffs[3]/norm; m.copy(ms); } Plane(Plane s){ // new Plane(s.coefficients, s.m); double[] coeffs=s.coefficients; origCoeff=new double[4]; m=new material(); coefficients=new double[4]; extNormal=new Vector(new double[] {coeffs[0], coeffs[1], coeffs[2]}); extNormal.normalize(); origCoeff[0]=coefficients[0]=coeffs[0]; origCoeff[1]=coefficients[1]=coeffs[1]; origCoeff[2]=coefficients[2]=coeffs[2]; origCoeff[3]=coefficients[3]=coeffs[3]; m.copy(s.m); } void setTransfo(Matrix3D tfs){ tf=new Matrix3D(); tf.copy(tfs); tf.invert(); tf.transpose(); tf.transform(origCoeff, coefficients); extNormal=new Vector(new double[] {coefficients[0], coefficients[1], coefficients[2]}); double norm=extNormal.norm; extNormal.normalize(); if (norm==0) norm=1; coefficients[0]/=norm; coefficients[1]/=norm; coefficients[2]/=norm; coefficients[3]/=norm; } void updateNormal(){ extNormal=new Vector(new double[] {coefficients[0], coefficients[1], coefficients[2]}); extNormal.normalize(); } Vector getNormal(double[] position){ return extNormal; } double[] intersections(double[] v, double[] w){ double vs0=extNormal.dotP(v)+coefficients[3]; double vs1=extNormal.dotP(w); if (vs1==0) {// normal orthogonal to w if (vs0>=0) return new double[]{INFTY+1,-1};// always out else return new double[]{0,INFTY};//always in } else{ double t=-vs0/vs1; if (vs1>0) {//w going away from the plane return new double[]{-1,t}; } else {//w going into the plane return new double[]{t,INFTY}; } } } }