顯示具有 JAVA 標籤的文章。 顯示所有文章
顯示具有 JAVA 標籤的文章。 顯示所有文章

2013年5月30日 星期四

[記事] The Quick Way to generate QR code in java

屬於阿宅世界的技術文章,想看的再點開,切莫自誤 !




2012年6月6日 星期三

[記事] URLConnection 與 Encoding

屬於阿宅世界的技術文章,想看的再點開,切莫自誤 !

2011年7月28日 星期四

[記事] Ant 入門

2011年7月25日 星期一

[記事] patch file

2011年6月22日 星期三

[記事] Tomcat and Memcached and Session Replication

要看的再點開

2011年5月24日 星期二

[記事] UMT (TWD97TM2) 轉 WGS84

public double[] TWD97TM2toWGS84(double x, double y) {
 // Ref1 : http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.htm
 // Ref2 : http://blog.ez2learn.com/2009/08/15/lat-lon-to-twd97/
 // 修正 Ref2 中lng回傳值 toDegree 設錯地方的Bug

 double dx = 250000;
 double dy = 0;
 double lon0 = 121;
 double k0 = 0.9999;
 double a =  6378137.0;
 double b = 6356752.314245;
 double e = Math.sqrt((1-(b*b)/(a*a)));

 x -= dx;
 y -= dy;

 // Calculate the Meridional Arc
 double M = y/k0;

 // Calculate Footprint Latitude
 double mu = M/(a*(1.0 - Math.pow(e, 2)/4.0 - 3*Math.pow(e, 4)/64.0 - 5*Math.pow(e, 6)/256.0));
 double e1 = (1.0 - Math.pow((1.0 - Math.pow(e, 2)), 0.5)) / (1.0 + Math.pow((1.0 - Math.pow(e, 2)), 0.5));

 double J1 = (3*e1/2 - 27*Math.pow(e1, 3)/32.0);
 double J2 = (21*Math.pow(e1, 2)/16 - 55*Math.pow(e1, 4)/32.0);
 double J3 = (151*Math.pow(e1, 3)/96.0);
 double J4 = (1097*Math.pow(e1, 4)/512.0);

 double fp = mu + J1*Math.sin(2*mu) + J2*Math.sin(4*mu) + J3*Math.sin(6*mu) + J4*Math.sin(8*mu);

 // Calculate Latitude and Longitude

 double e2 = Math.pow((e*a/b), 2);
 double C1 = Math.pow(e2*Math.cos(fp), 2);
 double T1 = Math.pow(Math.tan(fp), 2);
 double R1 = a*(1-Math.pow(e, 2))/Math.pow((1-Math.pow(e, 2)*Math.pow(Math.sin(fp), 2)), (3.0/2.0));
 double N1 = a/Math.pow((1-Math.pow(e, 2)*Math.pow(Math.sin(fp), 2)), 0.5);

 double D = x/(N1*k0);
 //double drad = Math.PI/180.0;

 // lat
 double Q1 = N1*Math.tan(fp)/R1;
 double Q2 = (Math.pow(D, 2)/2.0);
 double Q3 = (5 + 3*T1 + 10*C1 - 4*Math.pow(C1, 2) - 9*e2)*Math.pow(D, 4)/24.0;
 double Q4 = (61 + 90*T1 + 298*C1 + 45*Math.pow(T1, 2) - 3*Math.pow(C1, 2) - 252*e2)*Math.pow(D, 6)/720.0;
 double lat = Math.toDegrees(fp - Q1*(Q2 - Q3 + Q4));

 // long
 double Q5 = D;
 double Q6 = (1 + 2*T1 + C1)*Math.pow(D, 3)/6.0;
 double Q7 = (5 - 2*C1 + 28*T1 - 3*Math.pow(C1, 2) + 8*Math.pow(e2,2) + 24*Math.pow(T1, 2))*Math.pow(D, 5)/120.0;

 double lon = lon0 + Math.toDegrees((Q5 - Q6 + Q7)/Math.cos(fp));

 return new double[] {lat, lon};
 }

p.s example

double[] x = TWD97TM2toWGS84(300795.859, 2781073.746);
double[] x2 = WGS84toTWD97TM2( x[0], x[1]);
System.out.println(x[0] + ", " + x[1]);
System.out.println(x2[0] + ", " + x2[1]);

output
25.1372420521456, 121.5037851750446
300795.8619411328, 2781073.7458224166


p.s2 UNIT
UMT: meter
WGS84: degree

[記事] WGS84 轉 UMT (TWD97TM2)

 public double[] WGS84toTWD97TM2(double lat, double lon){
 // Ref1 : http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.htm
 // Ref2 : http://blog.ez2learn.com/2009/08/15/lat-lon-to-twd97/

 // convert from degrees to radians
 lat = Math.toRadians(lat);
 lon = Math.toRadians(lon);

 double a =  6378137.0;
 double b = 6356752.314245;
 double long0 = Math.toRadians(121);
 double k0 = 0.9999;
 double dx = 250000;

 double e = Math.sqrt(1- Math.pow(b, 2)/Math.pow(a,2));

 double e2 = Math.pow(e,2)/(1- Math.pow(e,2));

 double n = (a-b) / (a+b);

 double n2 = n*n;
 double n3 = n*n*n;
 double n4 = n*n*n*n;
 double n5 = n*n*n*n*n;

 double nu = a / Math.sqrt(1- Math.pow(e,2) * Math.pow(Math.sin(lat),2));

 double p = lon - long0;

 double A = a * (1 - n + (5/4.0)*(n2-n3) + (81/64.0)*(n4 - n5));
 double B = (3*a*n/2.0)*(1 - n + (7/8.0)*(n2 -n3) + (55/64.0)*(n4 - n5));
 double C = (15*a*n2/16.0)*(1 - n + (3/4.0)*(n2 - n3));
 double D = (35*a*n3/48.0)*(1 - n + (11/16.0)*(n2 - n3));
 double E = (315*a*n4/51.0)*(1-n);
 
 double S = A*lat - B*Math.sin(2*lat) + C*Math.sin(4*lat) - D*Math.sin(6*lat) + E*Math.sin(8*lat);

 double K1 = S*k0;
 double K2 = k0*nu*Math.sin(2*lat)/4.0;
 double K3 = (k0*nu*Math.sin(lat)*(Math.pow(Math.cos(lat),3)/24.0)) * (5 - Math.pow(Math.tan(lat), 2) + 9*e2*Math.pow(Math.cos(lat),2)) + 4*Math.pow(e2,2)*Math.pow(Math.cos(lat), 4);
 double y = K1+K2*Math.pow(p,2) + K3*Math.pow(p, 4);

 double K4 = k0*nu*Math.cos(lat);
 double K5 = (k0*nu*Math.pow(Math.cos(lat), 3)/6.0) * (1-Math.pow(Math.tan(lat),2) + e2*Math.pow(Math.cos(lat), 2));

 double x = K4*p + K5*Math.pow(p, 3) + dx;

 return new double[] {x,y};
 }