QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsray3d.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsray3d.cpp
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#include "qgsray3d.h"
16
17#include <QtMath>
18
19QgsRay3D::QgsRay3D( const QVector3D &origin, const QVector3D &direction )
20 : mOrigin( origin )
21 , mDirection( direction.normalized() )
22{
23
24}
25
26void QgsRay3D::setOrigin( const QVector3D &origin )
27{
28 mOrigin = origin;
29}
30
31void QgsRay3D::setDirection( const QVector3D direction )
32{
33 mDirection = direction.normalized();
34}
35
36QVector3D QgsRay3D::projectedPoint( const QVector3D &point ) const
37{
38 return mOrigin + QVector3D::dotProduct( point - mOrigin, mDirection ) * mDirection;
39}
40
41bool QgsRay3D::isInFront( const QVector3D &point ) const
42{
43 return QVector3D::dotProduct( ( point - mOrigin ).normalized(), mDirection ) >= 0.0;
44}
45
46double QgsRay3D::angleToPoint( const QVector3D &point ) const
47{
48 // project point onto the ray
49 const QVector3D projPoint = projectedPoint( point );
50
51 // calculate the angle between the point and the projected point
52 const QVector3D v1 = projPoint - mOrigin ;
53 const QVector3D v2 = point - projPoint;
54 return qRadiansToDegrees( std::atan2( v2.length(), v1.length() ) );
55}
QVector3D origin() const
Returns the origin of the ray.
Definition qgsray3d.h:44
QgsRay3D(const QVector3D &origin, const QVector3D &direction)
Constructor.
Definition qgsray3d.cpp:19
void setDirection(const QVector3D direction)
Sets the direction of the ray.
Definition qgsray3d.cpp:31
QVector3D projectedPoint(const QVector3D &point) const
Returns the projection of the point on the ray (which is the closest point of the ray to point)
Definition qgsray3d.cpp:36
QVector3D direction() const
Returns the direction of the ray see setDirection()
Definition qgsray3d.h:50
double angleToPoint(const QVector3D &point) const
Returns the angle between the ray and the vector from the ray's origin and the point point.
Definition qgsray3d.cpp:46
void setOrigin(const QVector3D &origin)
Sets the origin of the ray.
Definition qgsray3d.cpp:26
bool isInFront(const QVector3D &point) const
Checks whether the point is in front of the ray.
Definition qgsray3d.cpp:41