 Timestamp:
 Apr 30, 2007, 12:52:30 PM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/npemap.org.uk/scripts/gmclondon/FindBestMatch.java
r538 r540 23 23 new Place("EustonRdCorner", 529752,182592, 11697,5595), 24 24 new Place("TowerOfLondon", 533648,180544, 16268,7075), 25 new Place("CanningTownSta", 539304,181544, 23239,6190) 25 new Place("CanningTownSta", 539304,181544, 23239,6190), 26 26 }; 27 27 }; 28 29 /** 30 * Convert a place into meters from 00 of the map, having applied the 31 * scale and the slant 32 */ 33 public static double[] placeTo00Meters(Place place, double slant_base, double slant_adj_e, double slant_adj_n, double scale) { 34 double slant, slant_rad, gmc_e_m, gmc_n_m; 35 double[] ret = new double[2]; 36 37 // The slant seems to be higher towards the left 38 slant = slant_base + 39 slant_adj_e * ((26000.0  place.gmc_e)/26000.0) + 40 slant_adj_n * ((17000.0  place.gmc_n)/17000.0); 41 slant_rad = slant / 360.0 * 2.0 * Math.PI; 42 43 // Turn the gmc e+n into meters from the start of the map, 44 // with scaling 45 // (Grid squares were half mile) 46 gmc_e_m = place.gmc_e / 2.0 * 1.609344 * scale; 47 gmc_n_m = place.gmc_n / 2.0 * 1.609344 * scale; 48 49 // Apply the slant factor 50 ret[0] = (Math.sin(slant_rad)*gmc_n_m) + (Math.cos(slant_rad)*gmc_e_m); 51 ret[1] = (Math.cos(slant_rad)*gmc_n_m) + (Math.sin(slant_rad)*gmc_e_m); 52 return ret; 53 } 28 54 29 55 // Loop by slant,slant_adj_e,slant_adj_n 30 56 // Then calculate, then loop by scale and find error 31 57 public static void main(String[] args) { 32 // What the unscaled e+n's are33 double[] e_m = new double[places.length];34 double[] n_m = new double[places.length];35 58 36 59 // Don't reallocate all the time 37 double slant, slant_rad, gmc_e_m, gmc_n_m;60 double[] gmc_00; 38 61 double ngr_e_0, ngr_n_0, ngr_e, ngr_n; 39 double error;62 double delta_e, delta_n, error; 40 63 41 64 // Our matches 42 65 ArrayList<Match> matches = new ArrayList<Match>(); 43 66 44 //for(double slant_base=0.35; slant_base<=1.4; slant_base += 0.01) {45 for(double slant_base=1.05; slant_base<=1.09; slant_base += 0.01) {67 for(double slant_base=0.35; slant_base<=1.4; slant_base += 0.01) { 68 //for(double slant_base=1.05; slant_base<=1.09; slant_base += 0.01) { 46 69 System.out.println("The slant is " + slant_base); 47 70 for(double slant_adj_e=0.5; slant_adj_e<=1.2; slant_adj_e += 0.01) { 48 71 for(double slant_adj_n=0.5; slant_adj_n<=1.2; slant_adj_n += 0.01) { 49 // Calculate for this slant set50 for(int i=0; i<places.length; i++) {51 slant = slant_base +52 slant_adj_e * ((26000.0  places[i].gmc_e)/26000.0) +53 slant_adj_n * ((17000.0  places[i].gmc_n)/17000.0);54 slant_rad = slant / 360.0 * 2.0 * Math.PI;55 56 // Turn the gmc e+n into meters from the start of the map,57 // but without scaling58 // (Grid squares were half mile)59 gmc_e_m = places[i].gmc_e / 2.0 * 1.609344;60 gmc_n_m = places[i].gmc_n / 2.0 * 1.609344;61 62 // Apply the slant factor63 e_m[i] = (Math.sin(slant_rad)*gmc_n_m) + (Math.cos(slant_rad)*gmc_e_m);64 n_m[i] = (Math.cos(slant_rad)*gmc_n_m) + (Math.sin(slant_rad)*gmc_e_m);65 }66 67 72 // Loop over the scales 68 for(double scale=0.9 5; scale <= 1.25; scale += 0.01) {73 for(double scale=0.900; scale <= 1.250; scale += 0.001) { 69 74 // Calculate the left corner e+n using 1st Place 70 75 // (We know that 0,646 2,487 is 520,896 174,936) 71 ngr_e_0 = 520896  (e_m[0] * scale); 72 ngr_n_0 = 174936  (n_m[0] * scale); 76 gmc_00 = placeTo00Meters(places[0],slant_base,slant_adj_e,slant_adj_n,scale); 77 ngr_e_0 = 520896  gmc_00[0]; 78 ngr_n_0 = 174936  gmc_00[1]; 73 79 74 80 error = 0.0; 75 81 for(int i=0; i<places.length; i++) { 76 // Adjust by scale 77 ngr_e = (e_m[i] * scale) + ngr_e_0; 78 ngr_n = (n_m[i] * scale) + ngr_n_0; 82 // Slant and scale 83 gmc_00 = placeTo00Meters(places[i],slant_base,slant_adj_e,slant_adj_n,scale); 84 ngr_e = gmc_00[0] + ngr_e_0; 85 ngr_n = gmc_00[1] + ngr_n_0; 79 86 80 // Find the error 87 // Figure out the error 88 delta_e = places[i].osgb_e  ngr_e; 89 delta_n = places[i].osgb_n  ngr_n; 90 //System.out.println(""); 91 //System.out.println(delta_e + "  " + ngr_e + " vs " + places[i].osgb_e); 92 //System.out.println(delta_n + "  " + ngr_n + " vs " + places[i].osgb_n); 93 94 // Total up the running error 81 95 error += Math.sqrt( 82 Math.pow(places[i].osgb_e  ngr_e, 2) + 83 Math.pow(places[i].osgb_n  ngr_n, 2) 96 (delta_e*delta_e) + (delta_n*delta_n) 84 97 ); 85 98 } 86 99 87 100 // Was the error small enough? If so, save it 88 if( error < 4000) {89 System.out.println("Slant is " + slant_base + ", " + slant_adj_e + ", " + slant_adj_n + "  Scale is " + scale + "  Error is " + error);101 if( (error/places.length) < 900) { 102 System.out.println("Slant is " + slant_base + ", " + slant_adj_e + ", " + slant_adj_n + "  Scale is " + scale + "  Error is " + (error/places.length) + " (" + error + ")"); 90 103 matches.add( 91 104 new Match(slant_base,slant_adj_e,slant_adj_n,scale,error) … … 104 117 // Print out the best few 105 118 for(int i=0; i<= 10; i++) { 106 System.out.println("Error was " + m[i].error);119 System.out.println("Error was " + (int)(m[i].error/places.length) + " (" + m[i].error + ")"); 107 120 System.out.println(" Scale was " + m[i].scale); 108 121 System.out.println(" slant was " + m[i].slant + ", " + m[i].slant_ajd_e + ", " + m[i].slant_ajd_n);
Note: See TracChangeset
for help on using the changeset viewer.