All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
plane.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_GF_PLANE_H
8#define PXR_BASE_GF_PLANE_H
9
12
13#include "pxr/pxr.h"
14#include "pxr/base/gf/vec3d.h"
15#include "pxr/base/gf/api.h"
16
17#include <iosfwd>
18#include <vector>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
22class GfRange3d;
23class GfMatrix4d;
24class GfVec4d;
25
37{
38 public:
39
42 }
43
47 GfPlane(const GfVec3d &normal, double distanceToOrigin) {
48 Set(normal, distanceToOrigin);
49 }
50
54 GfPlane(const GfVec3d &normal, const GfVec3d &point) {
55 Set(normal, point);
56 }
57
62 GfPlane(const GfVec3d &p0, const GfVec3d &p1, const GfVec3d &p2) {
63 Set(p0, p1, p2);
64 }
65
68 GfPlane(const GfVec4d &eqn) {
69 Set(eqn);
70 }
71
75 void Set(const GfVec3d &normal, double distanceToOrigin) {
76 _normal = normal.GetNormalized();
77 _distance = distanceToOrigin;
78 }
79
83 GF_API
84 void Set(const GfVec3d &normal, const GfVec3d &point);
85
90 GF_API
91 void Set(const GfVec3d &p0,
92 const GfVec3d &p1,
93 const GfVec3d &p2);
94
97 GF_API
98 void Set(const GfVec4d &eqn);
99
101 const GfVec3d & GetNormal() const {
102 return _normal;
103 }
104
106 double GetDistanceFromOrigin() const {
107 return _distance;
108 }
109
112 GF_API
114
117 bool operator ==(const GfPlane &p) const {
118 return (_normal == p._normal &&
119 _distance == p._distance);
120 }
121
124 bool operator !=(const GfPlane &p) const {
125 return ! (*this == p);
126 }
127
131 double GetDistance(const GfVec3d &p) const {
132 return p * _normal - _distance;
133 }
134
136 GfVec3d Project(const GfVec3d& p) const {
137 return p - GetDistance(p) * _normal;
138 }
139
141 GF_API
142 GfPlane & Transform(const GfMatrix4d &matrix);
143
146 void Reorient(const GfVec3d& p) {
147 if (GetDistance(p) < 0) {
148 _normal = -_normal;
149 _distance = -_distance;
150 }
151 }
152
156 GF_API
158
161 bool IntersectsPositiveHalfSpace(const GfVec3d &pt) const {
162 return GetDistance(pt) >= 0.0;
163 }
164
165 private:
167 GfVec3d _normal;
168
170 double _distance;
171};
172
190GF_API
191bool GfFitPlaneToPoints(const std::vector<GfVec3d>& points, GfPlane* fitPlane);
192
195GF_API std::ostream& operator<<(std::ostream&, const GfPlane&);
196
197PXR_NAMESPACE_CLOSE_SCOPE
198
199#endif // PXR_BASE_GF_PLANE_H
GF_API bool GfFitPlaneToPoints(const std::vector< GfVec3d > &points, GfPlane *fitPlane)
Fits a plane to the given points.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type: 3-dimensional plane.
Definition: plane.h:37
GF_API GfVec4d GetEquation() const
Give the coefficients of the equation of the plane.
GfPlane(const GfVec3d &normal, double distanceToOrigin)
This constructor sets this to the plane perpendicular to normal and at distance units from the origin...
Definition: plane.h:47
bool operator!=(const GfPlane &p) const
Component-wise inequality test.
Definition: plane.h:124
void Set(const GfVec3d &normal, double distanceToOrigin)
Sets this to the plane perpendicular to normal and at distance units from the origin.
Definition: plane.h:75
bool IntersectsPositiveHalfSpace(const GfVec3d &pt) const
Returns true if the given point is on the plane or within its positive half space.
Definition: plane.h:161
GfPlane()
The default constructor leaves the plane parameters undefined.
Definition: plane.h:41
GfPlane(const GfVec4d &eqn)
This constructor creates a plane given by the equation eqn[0] * x + eqn[1] * y + eqn[2] * z + eqn[3] ...
Definition: plane.h:68
GfPlane(const GfVec3d &p0, const GfVec3d &p1, const GfVec3d &p2)
This constructor sets this to the plane that contains the three given points.
Definition: plane.h:62
bool operator==(const GfPlane &p) const
Component-wise equality test.
Definition: plane.h:117
GF_API GfPlane & Transform(const GfMatrix4d &matrix)
Transforms the plane by the given matrix.
GF_API void Set(const GfVec3d &normal, const GfVec3d &point)
This constructor sets this to the plane perpendicular to normal and that passes through point.
GfPlane(const GfVec3d &normal, const GfVec3d &point)
This constructor sets this to the plane perpendicular to normal and that passes through point.
Definition: plane.h:54
GfVec3d Project(const GfVec3d &p) const
Return the projection of p onto the plane.
Definition: plane.h:136
GF_API void Set(const GfVec3d &p0, const GfVec3d &p1, const GfVec3d &p2)
This constructor sets this to the plane that contains the three given points.
const GfVec3d & GetNormal() const
Returns the unit-length normal vector of the plane.
Definition: plane.h:101
double GetDistanceFromOrigin() const
Returns the distance of the plane from the origin.
Definition: plane.h:106
double GetDistance(const GfVec3d &p) const
Returns the distance of point from the plane.
Definition: plane.h:131
void Reorient(const GfVec3d &p)
Flip the plane normal (if necessary) so that p is in the positive halfspace.
Definition: plane.h:146
GF_API void Set(const GfVec4d &eqn)
This method sets this to the plane given by the equation eqn[0] * x + eqn[1] * y + eqn[2] * z + eqn[3...
GF_API bool IntersectsPositiveHalfSpace(const GfRange3d &box) const
Returns true if the given aligned bounding box is at least partially on the positive side (the one th...
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
Basic type for a vector of 3 double components.
Definition: vec3d.h:46
Basic type for a vector of 4 double components.
Definition: vec4d.h:46
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].