int img_sample(img *p, const double *v, float *c) { const double lon = tolon(atan2(v[0], v[2])), lat = asin(v[1]); float klat = 1.f; float klon = 1.f; if (p->latc || p->lat0 || p->lat1) klat = (float) blend(p->lat0, p->lat1, angle(lat, p->latc)); if (p->lonc || p->lon0 || p->lon1) klon = (float) blend(p->lon0, p->lon1, angle(lon, p->lonc)); float k; int h = 0; if ((k = klat * klon)) { double t[2]; if (p->project(p, v, lon, lat, t)) { if ((h = img_linear(p, t, c))) { switch (p->c) { case 4: c[3] *= k; case 3: c[2] *= k; case 2: c[1] *= k; case 1: c[0] *= k; } } } } return h; }
int img_default(img *p, const double *v, double lon, double lat, double *t) { t[0] = p->h * (lat - p->minimum_latitude) / ( p->maximum_latitude - p->minimum_latitude); t[1] = p->w * tolon(lon - p->westernmost_longitude) / (p->easternmost_longitude - p->westernmost_longitude); return 1; }
virtual void tolatlon(double l, double s, double& lat, double& lon) const { double x; double y; toXY(l, s, x, y); double p = sqrt(x * x + y * y); double c = atan(radius * p / 2) * 2; lat = asin(cos(c) * sin(latp) + y * sin(c) * cos(latp) / p); if (latp > 0) lon = tolon(lonp + atan2(x, -y)); else lon = tolon(lonp + atan2(x, y)); }
int img_simple_cylindrical(img *p, const double *v, double lon, double lat, double *t) { #if 0 lon = tolon(lon - M_PI); #endif t[0] = p->line_projection_offset - p->map_resolution * (todeg(lat) - todeg( p->center_latitude)) - 1; // FIRST_PIXEL t[1] = p->sample_projection_offset + p->map_resolution * (todeg(lon) - todeg(p->center_longitude)) - 1; // FIRST_PIXEL return 1; }
virtual void tolatlon(double l, double s, double& lat, double& lon) const { double x; double y; toXY(l, s, x, y); double p = sqrt(x * x + y * y); double c = asin(p / radius); lat = asin(cos(c) * sin(latp) + y * sin(c) * cos(latp) / p); lon = tolon(lonp + atan2(x * sin(c), p * cos(c))); }
int img_locate(img *p, const double *v) { const double lon = tolon(atan2(v[0], v[2])), lat = asin(v[1]); double t[2]; if (p->project(p, v, lon, lat, t)) { if (0 <= t[0] && t[0] < p->h && 0 <= t[1] && t[1] < p->w) { return 1; } return 0; } return 0; }