ACF $AcfVersion:0$
CLine3d.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
18{
19public:
24 CLine3d();
25
31 CLine3d(const CVector3d& p1, const CVector3d& p2);
32
36 bool IsNull() const;
37
41 const CVector3d& GetPoint1() const;
42
46 void SetPoint1(const CVector3d& point);
47
51 const CVector3d& GetPoint2() const;
52
56 void SetPoint2(const CVector3d& point);
57
61 CVector3d GetDirection() const;
62
66 double GetLength() const;
67
71 double GetLengthSq() const;
72
77 CVector3d GetPointAt(double t) const;
78
84 CVector3d GetClosestPoint(const CVector3d& point) const;
85
91 double GetClosestParameter(const CVector3d& point) const;
92
96 double GetDistance(const CVector3d& point) const;
97
101 double GetDistanceSq(const CVector3d& point) const;
102
106 bool Serialize(iser::IArchive& archive);
107
108 bool operator==(const CLine3d& line) const;
109 bool operator!=(const CLine3d& line) const;
110
111private:
112 CVector3d m_point1;
113 CVector3d m_point2;
114};
115
116
117// inline methods
118
120: m_point1(0.0, 0.0, 0.0)
121, m_point2(1.0, 0.0, 0.0)
122{
123}
124
125
126inline CLine3d::CLine3d(const CVector3d& p1, const CVector3d& p2)
127: m_point1(p1)
128, m_point2(p2)
129{
130}
131
132
133inline bool CLine3d::IsNull() const
134{
135 return m_point1 == m_point2;
136}
137
138
139inline const CVector3d& CLine3d::GetPoint1() const
140{
141 return m_point1;
142}
143
144
145inline void CLine3d::SetPoint1(const CVector3d& point)
146{
147 m_point1 = point;
148}
149
150
151inline const CVector3d& CLine3d::GetPoint2() const
152{
153 return m_point2;
154}
155
156
157inline void CLine3d::SetPoint2(const CVector3d& point)
158{
159 m_point2 = point;
160}
161
162
164{
165 return (m_point2 - m_point1).GetNormalized();
166}
167
168
169inline double CLine3d::GetLength() const
170{
171 return (m_point2 - m_point1).GetLength();
172}
173
174
175inline double CLine3d::GetLengthSq() const
176{
177 return (m_point2 - m_point1).GetLength2();
178}
179
180
181inline CVector3d CLine3d::GetPointAt(double t) const
182{
183 return m_point1 + (m_point2 - m_point1) * t;
184}
185
186
187inline bool CLine3d::operator==(const CLine3d& line) const
188{
189 return m_point1 == line.m_point1 && m_point2 == line.m_point2;
190}
191
192
193inline bool CLine3d::operator!=(const CLine3d& line) const
194{
195 return !(*this == line);
196}
197
198
199} // namespace i3d
200
201
Definition of a line in 3D space.
Definition CLine3d.h:18
const CVector3d & GetPoint2() const
Get second point of the line.
Definition CLine3d.h:151
CVector3d GetPointAt(double t) const
Get point at parameter t.
Definition CLine3d.h:181
void SetPoint1(const CVector3d &point)
Set first point of the line.
Definition CLine3d.h:145
double GetDistance(const CVector3d &point) const
Calculate distance from point to line segment.
CLine3d()
Default constructor.
Definition CLine3d.h:119
const CVector3d & GetPoint1() const
Get first point of the line.
Definition CLine3d.h:139
double GetLength() const
Get length of the line segment.
Definition CLine3d.h:169
bool Serialize(iser::IArchive &archive)
Serialize this line to specified archive.
CVector3d GetClosestPoint(const CVector3d &point) const
Get closest point on line to given point.
double GetDistanceSq(const CVector3d &point) const
Calculate squared distance from point to line segment (faster).
bool IsNull() const
Returns true if the line has zero length.
Definition CLine3d.h:133
CVector3d GetDirection() const
Get direction vector of the line (normalized).
Definition CLine3d.h:163
bool operator==(const CLine3d &line) const
Definition CLine3d.h:187
bool operator!=(const CLine3d &line) const
Definition CLine3d.h:193
double GetClosestParameter(const CVector3d &point) const
Get parameter value t for closest point on line to given point.
void SetPoint2(const CVector3d &point)
Set second point of the line.
Definition CLine3d.h:157
double GetLengthSq() const
Get squared length of the line segment (faster than GetLength).
Definition CLine3d.h:175
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 GetLength() const
Calculates the Euclidean length (magnitude) of the vector.
Definition TVector.h:667
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
Contains the 3D objects.
Definition CAffine3d.h:12