Well flattening it can be useful when you want it to fit a flat screen. Here’s a little code from an old project of mine. Does this make me a flat earther?
function MapLatLonToXY($phi, $lambda, $lambda0)
{
$N; $nu2; $ep2; $t; $t2; $l;
$l3coef; $l4coef; $l5coef; $l6coef; $l7coef; $l8coef;
$tmp;
/* Precalculate ep2 */
$ep2 = (pow($GLOBALS[‘sm_a’], 2.0) - pow($GLOBALS[‘sm_b’], 2.0)) / pow($GLOBALS[‘sm_b’], 2.0);
/* Precalculate nu2 */
$nu2 = $ep2 * pow (cos($phi), 2.0);
/* Precalculate N */
$N = pow($GLOBALS[‘sm_a’], 2.0) / ($GLOBALS[‘sm_b’] * sqrt(1 + $nu2));
/* Precalculate t */
$t = tan($phi);
$t2 = $t * $t;
$tmp = ($t2 * $t2 * $t2) - pow($t, 6.0);
/* Precalculate l */
$l = $lambda - $lambda0;
/* Precalculate coefficients for l**n in the equations below
so a normal human being can read the expressions for easting
and northing
— l*1 and l2 have coefficients of 1.0/
$l3coef = 1.0 - $t2 + $nu2;
$l4coef = 5.0 - $t2 + 9 * $nu2 + 4.0 * ($nu2 * $nu2);
$l5coef = 5.0 - 18.0 * $t2 + ($t2 * $t2) + 14.0 * $nu2
$l6coef = 61.0 - 58.0 * $t2 + ($t2 * $t2) + 270.0 * $nu2
$l7coef = 61.0 - 479.0 * $t2 + 179.0 * ($t2 * $t2) - ($t2 * $t2 * $t2);
$l8coef = 1385.0 - 3111.0 * $t2 + 543.0 * ($t2 * $t2) - ($t2 * $t2 * $t2);
/* Calculate easting (x) */
$xy;
$xy[0] = $N * cos($phi) * $l
- ($N / 6.0 * pow (cos ($phi), 3.0) * $l3coef * pow($l, 3.0))
- ($N / 120.0 * pow (cos ($phi), 5.0) * $l5coef * pow($l, 5.0))
- ($N / 5040.0 * pow (cos ($phi), 7.0) * $l7coef * pow($l, 7.0));
/* Calculate northing (y) */
$xy[1] = ArcLengthOfMeridian($phi)
- ($t / 2.0 * $N * pow(cos($phi), 2.0) * pow($l, 2.0))
- ($t / 24.0 * $N * pow(cos($phi), 4.0) * $l4coef * pow($l, 4.0))
- ($t / 720.0 * $N * pow(cos($phi), 6.0) * $l6coef * pow($l, 6.0))
- ($t / 40320.0 * $N * pow(cos($phi), 8.0) * $l8coef * pow($l, 8.0));
return $xy;
}
Edit: man the formatting went to heck.