File indexing completed on 2024-04-28 15:09:05

0001 /*
0002     SPDX-FileCopyrightText: 2021 Hy Murveit <hy@murveit.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QPointF>
0010 
0011 namespace Rotations
0012 {
0013 
0014 // Like QVector3D but double precision.
0015 class V3
0016 {
0017     public:
0018         V3(double x, double y, double z) : X(x), Y(y), Z(z) {};
0019         V3() : X(0.0), Y(0.0), Z(0.0) {};
0020         double x() const
0021         {
0022             return X;
0023         }
0024         double y() const
0025         {
0026             return Y;
0027         }
0028         double z() const
0029         {
0030             return Z;
0031         }
0032         static V3 normal(const V3 &v1, const V3 &v2, const V3 &v3);
0033         double length();
0034     private:
0035         double X, Y, Z;
0036 };
0037 
0038 // Convert degrees to radians and vica versa.
0039 double d2r(double degrees);
0040 double r2d(double radians);
0041 
0042 // With 2 args, get the axis of rotation defined by 2 points on a sphere
0043 // (the 3rd point is assumed to be the center of the sphere)
0044 // So the rotation is along the geodesic defined by the two points and the center.
0045 // With all three args, find the axis defined by those 3 points.
0046 V3 getAxis(const V3 &p1, const V3 &p2, const V3 &p3 = V3(0.0, 0.0, 0.0));
0047 
0048 // Gets the angle between 2 points on a sphere from the point of view of the
0049 // center of the sphere.
0050 double getAngle(const V3 &p1, const V3 &p2);
0051 
0052 // Rotates the point around the unit vector axis (must be a unit vector to work)
0053 // by degrees.
0054 V3 rotateAroundAxis(const V3 &point, const V3 &axis, double degrees);
0055 V3 rotateAroundY(const V3 &point, double degrees);
0056 V3 rotateAroundZ(const V3 &point, double degrees);
0057 
0058 // Converts the AzAlt (azimuth is in .x(), altitude in .y())
0059 // to an xyz point, and vica versa.
0060 V3 azAlt2xyz(const QPointF &azAlt);
0061 QPointF xyz2azAlt(const V3 &xyz);
0062 
0063 // Converts an xyz point to HA and DEC (ha is in .x(), dec in .y())
0064 // and vica versa.
0065 QPointF xyz2haDec(const V3 &xyz, double latitude);
0066 V3 haDec2xyz(const QPointF &haDec, double latitude);
0067 
0068 // Rotate the az/alt point. Used when assisting the user to correct a polar alignment error.
0069 // Input is the point to be rotated, Azimuth = azAltPoint.x(), Altitude = azAltPoint.y().
0070 // azAltRotation: the rotation angles, which correspond to the error in polar alignment
0071 // that we would like to correct at the pole. The returned QPointF is the rotated azimuth
0072 // and altitude coordinates.
0073 QPointF rotateRaAxis(const QPointF &azAltPoint, const QPointF &azAltRotation);
0074 
0075 }  // namespace rotations