Esempio n. 1
0
QString AngleMeasure::calculatePositionAngle(const Vec3d p1, const Vec3d p2) const
{
	double y = cos(p2.latitude())*sin(p2.longitude()-p1.longitude());
	double x = cos(p1.latitude())*sin(p2.latitude()) - sin(p1.latitude())*cos(p2.latitude())*cos(p2.longitude()-p1.longitude());
	double r = std::atan2(y,x);
	if (r<0)
		r+= 2*M_PI;

	unsigned int d, m;
	double s;
	bool sign;

	if (withDecimalDegree)
	{
		StelUtils::radToDecDeg(r, sign, s);
		if (flagUseDmsFormat)
			return QString("%1d").arg(s, 0, 'f', 5);
		else
			return QString("%1%2").arg(s, 0, 'f', 5).arg(QChar(0x00B0));
	}
	else
	{
		StelUtils::radToDms(r, sign, d, m, s);
		if (flagUseDmsFormat)
			return QString("%1d %2m %3s").arg(d).arg(m).arg(s, 0, 'f', 2);
		else
			return QString("%1%2 %3' %4\"").arg(d).arg(QChar(0x00B0)).arg(m).arg(s, 0, 'f', 2);
	}
}
QString AngleMeasure::calculatePositionAngle(const Vec3d p1, const Vec3d p2) const
{
	double y = cos(p2.latitude())*sin(p2.longitude()-p1.longitude());
	double x = cos(p1.latitude())*sin(p2.latitude()) - sin(p1.latitude())*cos(p2.latitude())*cos(p2.longitude()-p1.longitude());
	double r = std::atan(y/x);
	if (x<0)
		r += M_PI;
	if (y<0)
		r += 2*M_PI;
	if (r>(2*M_PI))
		r -= 2*M_PI;

	unsigned int d, m;
	double s;
	bool sign;
	StelUtils::radToDms(r, sign, d, m, s);
	if (flagUseDmsFormat)
		return QString("%1d %2m %3s").arg(d).arg(m).arg(s, 0, 'f', 2);
	else
		return QString("%1%2 %3' %4\"").arg(d).arg(QChar(0x00B0)).arg(m).arg(s, 0, 'f', 2);
}