Is there any known java library which allows me to convert WGS 84 cords to OSGB36 or if there is a good formula I can use? I am currently using this one, but it's not very accurate so I'm wondering if there's a better one I can use.
private static double[] Wgs84ToBNG(double inLat, double inLon) {
double lat = inLat * Math.PI / 180.0;
double lon = inLon * Math.PI / 180.0;
double a = 6377563.396; // Airy 1830 major & minor semi-axes
double b = 6356256.910;
double F0 = 0.9996012717; // NatGrid scale factor on central meridian
double lat0 = 49 * Math.PI / 180.0; // NatGrid true origin
double lon0 = -2 * Math.PI / 180.0;
double N0 = -100000; // northing & easting of true origin, metres
double E0 = 400000;
double e2 = 1 - (b * b) / (a * a); // eccentricity squared
double n = (a - b) / (a + b), n2 = n * n, n3 = n * n * n;
double cosLat = Math.cos(lat), sinLat = Math.sin(lat);
double nu = a * F0 / Math.sqrt(1 - e2 * sinLat * sinLat); // transverse
// radius of
// curvature
double rho = a * F0 * (1 - e2)
/ Math.pow(1 - e2 * sinLat * sinLat, 1.5); // meridional radius
// of curvature
double eta2 = nu / rho - 1;
double Ma = (1 + n + (5 / 4) * n2 + (5 / 4) * n3) * (lat - lat0);
double Mb = (3 * n + 3 * n * n + (21 / 8) * n3) * Math.sin(lat - lat0)
* Math.cos(lat + lat0);
double Mc = ((15 / 8) * n2 + (15 / 8) * n3)
* Math.sin(2 * (lat - lat0)) * Math.cos(2 * (lat + lat0));
double Md = (35 / 24) * n3 * Math.sin(3 * (lat - lat0))
* Math.cos(3 * (lat + lat0));
double M = b * F0 * (Ma - Mb + Mc - Md); // meridional arc
double cos3lat = cosLat * cosLat * cosLat;
double cos5lat = cos3lat * cosLat * cosLat;
double tan2lat = Math.tan(lat) * Math.tan(lat);
double tan4lat = tan2lat * tan2lat;
double I = M + N0;
double II = (nu / 2) * sinLat * cosLat;
double III = (nu / 24) * sinLat * cos3lat * (5 - tan2lat + 9 * eta2);
double IIIA = (nu / 720) * sinLat * cos5lat
* (61 - 58 * tan2lat + tan4lat);
double IV = nu * cosLat;
double V = (nu / 6) * cos3lat * (nu / rho - tan2lat);
double VI = (nu / 120)
* cos5lat
* (5 - 18 * tan2lat + tan4lat + 14 * eta2 - 58 * tan2lat * eta2);
double dLon = lon - lon0;
double dLon2 = dLon * dLon;
double dLon3 = dLon2 * dLon;
double dLon4 = dLon3 * dLon;
double dLon5 = dLon4 * dLon;
double dLon6 = dLon5 * dLon;
double N = I + II * dLon2 + III * dLon4 + IIIA * dLon6;
double E = E0 + IV * dLon + V * dLon3 + VI * dLon5;
double[] returnValue = { E, N };
return returnValue;
}