QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
geometry
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
19
QgsRay3D::QgsRay3D
(
const
QVector3D &
origin
,
const
QVector3D &
direction
)
20
: mOrigin(
origin
)
21
, mDirection(
direction
.normalized() )
22
, mDirectionInversed( 1.0f / mDirection.x(), 1.0f / mDirection.y(), 1.0f / mDirection.z() )
23
{}
24
25
void
QgsRay3D::setOrigin
(
const
QVector3D &
origin
)
26
{
27
mOrigin =
origin
;
28
}
29
30
void
QgsRay3D::setDirection
(
const
QVector3D
direction
)
31
{
32
mDirection =
direction
.normalized();
33
mDirectionInversed = QVector3D( 1.0f / mDirection.x(), 1.0f / mDirection.y(), 1.0f / mDirection.z() );
34
}
35
36
QVector3D
QgsRay3D::projectedPoint
(
const
QVector3D &
point
)
const
37
{
38
return
mOrigin + QVector3D::dotProduct(
point
- mOrigin, mDirection ) * mDirection;
39
}
40
41
float
QgsRay3D::projectedDistance
(
const
QVector3D &
point
)
const
42
{
43
return
QVector3D::dotProduct(
point
- mOrigin, mDirection ) / mDirection.lengthSquared();
44
}
45
46
bool
QgsRay3D::isInFront
(
const
QVector3D &
point
)
const
47
{
48
return
QVector3D::dotProduct( (
point
- mOrigin ).normalized(), mDirection ) >= 0.0;
49
}
50
51
double
QgsRay3D::angleToPoint
(
const
QVector3D &
point
)
const
52
{
53
// project point onto the ray
54
const
QVector3D projPoint =
projectedPoint
(
point
);
55
56
// calculate the angle between the point and the projected point
57
const
QVector3D v1 = projPoint - mOrigin;
58
const
QVector3D v2 =
point
- projPoint;
59
return
qRadiansToDegrees( std::atan2( v2.length(), v1.length() ) );
60
}
61
62
QVector3D
QgsRay3D::point
(
float
distance )
const
63
{
64
return
mOrigin + distance * mDirection;
65
}
QgsRay3D::projectedDistance
float projectedDistance(const QVector3D &point) const
Returns the distance of the projection of a point to the ray.
Definition
qgsray3d.cpp:41
QgsRay3D::origin
QVector3D origin() const
Returns the origin of the ray.
Definition
qgsray3d.h:43
QgsRay3D::QgsRay3D
QgsRay3D(const QVector3D &origin, const QVector3D &direction)
Constructor.
Definition
qgsray3d.cpp:19
QgsRay3D::setDirection
void setDirection(const QVector3D direction)
Sets the direction of the ray.
Definition
qgsray3d.cpp:30
QgsRay3D::projectedPoint
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
QgsRay3D::direction
QVector3D direction() const
Returns the direction of the ray see setDirection().
Definition
qgsray3d.h:49
QgsRay3D::angleToPoint
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:51
QgsRay3D::setOrigin
void setOrigin(const QVector3D &origin)
Sets the origin of the ray.
Definition
qgsray3d.cpp:25
QgsRay3D::isInFront
bool isInFront(const QVector3D &point) const
Checks whether the point is in front of the ray.
Definition
qgsray3d.cpp:46
QgsRay3D::point
QVector3D point(float distance) const
Returns the point along the ray with the specified distance from the ray's origin.
Definition
qgsray3d.cpp:62
qgsray3d.h
Generated on
for QGIS API Documentation by
1.17.0