New Zealand Map Grid Forward  - long/lat to x/y
long/lat in radians
509350
public function forward($p)
    {
        $lon = $p->x;
        $lat = $p->y;

        $delta_lat = $lat - $this->lat0;
        $delta_lon = $lon - $this->long0;

        // 1. Calculate d_phi and d_psi    ...                          // and d_lambda
        // For this algorithm, delta_latitude is in seconds of arc x 10-5, so we need to scale to those units. Longitude is radians.
        $d_phi = $delta_lat / Common::SEC_TO_RAD * 1E-5;
        $d_lambda = $delta_lon;
        $d_phi_n = 1;  // d_phi^0

        $d_psi = 0;

        for ($n = 1; $n <= 10; $n++) {
            $d_phi_n = $d_phi_n * $d_phi;
            $d_psi = $d_psi + $this->A[$n] * $d_phi_n;
        }

        // 2. Calculate theta
        $th_re = $d_psi;
        $th_im = $d_lambda;

        // 3. Calculate z
        $th_n_re = 1;
        $th_n_im = 0;  // theta^0
        #$th_n_re1;
        #$th_n_im1;

        $z_re = 0;
        $z_im = 0;

        for ($n = 1; $n <= 6; $n++) {
            $th_n_re1 = $th_n_re * $th_re - $th_n_im * $th_im;
            $th_n_im1 = $th_n_im * $th_re + $th_n_re * $th_im;
            $th_n_re = $th_n_re1;
            $th_n_im = $th_n_im1;
            $z_re = $z_re + $this->B_re[$n] * $th_n_re - $this->B_im[$n] * $th_n_im;
            $z_im = $z_im + $this->B_im[$n] * $th_n_re + $this->B_re[$n] * $th_n_im;
        }

        // 4. Calculate easting and northing
        $p->x = ($z_im * $this->a) + $this->x0;
        $p->y = ($z_re * $this->a) + $this->y0;

        return $p;
    }
1097608
def to_lat_lon
      k0 = 0.9996
      x  = @e - 500000 # Remove Longitude offset
      y  = @n

      # Set hemisphere (1=Northern, 0=Southern)
      y    -= 10000000.0 unless UTMZones::northern_hemisphere? @zone

      ecc = @ellipsoid.eccentricity
      eccPrimeSquared = (ecc)/(1-ecc)
      m  = y / k0
      mu = m / (@ellipsoid.radius * (1 - ecc / 4 - 3 * ecc ** 2 / 64 - 5 * ecc ** 3 / 256))
      e1 = (1 - Math::sqrt(1 - ecc)) / (1 + Math::sqrt(1 - ecc))
      phi1rad = mu +
        (3 * e1 / 2 - 27 * e1 ** 3 / 32) * Math::sin(2 * mu) +
        (21 * e1 ** 2 / 16 - 55 * e1 ** 4 / 32) * Math::sin(4 * mu) +
        (151 * e1 ** 3 / 96) * Math::sin(6 * mu)
      n1 = @ellipsoid.radius / Math::sqrt(1 - ecc * Math::sin(phi1rad) ** 2)
      t1 = Math::tan(phi1rad) ** 2
      c1 = ecc * Math::cos(phi1rad)**2
      r1 = @ellipsoid.radius * (1 - ecc) / ((1 - ecc * Math::sin(phi1rad) ** 2) ** 1.5)
      d = x / (n1 * k0)
      latitude_rad = phi1rad-
        (n1 * Math::tan(phi1rad) / r1) * (d * d / 2 - 
                                    (5 + 3 * t1 + 10 * c1 - 4 * c1 * c1 - 9 * eccPrimeSquared) * d ** 4 / 24 +
                                    (61 + 90 * t1 + 298 * c1 + 45 * t1 * t1 - 
                                     252 * eccPrimeSquared - 3 * c1 * c1) * d ** 6 / 720)
      latitude_deg = latitude_rad * 180.0 / Math::PI
      lon_tmp = (d - (1 + 2 * t1 + c1) * d ** 3 / 6 +
                   (5 - 2 * c1 + 28 * t1 - 3 * c1 * c1 + 8 * eccPrimeSquared +
                    24 * t1 * t1) * d ** 5 / 120) / Math::cos(phi1rad)
      longitude_deg = UTMZones::lon_origin(@zone) + lon_tmp * 180.0 / Math::PI
      LatLon.new latitude_deg, longitude_deg
    end
1131446
private int pointToGridIdx(Grid grid, float x, float y, float z) {
        Vec3f size = grid.getSize();

        int idx = calcIndex(x, size.getX(), grid.getMin().getX(), grid.getDivision().getX());
        int idy = calcIndex(y, size.getY(), grid.getMin().getY(), grid.getDivision().getY());
        int idz = calcIndex(z, size.getZ(), grid.getMin().getZ(), grid.getDivision().getZ());

        return idx + grid.getDivision().getX() * (idy + grid.getDivision().getY() * idz);
    }
980332
function positionToGeographic(position) {
    var x = position[0];
    var y = position[1];
    return [radToDeg(x / EarthRadius) - (Math.floor((radToDeg(x / EarthRadius) + 180) / 360) * 360), radToDeg((Math.PI / 2) - (2 * Math.atan(Math.exp(-1.0 * y / EarthRadius))))];
  }
1083191
def _format_lat(self, lat):
        '''  '''
        if self.ppd in [4, 16, 64, 128]:
            return None
        else:
            if lat < 0:
                return map(lambda x: "{0:0>2}"
                           .format(int(np.abs(x))) + 'S', self._map_center('lat', lat))
            else:
                return map(lambda x: "{0:0>2}"
                           .format(int(x)) + 'N', self._map_center('lat', lat))
201821
def screen_to_latlon(self, x, y):
        
        xtile = 1. * x / TILE_SIZE + self.xtile
        ytile = 1. * y / TILE_SIZE + self.ytile
        return self.num2deg(xtile, ytile, self.zoom)
370173
function forward$2(p) {
        var lon = p.x;
        var lat = p.y;

        var delta_lon = adjust_lon(lon - this.long0);
        var con;
        var x, y;
        var sin_phi = Math.sin(lat);
        var cos_phi = Math.cos(lat);

        if (!this.es) {
            var b = cos_phi * Math.sin(delta_lon);

            if ((Math.abs(Math.abs(b) - 1)) < EPSLN) {
                return (93);
            }
            else {
                x = 0.5 * this.a * this.k0 * Math.log((1 + b) / (1 - b)) + this.x0;
                y = cos_phi * Math.cos(delta_lon) / Math.sqrt(1 - Math.pow(b, 2));
                b = Math.abs(y);

                if (b >= 1) {
                    if ((b - 1) > EPSLN) {
                        return (93);
                    }
                    else {
                        y = 0;
                    }
                }
                else {
                    y = Math.acos(y);
                }

                if (lat < 0) {
                    y = -y;
                }

                y = this.a * this.k0 * (y - this.lat0) + this.y0;
            }
        }
        else {
            var al = cos_phi * delta_lon;
            var als = Math.pow(al, 2);
            var c = this.ep2 * Math.pow(cos_phi, 2);
            var cs = Math.pow(c, 2);
            var tq = Math.abs(cos_phi) > EPSLN ? Math.tan(lat) : 0;
            var t = Math.pow(tq, 2);
            var ts = Math.pow(t, 2);
            con = 1 - this.es * Math.pow(sin_phi, 2);
            al = al / Math.sqrt(con);
            var ml = pj_mlfn(lat, sin_phi, cos_phi, this.en);

            x = this.a * (this.k0 * al * (1 +
                als / 6 * (1 - t + c +
                als / 20 * (5 - 18 * t + ts + 14 * c - 58 * t * c +
                als / 42 * (61 + 179 * ts - ts * t - 479 * t))))) +
                this.x0;

            y = this.a * (this.k0 * (ml - this.ml0 +
                sin_phi * delta_lon * al / 2 * (1 +
                als / 12 * (5 - t + 9 * c + 4 * cs +
                als / 30 * (61 + ts - 58 * t + 270 * c - 330 * t * c +
                als / 56 * (1385 + 543 * ts - ts * t - 3111 * t)))))) +
                this.y0;
        }

        p.x = x;
        p.y = y;

        return p;
    }
670684
def coord_to_pixel(self, lat, lon, width, ground_width, lat2, lon2):
		''''''
		pixel_width = ground_width / float(width)

		if lat is None or lon is None or lat2 is None or lon2 is None:
			return (0,0)

		dx = mp_util.gps_distance(lat, lon, lat, lon2)
		if lon2 < lon:
			dx = -dx
		dy = mp_util.gps_distance(lat, lon, lat2, lon)
		if lat2 > lat:
			dy = -dy

		dx /= pixel_width
		dy /= pixel_width
		return (int(dx), int(dy))
147832
function getGridOffsets(directions, grid, opt) {

        var step = opt.step;

        util.toArray(opt.directions).forEach(function(direction) {

            direction.gridOffsetX = (direction.offsetX / step) * grid.x;
            direction.gridOffsetY = (direction.offsetY / step) * grid.y;
        });
    }
1349183
function forward$20(p) {
        var x, y;
        var lon = p.x;
        var lat = p.y;
        /* Forward equations
         -----------------*/
        lon = adjust_lon(lon - this.long0);

        if (this.sphere) {
            if (!this.m) {
                lat = this.n !== 1 ? Math.asin(this.n * Math.sin(lat)) : lat;
            }
            else {
                var k = this.n * Math.sin(lat);
                for (var i = MAX_ITER$3; i; --i) {
                    var V = (this.m * lat + Math.sin(lat) - k) / (this.m + Math.cos(lat));
                    lat -= V;
                    if (Math.abs(V) < EPSLN) {
                        break;
                    }
                }
            }
            x = this.a * this.C_x * lon * (this.m + Math.cos(lat));
            y = this.a * this.C_y * lat;

        }
        else {

            var s = Math.sin(lat);
            var c = Math.cos(lat);
            y = this.a * pj_mlfn(lat, s, c, this.en);
            x = this.a * lon * c / Math.sqrt(1 - this.es * s * s);
        }

        p.x = x;
        p.y = y;
        return p;
    }
670970
function emitHeatmapCoordinates() {
        if(coordinates.length > 0) {
            ceddl.emitEvent('heatmap:update', {
                width: windowWidth,
                coordinates: coordinates.splice(0, coordinates.length)
            });
        }
        windowWidth = Math.round(parseInt(window.innerWidth, 10));
    }
425717
def make_grid_transformed(numPix, Mpix2Angle):
    
    x_grid, y_grid = make_grid(numPix, deltapix=1)
    ra_grid, dec_grid = map_coord2pix(x_grid, y_grid, 0, 0, Mpix2Angle)
    return ra_grid, dec_grid
147734
def gridSnap(point, grid=1.0):
    """"""
    def snapFunc(value):
        value += 0.000001 # ensure values that are close to a half grid value round up
        remainder = value%grid
        value -= remainder
        newAdd = round(remainder/grid)*grid
        return value + newAdd
    return MapPoint( snapFunc(point.x) ,
                     snapFunc(point.y) )
128655
def cprNL(lat):
    """"""

    if lat == 0:
        return 59

    if lat == 87 or lat == -87:
        return 2

    if lat > 87 or lat < -87:
        return 1

    nz = 15
    a = 1 - np.cos(np.pi / (2 * nz))
    b = np.cos(np.pi / 180.0 * abs(lat)) ** 2
    nl = 2 * np.pi / (np.arccos(1 - a/b))
    NL = floor(nl)
    return NL
181724
function(data) {
        var toLat = coordinate.format(data.to.lat, 'lat');
        var toLon = coordinate.format(data.to.lon, 'lon');

        var parts = ["IIRMB",
            "A",
            data.xte.toFixed(2),
            data.dts,
            data.to.name,
            data.from.name,
            toLat[0],
            toLat[1],
            toLon[0],
            toLon[1],
            data.dtw.toFixed(1),
            data.btw.toFixed(0),
            data.vmgw.toFixed(2),
            'V'
        ];

        return parts.join(',');
    }
786475
def inc_from_lat(lat):
    
    rad = old_div(np.pi, 180.)
    inc = old_div(np.arctan(2 * np.tan(lat * rad)), rad)
    return inc
481446
function (latitude) {
                return Math.log(Math.tan(Math.PI / 4 + (latitude * Angle.DEGREES_TO_RADIANS) / 2)) / Math.PI;
            }