/** * 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 ldc6{ public static void main(String args[]) throws Exception { double // impirically-found values of the radii of the 3 circles p = 2, // radius of small circle q = 2.5, // radius of medium circle r = 4, // radius of large circle beta = 0, // angle used in the SAS case of the Cosine Rule i = .000001/r, // incrementer = 0.001 mm (rescaled to r = 1) j = i/2, // half the increment R1 = 0.02, // radius of entire ninho calculated using small circle R2 = 0.01; // radius of entire ninho calculated using 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 // dummy starting value to allow a = p + q + r; // entry to outer while-loop boolean // remains false if calculation does not flag = false; // 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) + 2; 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 the medium circle has not yet reached to touch the containing circle */ h = q + 1; //solve the left-hand right-angled triangle R2 = Math.sqrt(h * h - 1) + q + 1.732050808; q += i; // increment radius of medium circle o++; // iteration counter for the inner while-loop } beta = 2.094395102 - Math.acos(1 / (1 + q)) - Math.asin(p / (p + 1)); if(Double.isNaN(beta)) // break out of loop if beta break; // cannot be resolved double P = p + 1, Q = q + 1; // the 2 sides of the red triangle // cosine rule a = Math.sqrt(P * P + Q * Q - 2 * P * Q * Math.cos(beta)); q -= i; // negate the final loop increment p += i; // 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; // take half the increment off p q -= j; // take half the increment off q } // Re-scale the circles so that the smallest measures 2.5 metres double x = 2.5 / p; p = 2.5; 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 safety loop because converged successfully } // end of safety for-loop if(!flag) System.out.println("Didn't converge."); } }