Is there an easy way to type in common math symbols?
Posted
by
srcspider
on Programmers
See other posts from Programmers
or by srcspider
Published on 2014-06-08T11:55:40Z
Indexed on
2014/06/08
15:42 UTC
Read the original article
Hit count: 324
Disclaimer: I'm sure someone is going to moan about easy-of-use, for the purpose of this question consider readability to be the only factor that matters
So I found this site that converts to easting northing, it's not really important what that even means but here's how the piece of javascript looks.
/**
* Convert Ordnance Survey grid reference easting/northing coordinate to (OSGB36) latitude/longitude
*
* @param {OsGridRef} gridref - easting/northing to be converted to latitude/longitude
* @returns {LatLonE} latitude/longitude (in OSGB36) of supplied grid reference
*/
OsGridRef.osGridToLatLong = function(gridref) {
var E = gridref.easting;
var N = gridref.northing;
var a = 6377563.396, b = 6356256.909; // Airy 1830 major & minor semi-axes
var F0 = 0.9996012717; // NatGrid scale factor on central meridian
var f0 = 49*Math.PI/180, ?0 = -2*Math.PI/180; // NatGrid true origin
var N0 = -100000, E0 = 400000; // northing & easting of true origin, metres
var e2 = 1 - (b*b)/(a*a); // eccentricity squared
var n = (a-b)/(a+b), n2 = n*n, n3 = n*n*n; // n, n², n³
var f=f0, M=0;
do {
f = (N-N0-M)/(a*F0) + f;
var Ma = (1 + n + (5/4)*n2 + (5/4)*n3) * (f-f0);
var Mb = (3*n + 3*n*n + (21/8)*n3) * Math.sin(f-f0) * Math.cos(f+f0);
var Mc = ((15/8)*n2 + (15/8)*n3) * Math.sin(2*(f-f0)) * Math.cos(2*(f+f0));
var Md = (35/24)*n3 * Math.sin(3*(f-f0)) * Math.cos(3*(f+f0));
M = b * F0 * (Ma - Mb + Mc - Md); // meridional arc
} while (N-N0-M >= 0.00001); // ie until < 0.01mm
var cosf = Math.cos(f), sinf = Math.sin(f);
var ? = a*F0/Math.sqrt(1-e2*sinf*sinf); // nu = transverse radius of curvature
var ? = a*F0*(1-e2)/Math.pow(1-e2*sinf*sinf, 1.5); // rho = meridional radius of curvature
var ?2 = ?/?-1; // eta = ?
var tanf = Math.tan(f);
var tan2f = tanf*tanf, tan4f = tan2f*tan2f, tan6f = tan4f*tan2f;
var secf = 1/cosf;
var ?3 = ?*?*?, ?5 = ?3*?*?, ?7 = ?5*?*?;
var VII = tanf/(2*?*?);
var VIII = tanf/(24*?*?3)*(5+3*tan2f+?2-9*tan2f*?2);
var IX = tanf/(720*?*?5)*(61+90*tan2f+45*tan4f);
var X = secf/?;
var XI = secf/(6*?3)*(?/?+2*tan2f);
var XII = secf/(120*?5)*(5+28*tan2f+24*tan4f);
var XIIA = secf/(5040*?7)*(61+662*tan2f+1320*tan4f+720*tan6f);
var dE = (E-E0), dE2 = dE*dE, dE3 = dE2*dE, dE4 = dE2*dE2, dE5 = dE3*dE2, dE6 = dE4*dE2, dE7 = dE5*dE2;
f = f - VII*dE2 + VIII*dE4 - IX*dE6;
var ? = ?0 + X*dE - XI*dE3 + XII*dE5 - XIIA*dE7;
return new LatLonE(f.toDegrees(), ?.toDegrees(), GeoParams.datum.OSGB36);
}
I found that to be a really nice way of writing an algorythm, at least as far as redability is concerned. Is there any way to easily write the special symbols. And by easily write I mean NOT copy/paste them.
© Programmers or respective owner