File indexing completed on 2024-04-14 03:46:56

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2014 Gerhard Holtkamp
0004 //
0005 
0006 #if !defined(__attlib_h)
0007 #define __attlib_h
0008 
0009 /***********************************************************************
0010     3-Dim Vector and Matrix Definitions and Operations
0011 
0012   License: GNU LGPL Version 2+
0013 
0014   Author: Gerhard HOLTKAMP                   14-JAN-2012
0015  ***********************************************************************/
0016 
0017 #include <iostream>
0018 #include "astrolib_export.h"
0019 
0020 
0021 ASTROLIB_EXPORT double atan20 (double y, double x);
0022 
0023 class ASTROLIB_EXPORT Vec3
0024 {
0025  private:
0026    double v[3];
0027 
0028  public:
0029 
0030    friend class Mat3;
0031 
0032    Vec3(double x=0, double y=0, double z=0);
0033    Vec3 (const Vec3& c);
0034    void assign (double x=0, double y=0, double z=0);
0035    double& operator [] (unsigned index);
0036    Vec3& operator = (const Vec3& c);
0037    Vec3& operator += (const Vec3& c);
0038    Vec3& operator -= (const Vec3& c);
0039    Vec3& operator *= (const Vec3& c);   // cross product
0040    Vec3& operator *= (double r);
0041    Vec3& operator /= (double r);
0042    friend double abs(const Vec3& c);               // absolute value
0043    friend double dot (const Vec3& c1, const Vec3& c2);   // dot product
0044    friend Vec3 operator + (const Vec3& c1, const Vec3& c2);
0045    friend Vec3 operator - (const Vec3& c1, const Vec3& c2);
0046    friend Vec3 operator * (double r, const Vec3& c1);
0047    friend Vec3 operator * (const Vec3& c1, double r);
0048    friend Vec3 operator * (const Vec3& c1, const Vec3& c2);  // cross product
0049    friend Vec3 operator / (const Vec3& c1, double r);
0050    friend Vec3 vnorm(const Vec3& c);       // norm vector
0051    friend Vec3 carpol (const Vec3& c);    // Cartesian -> Polar
0052    friend Vec3 polcar (const Vec3& c);    // Polar -> Cartesian
0053    friend std::ostream& operator << (std::ostream& os, const Vec3& c);
0054 };
0055 
0056 /********************************************************************/
0057 
0058 // class Mat3: public Vec3
0059 class ASTROLIB_EXPORT Mat3
0060 {
0061  public:
0062    double m[3][3];
0063 
0064    explicit Mat3(double x=0);
0065    Mat3 (const Mat3& c);
0066    void assign (double x11, double x12, double x13,  double x21, double x22,
0067                 double x23, double x31, double x32, double x33);
0068    void assign (double x[3][3]);             // assign matrix
0069    void PutMij (double x, int i, int j);    // put single matrix element
0070    double GetMij (int i, int j);            // get single matrix element
0071    Mat3& operator = (const Mat3& c);
0072    Mat3& operator += (const Mat3& c);
0073    Mat3& operator -= (const Mat3& c);
0074    Mat3& operator *= (const Mat3& c);
0075    Mat3& operator *= (double r);
0076    Mat3& operator /= (double r);
0077    friend Mat3 mxtrn (const Mat3& m1);  // transposed matrix
0078    friend double mxdet (const Mat3& c); // determinant
0079    friend Mat3 operator + (const Mat3& c1, const Mat3& c2);
0080    friend Mat3 operator - (const Mat3& c1, const Mat3& c2);
0081    friend Mat3 operator * (double r, const Mat3& c1);
0082    friend Mat3 operator * (const Mat3& c1, double r);
0083    friend Mat3 operator * (const Mat3& c1, const Mat3& c2);
0084    friend Mat3 operator / (const Mat3& c1, double r);
0085    friend Vec3 mxvct (const Mat3& m1, Vec3& v1);  // multiply vector with matrix
0086    friend void gpyr (const Mat3& m1, double& p, double& y, double& r); // get p/y/r
0087    friend void mxevc (const Mat3& m, double& a, Vec3& v);  // eigenvector
0088    friend std::ostream& operator << (std::ostream& os, const Mat3& c);
0089 };
0090 
0091 //  ****************************************************************************
0092 // defining the following functions here seems to make more compilers happy
0093    Mat3 mxcon (double r);  // constant matrix
0094    Mat3 mxidn ();          // identity matrix
0095     //  friend Mat3 mxtrn (const Mat3& m1);  // transposed matrix
0096    Mat3 xrot (double a);  // rotation around x-axis
0097    Mat3 yrot (double a);  // rotation around y-axis
0098    Mat3 zrot (double a);  // rotation around z-axis
0099 
0100    Mat3 csmx (double p, double y, double r); // pitch/yaw/roll matrix
0101    void vcpy (Vec3& v, double& p, double& y); // get pitch and yaw from vector
0102    void vcrp (Vec3& v, double& p, double& r); // get pitch and roll from vector
0103    Mat3 mxrox (double& a, Vec3& v);  // get matrix from eigenvector and angle
0104 
0105 #endif         // __attlib_h sentry.
0106