StelProjectorClasses.cpp   StelProjectorClasses.cpp 
skipping to change at line 32 skipping to change at line 32
#include <limits> #include <limits>
QString StelProjectorPerspective::getNameI18() const QString StelProjectorPerspective::getNameI18() const
{ {
return q_("Perspective"); return q_("Perspective");
} }
QString StelProjectorPerspective::getDescriptionI18() const QString StelProjectorPerspective::getDescriptionI18() const
{ {
return q_("Perspective projection keeps the horizon a straight line. The mathematical name for this projection method is <i>gnomonic projection </i>."); return q_("Perspective projection maps the horizon and other great c ircles like equator, ecliptic, hour lines, etc. into straight lines. The ma thematical name for this projection method is <i>gnomonic projection</i>.") ;
} }
bool StelProjectorPerspective::forward(Vec3f &v) const bool StelProjectorPerspective::forward(Vec3f &v) const
{ {
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
if (v[2] < 0) { if (v[2] < 0) {
v[0] /= (-v[2]); v[0] *= (-widthStretch/v[2]);
v[1] /= (-v[2]); v[1] /= (-v[2]);
v[2] = r; v[2] = r;
return true; return true;
} }
if (v[2] > 0) { if (v[2] > 0) {
v[0] /= v[2]; v[0] *= widthStretch/v[2];
v[1] /= v[2]; v[1] /= v[2];
v[2] = -std::numeric_limits<float>::max(); v[2] = -std::numeric_limits<float>::max();
return false; return false;
} }
v[0] = std::numeric_limits<float>::max(); v[0] = std::numeric_limits<float>::max();
v[1] = std::numeric_limits<float>::max(); v[1] = std::numeric_limits<float>::max();
v[2] = -std::numeric_limits<float>::max(); v[2] = -std::numeric_limits<float>::max();
return false; return false;
} }
bool StelProjectorPerspective::backward(Vec3d &v) const bool StelProjectorPerspective::backward(Vec3d &v) const
{ {
v[0] /= widthStretch;
v[2] = std::sqrt(1.0/(1.0+v[0]*v[0]+v[1]*v[1])); v[2] = std::sqrt(1.0/(1.0+v[0]*v[0]+v[1]*v[1]));
v[0] *= v[2]; v[0] *= v[2];
v[1] *= v[2]; v[1] *= v[2];
v[2] = -v[2]; v[2] = -v[2];
return true; return true;
} }
float StelProjectorPerspective::fovToViewScalingFactor(float fov) const float StelProjectorPerspective::fovToViewScalingFactor(float fov) const
{ {
return std::tan(fov); return std::tan(fov);
skipping to change at line 90 skipping to change at line 91
return vsf / (1.f+vsf*vsf); return vsf / (1.f+vsf*vsf);
} }
QString StelProjectorEqualArea::getNameI18() const QString StelProjectorEqualArea::getNameI18() const
{ {
return q_("Equal Area"); return q_("Equal Area");
} }
QString StelProjectorEqualArea::getDescriptionI18() const QString StelProjectorEqualArea::getDescriptionI18() const
{ {
return q_("The full name of this projection method is, <i>Lambert az imuthal equal-area projection</i>. It preserves the area but not the angle. "); return q_("The full name of this projection method is <i>Lambert azi muthal equal-area projection</i>. It preserves the area but not the angle." );
} }
bool StelProjectorEqualArea::forward(Vec3f &v) const bool StelProjectorEqualArea::forward(Vec3f &v) const
{ {
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const float f = std::sqrt(2.f/(r*(r-v[2]))); const float f = std::sqrt(2.f/(r*(r-v[2])));
v[0] *= f; v[0] *= f*widthStretch;
v[1] *= f; v[1] *= f;
v[2] = r; v[2] = r;
return true; return true;
} }
bool StelProjectorEqualArea::backward(Vec3d &v) const bool StelProjectorEqualArea::backward(Vec3d &v) const
{ {
v[0] /= widthStretch;
// FIXME: for high FoV, return false but don't cause crash with Mous e Pointer Coordinates. // FIXME: for high FoV, return false but don't cause crash with Mous e Pointer Coordinates.
const double dq = v[0]*v[0] + v[1]*v[1]; const double dq = v[0]*v[0] + v[1]*v[1];
double l = 1.0 - 0.25*dq; double l = 1.0 - 0.25*dq;
if (l < 0) if (l < 0)
{ {
v[0] = 0.0; v[0] = 0.0;
v[1] = 0.0; v[1] = 0.0;
v[2] = 1.0; v[2] = 1.0;
//return false; // GZ tentative fix for projecting invalid o utlying screen point. CAUSES CRASH SOMETIMES!? //return false; // GZ tentative fix for projecting invalid o utlying screen point. CAUSES CRASH SOMETIMES!?
} }
skipping to change at line 147 skipping to change at line 149
return fov; return fov;
} }
QString StelProjectorStereographic::getNameI18() const QString StelProjectorStereographic::getNameI18() const
{ {
return q_("Stereographic"); return q_("Stereographic");
} }
QString StelProjectorStereographic::getDescriptionI18() const QString StelProjectorStereographic::getDescriptionI18() const
{ {
return q_("Stereographic projection is known since the antiquity and was originally known as the planisphere projection. It preserves the angle s at which curves cross each other but it does not preserve area."); return q_("Stereographic projection is known since antiquity and was originally known as the planisphere projection. It preserves the angles at which curves cross each other but it does not preserve area.");
} }
bool StelProjectorStereographic::forward(Vec3f &v) const bool StelProjectorStereographic::forward(Vec3f &v) const
{ {
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const float h = 0.5f*(r-v[2]); const float h = 0.5f*(r-v[2]);
if (h <= 0.f) { if (h <= 0.f) {
v[0] = std::numeric_limits<float>::max(); v[0] = std::numeric_limits<float>::max();
v[1] = std::numeric_limits<float>::max(); v[1] = std::numeric_limits<float>::max();
v[2] = -std::numeric_limits<float>::min(); v[2] = -std::numeric_limits<float>::min();
return false; return false;
} }
const float f = 1.f / h; const float f = 1.f / h;
v[0] *= f; v[0] *= f*widthStretch;
v[1] *= f; v[1] *= f;
v[2] = r; v[2] = r;
return true; return true;
} }
bool StelProjectorStereographic::backward(Vec3d &v) const bool StelProjectorStereographic::backward(Vec3d &v) const
{ {
const double lqq = 0.25*(v[0]*v[0] + v[1]*v[1]); v[0] /= widthStretch;
v[2] = lqq - 1.0; const double lqq = 0.25*(v[0]*v[0] + v[1]*v[1]);
v *= (1.0 / (lqq + 1.0)); v[2] = lqq - 1.0;
return true; v *= (1.0 / (lqq + 1.0));
return true;
} }
float StelProjectorStereographic::fovToViewScalingFactor(float fov) const float StelProjectorStereographic::fovToViewScalingFactor(float fov) const
{ {
return 2.f * std::tan(0.5f * fov); return 2.f * std::tan(0.5f * fov);
} }
float StelProjectorStereographic::viewScalingFactorToFov(float vsf) const float StelProjectorStereographic::viewScalingFactorToFov(float vsf) const
{ {
return 2.f * std::atan(0.5f * vsf); return 2.f * std::atan(0.5f * vsf);
skipping to change at line 207 skipping to change at line 210
{ {
return q_("In fish-eye projection, or <i>azimuthal equidistant proje ction</i>, straight lines become curves when they appear a large angular di stance from the centre of the field of view (like the distortions seen with very wide angle camera lenses)."); return q_("In fish-eye projection, or <i>azimuthal equidistant proje ction</i>, straight lines become curves when they appear a large angular di stance from the centre of the field of view (like the distortions seen with very wide angle camera lenses).");
} }
bool StelProjectorFisheye::forward(Vec3f &v) const bool StelProjectorFisheye::forward(Vec3f &v) const
{ {
const float rq1 = v[0]*v[0] + v[1]*v[1]; const float rq1 = v[0]*v[0] + v[1]*v[1];
if (rq1 > 0.f) { if (rq1 > 0.f) {
const float h = std::sqrt(rq1); const float h = std::sqrt(rq1);
const float f = std::atan2(h,-v[2]) / h; const float f = std::atan2(h,-v[2]) / h;
v[0] *= f; v[0] *= f*widthStretch;
v[1] *= f; v[1] *= f;
v[2] = std::sqrt(rq1 + v[2]*v[2]); v[2] = std::sqrt(rq1 + v[2]*v[2]);
return true; return true;
} }
if (v[2] < 0.f) { if (v[2] < 0.f) {
v[0] = 0.f; v[0] = 0.f;
v[1] = 0.f; v[1] = 0.f;
v[2] = 1.f; v[2] = 1.f;
return true; return true;
} }
v[0] = std::numeric_limits<float>::max(); v[0] = std::numeric_limits<float>::max();
v[1] = std::numeric_limits<float>::max(); v[1] = std::numeric_limits<float>::max();
v[2] = std::numeric_limits<float>::min(); v[2] = std::numeric_limits<float>::min();
return false; return false;
} }
bool StelProjectorFisheye::backward(Vec3d &v) const bool StelProjectorFisheye::backward(Vec3d &v) const
{ {
v[0] /= widthStretch;
const double a = std::sqrt(v[0]*v[0]+v[1]*v[1]); const double a = std::sqrt(v[0]*v[0]+v[1]*v[1]);
const double f = (a > 0.0) ? (std::sin(a) / a) : 1.0; const double f = (a > 0.0) ? (std::sin(a) / a) : 1.0;
v[0] *= f; v[0] *= f;
v[1] *= f; v[1] *= f;
v[2] = -std::cos(a); v[2] = -std::cos(a);
return (a < M_PI); return (a < M_PI);
} }
float StelProjectorFisheye::fovToViewScalingFactor(float fov) const float StelProjectorFisheye::fovToViewScalingFactor(float fov) const
{ {
skipping to change at line 266 skipping to change at line 270
return q_("The Hammer projection is an equal-area map projection, de scribed by Ernst Hammer in 1892 and directly inspired by the Aitoff project ion."); return q_("The Hammer projection is an equal-area map projection, de scribed by Ernst Hammer in 1892 and directly inspired by the Aitoff project ion.");
} }
bool StelProjectorHammer::forward(Vec3f &v) const bool StelProjectorHammer::forward(Vec3f &v) const
{ {
// Hammer Aitoff // Hammer Aitoff
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const float alpha = std::atan2(v[0],-v[2]); const float alpha = std::atan2(v[0],-v[2]);
const float cosDelta = std::sqrt(1.f-v[1]*v[1]/(r*r)); const float cosDelta = std::sqrt(1.f-v[1]*v[1]/(r*r));
float z = std::sqrt(1.+cosDelta*std::cos(alpha/2.f)); float z = std::sqrt(1.+cosDelta*std::cos(alpha/2.f));
v[0] = 2.f*M_SQRT2*cosDelta*std::sin(alpha/2.f)/z; v[0] = 2.f*M_SQRT2*cosDelta*std::sin(alpha/2.f)/z * widthStretch;
v[1] = M_SQRT2*v[1]/r/z; v[1] = M_SQRT2*v[1]/r/z;
v[2] = r; v[2] = r;
return true; return true;
} }
bool StelProjectorHammer::backward(Vec3d &v) const bool StelProjectorHammer::backward(Vec3d &v) const
{ {
v[0] /= widthStretch;
const double zsq = 1.-0.25*0.25*v[0]*v[0]-0.5*0.5*v[1]*v[1]; const double zsq = 1.-0.25*0.25*v[0]*v[0]-0.5*0.5*v[1]*v[1];
const double z = zsq<0. ? 0. : std::sqrt(zsq); const double z = zsq<0. ? 0. : std::sqrt(zsq);
const bool ret = 0.25*v[0]*v[0]+v[1]*v[1]<2.0; // This is stolen fro m glunatic const bool ret = 0.25*v[0]*v[0]+v[1]*v[1]<2.0; // This is stolen fro m glunatic
const double alpha = 2.*std::atan2(z*v[0],(2.*(2.*zsq-1.))); const double alpha = 2.*std::atan2(z*v[0],(2.*(2.*zsq-1.)));
const double delta = std::asin(v[1]*z); const double delta = std::asin(v[1]*z);
const double cd = std::cos(delta); const double cd = std::cos(delta);
v[2] = - cd * std::cos(alpha); v[2] = - cd * std::cos(alpha);
v[0] = cd * std::sin(alpha); v[0] = cd * std::sin(alpha);
v[1] = v[1]*z; v[1] = v[1]*z;
return ret; return ret;
skipping to change at line 317 skipping to change at line 322
{ {
return q_("The full name of this projection mode is <i>cylindrical e quidistant projection</i>. With this projection all parallels are equally s paced."); return q_("The full name of this projection mode is <i>cylindrical e quidistant projection</i>. With this projection all parallels are equally s paced.");
} }
bool StelProjectorCylinder::forward(Vec3f &v) const bool StelProjectorCylinder::forward(Vec3f &v) const
{ {
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const bool rval = (-r < v[1] && v[1] < r); const bool rval = (-r < v[1] && v[1] < r);
const float alpha = std::atan2(v[0],-v[2]); const float alpha = std::atan2(v[0],-v[2]);
const float delta = std::asin(v[1]/r); const float delta = std::asin(v[1]/r);
v[0] = alpha; v[0] = alpha*widthStretch;
v[1] = delta; v[1] = delta;
v[2] = r; v[2] = r;
return rval; return rval;
} }
bool StelProjectorCylinder::backward(Vec3d &v) const bool StelProjectorCylinder::backward(Vec3d &v) const
{ {
v[0] /= widthStretch;
const bool rval = v[1]<M_PI_2 && v[1]>-M_PI_2 && v[0]>-M_PI && v[0]< M_PI; const bool rval = v[1]<M_PI_2 && v[1]>-M_PI_2 && v[0]>-M_PI && v[0]< M_PI;
const double cd = std::cos(v[1]); const double cd = std::cos(v[1]);
v[2] = - cd * std::cos(v[0]); const double alpha=v[0];
v[0] = cd * std::sin(v[0]); v[2] = - cd * std::cos(alpha);
v[0] = cd * std::sin(alpha);
v[1] = std::sin(v[1]); v[1] = std::sin(v[1]);
return rval; return rval;
} }
float StelProjectorCylinder::fovToViewScalingFactor(float fov) const float StelProjectorCylinder::fovToViewScalingFactor(float fov) const
{ {
return fov; return fov;
} }
float StelProjectorCylinder::viewScalingFactorToFov(float vsf) const float StelProjectorCylinder::viewScalingFactorToFov(float vsf) const
skipping to change at line 363 skipping to change at line 370
QString StelProjectorMercator::getDescriptionI18() const QString StelProjectorMercator::getDescriptionI18() const
{ {
return q_("The Mercator projection is one of the most used world map projections. It preserves direction and shapes but distorts size, in an in creasing degree away from the equator."); return q_("The Mercator projection is one of the most used world map projections. It preserves direction and shapes but distorts size, in an in creasing degree away from the equator.");
} }
bool StelProjectorMercator::forward(Vec3f &v) const bool StelProjectorMercator::forward(Vec3f &v) const
{ {
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const bool rval = (-r < v[1] && v[1] < r); const bool rval = (-r < v[1] && v[1] < r);
const float sin_delta = v[1]/r; const float sin_delta = v[1]/r;
v[0] = std::atan2(v[0],-v[2]); v[0] = std::atan2(v[0],-v[2]) *widthStretch;
v[1] = 0.5f*std::log((1.f+sin_delta)/(1.f-sin_delta)); v[1] = 0.5f*std::log((1.f+sin_delta)/(1.f-sin_delta));
v[2] = r; v[2] = r;
return rval; return rval;
} }
bool StelProjectorMercator::backward(Vec3d &v) const bool StelProjectorMercator::backward(Vec3d &v) const
{ {
const bool rval = v[1]<M_PI_2 && v[1]>-M_PI_2 && v[0]>-M_PI && v[0]< v[0] /= widthStretch;
M_PI; const bool rval = v[0]>-M_PI && v[0]<M_PI;
const double E = std::exp(v[1]); const double E = std::exp(v[1]);
const double h = E*E; const double h = E*E;
const double h1 = 1.0/(1.0+h); const double h1 = 1.0/(1.0+h);
const double sin_delta = (h-1.0)*h1; const double sin_delta = (h-1.0)*h1;
const double cos_delta = 2.0*E*h1; const double cos_delta = 2.0*E*h1;
v[2] = - cos_delta * std::cos(v[0]); v[2] = - cos_delta * std::cos(v[0]);
v[0] = cos_delta * std::sin(v[0]); v[0] = cos_delta * std::sin(v[0]);
v[1] = sin_delta; v[1] = sin_delta;
return rval; return rval;
} }
skipping to change at line 412 skipping to change at line 420
QString StelProjectorOrthographic::getDescriptionI18() const QString StelProjectorOrthographic::getDescriptionI18() const
{ {
return q_("Orthographic projection is related to perspective project ion, but the point of perspective is set to an infinite distance."); return q_("Orthographic projection is related to perspective project ion, but the point of perspective is set to an infinite distance.");
} }
bool StelProjectorOrthographic::forward(Vec3f &v) const bool StelProjectorOrthographic::forward(Vec3f &v) const
{ {
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const float h = 1.f/r; const float h = 1.f/r;
v[0] *= h; v[0] *= h *widthStretch;
v[1] *= h; v[1] *= h;
const bool rval = (v[2] <= 0.f); const bool rval = (v[2] <= 0.f);
v[2] = r; v[2] = r;
return rval; return rval;
} }
bool StelProjectorOrthographic::backward(Vec3d &v) const bool StelProjectorOrthographic::backward(Vec3d &v) const
{ {
v[0] /= widthStretch;
const double dq = v[0]*v[0] + v[1]*v[1]; const double dq = v[0]*v[0] + v[1]*v[1];
double h = 1.0 - dq; double h = 1.0 - dq;
if (h < 0) { if (h < 0) {
h = 1.0/std::sqrt(dq); h = 1.0/std::sqrt(dq);
v[0] *= h; v[0] *= h;
v[1] *= h; v[1] *= h;
v[2] = 0.0; v[2] = 0.0;
return false; return false;
} }
v[2] = -std::sqrt(h); v[2] = -std::sqrt(h);
skipping to change at line 465 skipping to change at line 474
{ {
return q_("The sinusoidal projection is a <i>pseudocylindrical equal -area map projection</i>, sometimes called the Sanson–Flamsteed or the Merc ator equal-area projection."); return q_("The sinusoidal projection is a <i>pseudocylindrical equal -area map projection</i>, sometimes called the Sanson–Flamsteed or the Merc ator equal-area projection.");
} }
bool StelProjectorSinusoidal::forward(Vec3f &v) const bool StelProjectorSinusoidal::forward(Vec3f &v) const
{ {
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const bool rval = (-r < v[1] && v[1] < r); const bool rval = (-r < v[1] && v[1] < r);
const float alpha = std::atan2(v[0],-v[2]); const float alpha = std::atan2(v[0],-v[2]);
const float delta = std::asin(v[1]/r); const float delta = std::asin(v[1]/r);
v[0] = alpha*std::cos(delta); v[0] = alpha*std::cos(delta) *widthStretch;
v[1] = delta; v[1] = delta;
v[2] = r; v[2] = r;
return rval; return rval;
} }
bool StelProjectorSinusoidal::backward(Vec3d &v) const bool StelProjectorSinusoidal::backward(Vec3d &v) const
{ {
v[0] /= widthStretch;
const bool rval = v[1]<M_PI_2 && v[1]>-M_PI_2 && v[0]>-M_PI && v[0]< M_PI; const bool rval = v[1]<M_PI_2 && v[1]>-M_PI_2 && v[0]>-M_PI && v[0]< M_PI;
const double cd = std::cos(v[1]); const double cd = std::cos(v[1]);
const double pcd = v[0]/cd; const double pcd = v[0]/cd;
if (v[0]<-M_PI*cd || v[0]>M_PI*cd) if (v[0]<-M_PI*cd || v[0]>M_PI*cd)
{ {
v[0] = -cd; v[0] = -cd;
v[1] = 1.0; v[1] = 1.0;
// FIXME: It is unclear what happens to v[2] here. // FIXME: It is unclear what happens to v[2] here.
v.normalize(); // make sure the length test in Atmosphere.cp p work. v.normalize(); // make sure the length test in Atmosphere.cp p work.
return false; return false;
} }
v[2] = -cd * std::cos(pcd); v[2] = -cd * std::cos(pcd);
v[0] = cd * std::sin(pcd); v[0] = cd * std::sin(pcd);
v[1] = std::sin(v[1]); v[1] = std::sin(v[1]);
return rval; return rval;
} }
QString StelProjectorMiller::getNameI18() const
{
return q_("Miller cylindrical");
}
QString StelProjectorMiller::getDescriptionI18() const
{
return q_("The Miller cylindrical projection is a modified Mercator
projection, proposed by Osborn Maitland Miller (1897–1979) in 1942. The pol
es are no longer mapped to infinity.");
}
bool StelProjectorMiller::forward(Vec3f &v) const
{
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const bool rval = (-r < v[1] && v[1] < r);
const float sin_delta = v[1]/r;
const float delta=asin(sin_delta);
v[0] = std::atan2(v[0],-v[2]) * widthStretch;
v[1] = 1.25f*asinh(tan(0.8f*delta));
v[2] = r;
return rval;
}
bool StelProjectorMiller::backward(Vec3d &v) const
{
v[0] /= widthStretch;
const double yMax=1.25f*asinh(tan(M_PI*2.0/5.0));
const bool rval = v[1]<yMax && v[1]>-yMax && v[0]>-M_PI && v[0]<M_PI
;
const double lat = 1.25*atan(sinh(0.8*v[1]));
const double lng = v[0];
const double cos_lat=cos(lat);
v[0] = cos_lat*sin(lng);
v[1] = sin(lat);
v[2]= -cos_lat*cos(lng);
return rval;
}
QString StelProjector2d::getNameI18() const QString StelProjector2d::getNameI18() const
{ {
return "2d"; return "2d";
} }
QString StelProjector2d::getDescriptionI18() const QString StelProjector2d::getDescriptionI18() const
{ {
return "Simple 2d projection for internal use."; return "Simple 2d projection for internal use.";
} }
 End of changes. 24 change blocks. 
21 lines changed or deleted 69 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/