1 /***************************************************************************
2   qgsray3d.h
3   --------------------------------------
4   Date                 : January 2021
5   Copyright            : (C) 2021 by Belgacem Nedjima
6   Email                : belgacem dot nedjima at gmail dot com
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 #ifndef QGSRAY3D_H
16 #define QGSRAY3D_H
17 
18 #include "qgsbox3d.h"
19 
20 #include <QVector3D>
21 
22 /**
23  * \ingroup core
24  * \brief A representation of a ray in 3D.
25  *
26  * A ray is composed of an origin point (the start of the ray) and a direction vector.
27  *
28  * \since QGIS 3.18
29  */
30 class CORE_EXPORT QgsRay3D
31 {
32   public:
33 
34     /**
35      * Constructor
36      * \note : the direction is automatically normalized
37      */
38     QgsRay3D( const QVector3D &origin, const QVector3D &direction );
39 
40     /**
41      * Returns the origin of the ray
42      * \see setOrigin()
43      */
origin()44     QVector3D origin() const { return mOrigin; }
45 
46     /**
47      * Returns the direction of the ray
48      * see setDirection()
49      */
direction()50     QVector3D direction() const { return mDirection; }
51 
52     /**
53      * Sets the origin of the ray
54      * \see origin()
55      */
56     void setOrigin( const QVector3D &origin );
57 
58     /**
59      * Sets the direction of the ray
60      * \note : the direction is automatically normalized
61      * \see direction()
62      */
63     void setDirection( const QVector3D direction );
64 
65     /**
66      * Returns the projection of the point on the ray
67      * (which is the closest point of the ray to \a point)
68      */
69     QVector3D projectedPoint( const QVector3D &point ) const;
70     //! Checks whether the point is in front of the ray
71     bool isInFront( const QVector3D &point ) const;
72     //! Returns the angle between the ray and the vector from the ray's origin and the point \a point
73     double angleToPoint( const QVector3D &point ) const;
74 
75   private:
76     QVector3D mOrigin;
77     QVector3D mDirection;
78 };
79 
80 #endif // QGSRAY3D_H
81