// test_faces.java see test_faces_java.out // compile javac -cp . test_faces.java // execute java -cp . test_faces public class test_faces { double a1, a2, a3, a4, a5; // angles double a1c, a2c, a3c, a4c, a5c; // angles recomputed double x1, x2, x3, x4, x5, x6; // orthoganal coordinates double R = 1.0; double sumsq, sq2, sq3, sq4, err, maxerr; double Pi = 3.141592653589793238462643; double twoPi = 2.0*Pi; double halfPi = Pi/2.0; double fourthPi = Pi/4.0; double eighthPi = Pi/8.0; int i1, i2, i3, i4, i5; public test_faces() { System.out.println("test_faces.java running, R = 1"); System.out.println("2D circle 1 angle radius 1 "); System.out.println(" x1 = R * cos(a1) "); System.out.println(" x2 = R * sin(a1) "); System.out.println(" R = sqrt(x1*x1 + x2*x2) "); System.out.println(" a1 = acos(x1/R) "); System.out.println(" if(x2<0.0) a1 = 2*Pi - a1 "); maxerr = 0.0; a1 = 0.0; for(i1=0; i1<8; i1++) { x1 = R*Math.cos(a1); x2 = R*Math.sin(a1); sumsq = x1*x1 + x2*x2; a1c = Math.acos(x1/Math.sqrt(sumsq)); if(x2<0.0) a1c = twoPi - a1c; maxerr = Math.max(maxerr,Math.abs(R*R-sumsq)); System.out.println("a1 ="+a1+", x1="+x1+", x2="+x2); System.out.println("a1c="+a1c); System.out.println(" "); a1 += fourthPi; } // end i1 System.out.println(" maxerr"+maxerr); System.out.println(" "); System.out.println("3D sphere 2 angles radius 1 "); System.out.println(" x1 = R * cos(a1) "); System.out.println(" x2 = R * sin(a1) * cos(a2) "); System.out.println(" x3 = R * sin(a1) * sin(a2) "); System.out.println(" R = sqrt(x1*x1 + x2*x2 + x3*x3) "); System.out.println(" R2 = sqrt(x2*x2 + x3*x3) "); System.out.println(" if R2 < 10^-8 then a2 = 0.0 "); System.out.println(" else a2 = acos(x2/R2) "); System.out.println(" if(x2<0.0) a2 = 2*Pi - a2 "); maxerr = 0.0; a1 = 0.0; for(i1=0; i1<=4; i1++) // both include poles { a2 = 0.0; for(i2=0; i2<8; i2++) { x1 = R*Math.cos(a1); x2 = R*Math.sin(a1)*Math.cos(a2); x3 = R*Math.sin(a1)*Math.sin(a2); sumsq = x1*x1 + x2*x2 + x3*x3; sq2 = x2*x2+x3*x3; a1c = Math.acos(x1/Math.sqrt(sumsq)); a2c = Math.acos(x2/Math.sqrt(sq2)); if(sq2<1.0e-8) a2c = 0.0; if(x3<0.0) a2c = twoPi - a2c; maxerr = Math.max(maxerr,Math.abs(R*R-sumsq)); System.out.println("a1 ="+a1+", a2 ="+a2+", x1="+x1+", x2="+x2+", x3="+x3); System.out.println("a1c="+a1c+", a2c="+a2c); System.out.println(" "); a2 += fourthPi; if(a1==0.0 || Math.abs(a1-Pi)<0.0001) break; // only one point on pole } // end i2 a1 += fourthPi; } // end i1 System.out.println(" maxerr="+maxerr); System.out.println(" "); System.out.println("4D sphere 3 angels radius 1 "); System.out.println(" x1 = R Math.cos(a1) "); System.out.println(" x2 = R Math.sin(a1)*Math.cos(a2) "); System.out.println(" x3 = R Math.sin(a1)*Math.sin(a2)*Math.cos(a3) "); System.out.println(" x4 = R Math.sin(a1)*Math.sin(a2)*Math.sin(a3) "); System.out.println(" R = sqrt(x1*x1 + x2*x2 + x3*x3 + x4*x4) "); System.out.println(" R2 = sqrt(x2*x2 + x3*x3 + x4*x4) "); System.out.println(" if R2 < 10^-8 then a2 = 0.0 "); System.out.println(" else a2 = acos(x2/R2) "); System.out.println(" R3 = sqrt(x3*x3 + x4*x4) "); System.out.println(" if R3 < 10^-8 then a3 = 0.0 "); System.out.println(" else a3 = acos(x3/R3) "); System.out.println(" if(x4<0.0) a3 = 2*Pi - a3 "); maxerr = 0.0; a1 = 0.0; for(i1=0; i1<4; i1++) { a2 = 0.0; for(i2=0; i2<4; i2++) { a3 = 0.0; for(i3=0; i3<8; i3++) { x1 = R*Math.cos(a1); x2 = R*Math.sin(a1)*Math.cos(a2); x3 = R*Math.sin(a1)*Math.sin(a2)*Math.cos(a3); x4 = R*Math.sin(a1)*Math.sin(a2)*Math.sin(a3); sumsq = x1*x1 + x2*x2 + x3*x3 + x4*x4; a1c = Math.acos(x1/Math.sqrt(sumsq)); sq2 = x2*x2+x3*x3+x4*x4; a2c = Math.acos(x2/Math.sqrt(sq2)); if(sq2<1.0e-8) a2c = 0.0; sq3 = x3*x3+x4*x4; a3c = Math.acos(x3/Math.sqrt(sq3)); if(sq3<1.0e-8) a3c = 0.0; if(x4<0.0) a3c = twoPi - a3c; maxerr = Math.max(maxerr,Math.abs(R*R-sumsq)); System.out.println("a1 ="+a1+", a2 ="+a2+", a3 ="+a3); System.out.println("x1 ="+a1+", x2 ="+x2+", x3 ="+x3+", x4 ="+x4); System.out.println("a1c="+a1c+", a2c="+a2c+", a3c="+a3c); System.out.println(" "); a3 += fourthPi; if(a1==0.0 || Math.abs(a1-Pi)<0.0001) break;//only one point on pole if(a2==0.0 || Math.abs(a2-Pi)<0.0001) break;//only one point on pole } // end i1 a2 += fourthPi; if(a2==0.0 || Math.abs(a2-Pi)<0.0001) break; // only one point on pole } // end i2 a1 += fourthPi; } // end i3 System.out.println(" maxerr="+maxerr); System.out.println(" "); System.out.println("5D sphere 4 angles radius 1 "); System.out.println(" x1 = R Math.cos(a1) "); System.out.println(" x2 = R Math.sin(a1) Math.cos(a2) "); System.out.println(" x3 = R Math.sin(a1) Math.sin(a2) Math.cos(a3) "); System.out.println(" x4 = R Math.sin(a1) Math.sin(a2) Math.sin(a3) Math.cos(a4) "); System.out.println(" x5 = R Math.sin(a1) Math.sin(a2) Math.sin(a3) Math.sin(a4) "); System.out.println(" R = sqrt(x1*x1 + x2*x2 + x3*x3 + x4*x4 + x5*x5) "); System.out.println(" R2 = sqrt(x2*x2 + x3*x3 + x4*x4 + x5*x5) "); System.out.println(" if R2 < 10^-8 then a2 = 0.0 "); System.out.println(" else a2 = acos(x2/R2) "); System.out.println(" R3 = sqrt(x3*x3 + x4*x4 + x5*x5) "); System.out.println(" if R3 < 10^-8 then a3 = 0.0 "); System.out.println(" else a3 = acos(x3/R3) "); System.out.println(" R4 = sqrt(x4*x4 + x5*x5) "); System.out.println(" if R4 < 10^-8 then a4 = 0.0 "); System.out.println(" else a4 = acos(x4/R4) "); System.out.println(" if(x5<0.0) a4 = 2*Pi - a3 "); maxerr = 0.0; a1 = 0.0; for(i1=0; i1<=4; i1++) { a2 = 0.0; for(i2=0; i2<=4; i2++) { a3 = 0.0; for(i3=0; i3<=4; i3++) // both include poles { a4 = 0.0; for(i4=0; i4<8; i4++) { x1 = R*Math.cos(a1); x2 = R*Math.sin(a1)*Math.cos(a2); x3 = R*Math.sin(a1)*Math.sin(a2)*Math.cos(a3); x4 = R*Math.sin(a1)*Math.sin(a2)*Math.sin(a3)*Math.cos(a4); x5 = R*Math.sin(a1)*Math.sin(a2)*Math.sin(a3)*Math.sin(a4); sumsq = x1*x1 + x2*x2 + x3*x3 + x4*x4 + x5*x5; a1c = Math.acos(x1/Math.sqrt(sumsq)); sq2 = x2*x2 + x3*x3 + x4*x4 + x5*x5; a2c = Math.acos(x2/Math.sqrt(sq2)); if(sq4<1.0e-8) a2c = 0.0; sq3 = x3*x3 + x4*x4 + x5*x5; a3c = Math.acos(x3/Math.sqrt(sq3)); if(sq3<1.0e-8) a3c = 0.0; sq4 = x4*x4 + x5*x5; a4c = Math.acos(x4/Math.sqrt(sq4)); if(sq2<1.0e-8) a4c = 0.0; if(x5<0.0) a4c = twoPi - a4c; maxerr = Math.max(maxerr,Math.abs(R*R-sumsq)); System.out.println("a1 ="+a1+", a2 ="+a2+", a3 ="+a3+" a4 ="+a4); System.out.println("x1="+x1+", x2="+x2+", x3="+x3+" x4="+x4+" x5="+x5); System.out.println("a1c="+a1c+", a2c="+a2c+", a3c="+a3c+", a4c="+a4c); System.out.println(" "); a4 += fourthPi; if(a1==0.0 || Math.abs(a1-Pi)<0.0001) break; // only one point on pole if(a2==0.0 || Math.abs(a2-Pi)<0.0001) break; // only one point on pole if(a3==0.0 || Math.abs(a3-Pi)<0.0001) break; // only one point on pole } // end i1 a3 += fourthPi; if(a1==0.0 || Math.abs(a1-Pi)<0.0001) break; // only one point on pole if(a2==0.0 || Math.abs(a2-Pi)<0.0001) break; // only one point on pole } // end i2 a2 += fourthPi; if(a1==0.0 || Math.abs(a1-Pi)<0.0001) break; // only one point on pole } // end i3 a1 += fourthPi; } // end i3 System.out.println(" maxerr="+maxerr); System.out.println(" "); System.out.println("test_faces.java finished"); } // end test_faces public static void main (String[] args) { new test_faces(); } } // end test_faces.java