/** * Ninho Circle ratios Calculation Program. * @author Robert J Morton * @version 14 April 208 */ /* Program to find the ratios p:q:r of the radii of the 3 sizes of circle of the Ninho 1) Let r = 1 in order to simplify the trigonometry. 2) Set p and q to the impirically-found values 3) Reduce p by 5% and q by 10% 4) Set the increment i=.0001 5) Compute R1 from p 6) Compute R2 from q 7) if(R2 < R1) {q += i; goto 5} 8) if(a > p+q) {p += i; q -= i; goto 5} 9) x = p + q - a; 10) if(x > i/2) p -= i/2; q -= i/2; 11) p = 2.5; q = q/p; r = 1/p; */ import java.io.*; class lardocecu{ public static void main(String args[]) throws Exception { double //the impirically-found values of the radii of the 3 circles p = 2.5, //radius of small circle q = 3.7, //radius of medium circle r = 4.449593469, //radius of large circle beta = 0, //angle used in the SAS case of the Cosine Rule i = .000001/r, //incrementer = a thousandth of a millimetre (rescaled to r = 1) j = i/2, //half the increment R1 = 0.02, //radius of the entire ninho calculated using the small circle R2 = 0.01; //radius of the entire ninho calculated using the medium circle p /= r; //p rescaled to r = 1 0.561849081 p *= 0.90; //reduce p by 10% 0.505664173 q /= r; //q rescaled to r = 1 0.831536639 q *= 0.70; //reduce q by 30% 0.582075648 r = 1; //make the large circle unit radius double a = p + q + r; //dummy starting value to allow entry to outer while-loop boolean flag = false; //remains false if calculation does not converge //after 10,000 iterations for(int m = 0; m < 10000; m++) { //safety loop to avoid possible infinite iteration int n = 0, o = 0; //loop iteration counters while(((p+q) < a) || Double.isNaN(beta)) { double h = Math.sqrt(1 + p + p) + 1.701301617; R1 = Math.sqrt(h * h + p * p) + p; //solve right-hand blue right-angle triangle R2 = 0.01; //seed value for R2 n++; //iteration counter for the outer while-loop while(R2 < R1) { //while medium circle has not reached to touch containing circle h = q + 1; //solve the left-hand right-angle triangle R2 = Math.sqrt(h * h - 1) + q + 1.37638192; q += i; //increment radius of medium circle o++; //iteration counter for the inner while-loop } beta = 2.199114857 - Math.acos(1 / (1 + q)) - Math.asin(p / (p + 1)); if(Double.isNaN(beta)) break; //break out of loop if beta cannot be resolved double P = p + 1, Q = q + 1; //the 2 sides of the red triangle a = Math.sqrt(P * P + Q * Q - 2 * P * Q * Math.cos(beta)); //cosine rule q -= i; p += i; //negate the final loop increment of q and increment p } p -= i; //negate the final loop increment of p if((p + q - a) > j) { //if the overshoot is more than half the amount of the increment p -= j; q -= j; //take half the increment off each of p and q } // Re-scale the circles so that the smallest measures 3 metres double x = 3 / p; p = 3; r *= x; q *= x; R1 *= x; R2 *= x; System.out.println( //display the results on the command line "#declare sr = " + p + ";" + "\n#declare mr = " + q + ";" + "\n#declare lr = " + r + ";" + "\n#declare R1 = " + R1 + ";" + "\n#declare R2 = " + R2 + ";" + "\nbeta = " + beta + "\na = " + a + "\nm = " + m + "\nn = " + n + "\no = " + o ); flag = true; break; //exit the safety loop because converged successfully } // end of safety for-loop if(!flag) System.out.println("Didn't converge."); } }