CVB++ 14.0
plane_3d.hpp
1#pragma once
2
3#include <cmath>
4
5#include "global.hpp"
6
7#include "point_3d.hpp"
8
9namespace Cvb
10{
11
12CVB_BEGIN_INLINE_NS
13
15
17class Plane3D final
18{
19public:
21
24 Plane3D() noexcept = default;
25
27
34 Plane3D(double nx, double ny, double nz, double distanceToOrigin) noexcept
35 : normal_{nx, ny, nz}, distanceToOrigin_{distanceToOrigin}
36 {
37 }
38
40
45 Plane3D(Point3D<double> normal, double distanceToOrigin) noexcept
46 : normal_{normal}, distanceToOrigin_{distanceToOrigin}
47 {
48 }
49
51
55 Point3D<double> Normal() const noexcept { return normal_; }
56
58
62 void SetNormal(Point3D<double> normal) noexcept { normal_ = normal; }
63
65
69 double DistanceToOrigin() const noexcept { return distanceToOrigin_; }
70
72
76 void SetDistanceToOrigin(double distanceToOrigin) noexcept { distanceToOrigin_ = distanceToOrigin; }
77
79
84 double DistanceToPoint(const Point3D<double> &pt) const noexcept { return DistanceToPoint(pt.X(), pt.Y(), pt.Z()); }
85
87
94 double DistanceToPoint(double x, double y, double z) const noexcept
95 {
96 auto normal = normal_ / normal_.Length();
97 return abs(normal.X() * x + normal.Y() * y + normal.Z() * z - distanceToOrigin_);
98 }
99
100private:
101 Point3D<double> normal_{0.0, 0.0, 0.0};
102 double distanceToOrigin_ = 0.0;
103};
104
105CVB_END_INLINE_NS
106}
A plane in 3D space in Hessian normal form.
Definition: plane_3d.hpp:18
Plane3D(Point3D< double > normal, double distanceToOrigin) noexcept
Creates a new Plane3D object.
Definition: plane_3d.hpp:45
double DistanceToPoint(const Point3D< double > &pt) const noexcept
Calculates the distance to the point pt.
Definition: plane_3d.hpp:84
double DistanceToPoint(double x, double y, double z) const noexcept
Calculates the distance to the point pt.
Definition: plane_3d.hpp:94
double DistanceToOrigin() const noexcept
Gets the distance to the origin in point units.
Definition: plane_3d.hpp:69
Plane3D() noexcept=default
Creates a default plane at (0, 0, 0, 0).
void SetDistanceToOrigin(double distanceToOrigin) noexcept
Sets the distance to the origin in point units.
Definition: plane_3d.hpp:76
Point3D< double > Normal() const noexcept
Gets the normal vector of the plane.
Definition: plane_3d.hpp:55
void SetNormal(Point3D< double > normal) noexcept
Sets the normal vector of the plane.
Definition: plane_3d.hpp:62
T Length() const noexcept
Gets the length of this point.
Definition: point_3d.hpp:140
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24