ACF $AcfVersion:0$
CPlane3d.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// ACF includes
6#include <i3d/CVector3d.h>
7
8
9namespace i3d
10{
11
12
19{
20public:
25 CPlane3d();
26
32 CPlane3d(const CVector3d& point, const CVector3d& normal);
33
41 CPlane3d(const CVector3d& p1, const CVector3d& p2, const CVector3d& p3);
42
46 const CVector3d& GetPoint() const;
47
51 void SetPoint(const CVector3d& point);
52
56 const CVector3d& GetNormal() const;
57
62 void SetNormal(const CVector3d& normal);
63
68 double GetSignedDistance(const CVector3d& point) const;
69
73 double GetDistance(const CVector3d& point) const;
74
78 CVector3d GetProjection(const CVector3d& point) const;
79
83 bool Contains(const CVector3d& point, double tolerance = I_BIG_EPSILON) const;
84
88 bool Serialize(iser::IArchive& archive);
89
90 bool operator==(const CPlane3d& plane) const;
91 bool operator!=(const CPlane3d& plane) const;
92
93private:
94 CVector3d m_point;
95 CVector3d m_normal;
96};
97
98
99// inline methods
100
102: m_point(0.0, 0.0, 0.0)
103, m_normal(0.0, 0.0, 1.0)
104{
105}
106
107
108inline CPlane3d::CPlane3d(const CVector3d& point, const CVector3d& normal)
109: m_point(point)
110, m_normal(normal.GetNormalized())
111{
112}
113
114
115inline const CVector3d& CPlane3d::GetPoint() const
116{
117 return m_point;
118}
119
120
121inline void CPlane3d::SetPoint(const CVector3d& point)
122{
123 m_point = point;
124}
125
126
127inline const CVector3d& CPlane3d::GetNormal() const
128{
129 return m_normal;
130}
131
132
133inline void CPlane3d::SetNormal(const CVector3d& normal)
134{
135 m_normal = normal.GetNormalized();
136}
137
138
139inline double CPlane3d::GetSignedDistance(const CVector3d& point) const
140{
141 return m_normal.GetDotProduct(point - m_point);
142}
143
144
145inline double CPlane3d::GetDistance(const CVector3d& point) const
146{
147 return qAbs(GetSignedDistance(point));
148}
149
150
152{
153 double distance = GetSignedDistance(point);
154 return point - m_normal * distance;
155}
156
157
158inline bool CPlane3d::Contains(const CVector3d& point, double tolerance) const
159{
160 return GetDistance(point) < tolerance;
161}
162
163
164inline bool CPlane3d::operator==(const CPlane3d& plane) const
165{
166 return m_point == plane.m_point && m_normal == plane.m_normal;
167}
168
169
170inline bool CPlane3d::operator!=(const CPlane3d& plane) const
171{
172 return !(*this == plane);
173}
174
175
176} // namespace i3d
177
178
Definition of a plane in 3D space.
Definition CPlane3d.h:19
void SetPoint(const CVector3d &point)
Set point on the plane.
Definition CPlane3d.h:121
void SetNormal(const CVector3d &normal)
Set normal vector of the plane.
Definition CPlane3d.h:133
const CVector3d & GetPoint() const
Get point on the plane.
Definition CPlane3d.h:115
CPlane3d()
Default constructor.
Definition CPlane3d.h:101
double GetSignedDistance(const CVector3d &point) const
Calculate signed distance from point to plane.
Definition CPlane3d.h:139
CVector3d GetProjection(const CVector3d &point) const
Project point onto the plane.
Definition CPlane3d.h:151
bool operator==(const CPlane3d &plane) const
Definition CPlane3d.h:164
bool Contains(const CVector3d &point, double tolerance=I_BIG_EPSILON) const
Check if point lies on the plane (within tolerance).
Definition CPlane3d.h:158
const CVector3d & GetNormal() const
Get normal vector of the plane.
Definition CPlane3d.h:127
CPlane3d(const CVector3d &p1, const CVector3d &p2, const CVector3d &p3)
Construct plane from three points.
bool Serialize(iser::IArchive &archive)
Serialize this plane to specified archive.
bool operator!=(const CPlane3d &plane) const
Definition CPlane3d.h:170
double GetDistance(const CVector3d &point) const
Calculate absolute distance from point to plane.
Definition CPlane3d.h:145
Represents a position or mathematical vector in 3D space with double precision.
Definition CVector3d.h:74
CVector3d GetNormalized(double length=1.0) const
Return normalized vector with the same direction and specified length.
Element GetDotProduct(const TVector< Size, Element > &vector) const
Calculates the dot product with another vector.
Definition TVector.h:647
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
static const double I_BIG_EPSILON
Definition istd.h:26
Contains the 3D objects.
Definition CAffine3d.h:12