1 /* 2 SPDX-FileCopyrightText: 2021 Hy Murveit <hy@murveit.com> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #pragma once 8 9 #include <QPointF> 10 11 namespace Rotations 12 { 13 14 // Like QVector3D but double precision. 15 class V3 16 { 17 public: V3(double x,double y,double z)18 V3(double x, double y, double z) : X(x), Y(y), Z(z) {}; V3()19 V3() : X(0.0), Y(0.0), Z(0.0) {}; x()20 double x() const 21 { 22 return X; 23 } y()24 double y() const 25 { 26 return Y; 27 } z()28 double z() const 29 { 30 return Z; 31 } 32 static V3 normal(const V3 &v1, const V3 &v2, const V3 &v3); 33 double length(); 34 private: 35 double X, Y, Z; 36 }; 37 38 // Convert degrees to radians and vica versa. 39 double d2r(double degrees); 40 double r2d(double radians); 41 42 // With 2 args, get the axis of rotation defined by 2 points on a sphere 43 // (the 3rd point is assumed to be the center of the sphere) 44 // So the rotation is along the geodesic defined by the two points and the center. 45 // With all three args, find the axis defined by those 3 points. 46 V3 getAxis(const V3 &p1, const V3 &p2, const V3 &p3 = V3(0.0, 0.0, 0.0)); 47 48 // Gets the angle between 2 points on a sphere from the point of view of the 49 // center of the sphere. 50 double getAngle(const V3 &p1, const V3 &p2); 51 52 // Rotates the point around the unit vector axis (must be a unit vector to work) 53 // by degrees. 54 V3 rotateAroundAxis(const V3 &point, const V3 &axis, double degrees); 55 V3 rotateAroundY(const V3 &point, double degrees); 56 57 // Converts the AzAlt (azimuth is in .x(), altitude in .y()) 58 // to an xyz point, and vica versa. 59 V3 azAlt2xyz(const QPointF &azAlt); 60 QPointF xyz2azAlt(const V3 &xyz); 61 62 // Converts an xyz point to HA and DEC (ha is in .x(), dec in .y()) 63 // and vica versa. 64 QPointF xyz2haDec(const V3 &xyz, double latitude); 65 V3 haDec2xyz(const QPointF &haDec, double latitude); 66 67 // Rotate the az/alt point. Used when assisting the user to correct a polar alignment error. 68 // Input is the point to be rotated, Azimuth = azAltPoint.x(), Altitude = azAltPoint.y(). 69 // azAltRotation: the rotation angles, which correspond to the error in polar alignment 70 // that we would like to correct at the pole. The returned QPointF is the rotated azimuth 71 // and altitude coordinates. 72 QPointF rotateRaAxis(const QPointF &azAltPoint, const QPointF &azAltRotation); 73 74 } // namespace rotations 75