All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plane.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef GF_PLANE_H
25 #define GF_PLANE_H
26 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/base/gf/vec3d.h"
32 #include "pxr/base/gf/api.h"
33 
34 #include <iosfwd>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
38 class GfRange3d;
39 class GfMatrix4d;
40 class GfVec4d;
41 
52 class GfPlane
53 {
54  public:
55 
57  GfPlane() {
58  }
59 
63  GfPlane(const GfVec3d &normal, double distanceToOrigin) {
64  Set(normal, distanceToOrigin);
65  }
66 
70  GfPlane(const GfVec3d &normal, const GfVec3d &point) {
71  Set(normal, point);
72  }
73 
78  GfPlane(const GfVec3d &p0, const GfVec3d &p1, const GfVec3d &p2) {
79  Set(p0, p1, p2);
80  }
81 
84  GfPlane(const GfVec4d &eqn) {
85  Set(eqn);
86  }
87 
91  void Set(const GfVec3d &normal, double distanceToOrigin) {
92  _normal = normal.GetNormalized();
93  _distance = distanceToOrigin;
94  }
95 
99  GF_API
100  void Set(const GfVec3d &normal, const GfVec3d &point);
101 
106  GF_API
107  void Set(const GfVec3d &p0,
108  const GfVec3d &p1,
109  const GfVec3d &p2);
110 
113  GF_API
114  void Set(const GfVec4d &eqn);
115 
117  const GfVec3d & GetNormal() const {
118  return _normal;
119  }
120 
122  double GetDistanceFromOrigin() const {
123  return _distance;
124  }
125 
128  GF_API
129  GfVec4d GetEquation() const;
130 
133  bool operator ==(const GfPlane &p) const {
134  return (_normal == p._normal &&
135  _distance == p._distance);
136  }
137 
140  bool operator !=(const GfPlane &p) const {
141  return ! (*this == p);
142  }
143 
147  double GetDistance(const GfVec3d &p) const {
148  return p * _normal - _distance;
149  }
150 
152  GfVec3d Project(const GfVec3d& p) const {
153  return p - GetDistance(p) * _normal;
154  }
155 
157  GF_API
158  GfPlane & Transform(const GfMatrix4d &matrix);
159 
162  void Reorient(const GfVec3d& p) {
163  if (GetDistance(p) < 0) {
164  _normal = -_normal;
165  _distance = -_distance;
166  }
167  }
168 
172  GF_API
173  bool IntersectsPositiveHalfSpace(const GfRange3d &box) const;
174 
177  bool IntersectsPositiveHalfSpace(const GfVec3d &pt) const {
178  return GetDistance(pt) >= 0.0;
179  }
180 
181  private:
183  GfVec3d _normal;
184 
186  double _distance;
187 };
188 
206 GF_API
207 bool GfFitPlaneToPoints(const std::vector<GfVec3d>& points, GfPlane* fitPlane);
208 
211 GF_API std::ostream& operator<<(std::ostream&, const GfPlane&);
212 
213 PXR_NAMESPACE_CLOSE_SCOPE
214 
215 #endif // GF_PLANE_H
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:70
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
GF_API bool GfFitPlaneToPoints(const std::vector< GfVec3d > &points, GfPlane *fitPlane)
Fits a plane to the given points.
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:63
double GetDistanceFromOrigin() const
Returns the distance of the plane from the origin.
Definition: plane.h:122
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:84
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
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 plane.
Definition: plane.h:52
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:177
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
void Reorient(const GfVec3d &p)
Flip the plane normal (if necessary) so that p is in the positive halfspace.
Definition: plane.h:162
bool operator!=(const GfPlane &p) const
Component-wise inequality test.
Definition: plane.h:140
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GfVec3d Project(const GfVec3d &p) const
Return the projection of p onto the plane.
Definition: plane.h:152
GF_API GfVec4d GetEquation() const
Give the coefficients of the equation of the plane.
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:78
GF_API GfPlane & Transform(const GfMatrix4d &matrix)
Transforms the plane by the given matrix.
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
const GfVec3d & GetNormal() const
Returns the unit-length normal vector of the plane.
Definition: plane.h:117
GfPlane()
The default constructor leaves the plane parameters undefined.
Definition: plane.h:57
bool operator==(const GfPlane &p) const
Component-wise equality test.
Definition: plane.h:133
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:91
double GetDistance(const GfVec3d &p) const
Returns the distance of point from the plane.
Definition: plane.h:147