Loading...
Searching...
No Matches
ray.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 PXR_BASE_GF_RAY_H
25#define PXR_BASE_GF_RAY_H
26
29
30#include "pxr/pxr.h"
32#include "pxr/base/gf/api.h"
33
34#include <float.h>
35#include <limits>
36#include <iosfwd>
37
38PXR_NAMESPACE_OPEN_SCOPE
39
40class GfBBox3d;
41class GfLine;
42class GfLineSeg;
43class GfPlane;
44class GfRange3d;
45
61class GfRay {
62
63 public:
64
67 }
68
70 GfRay(const GfVec3d &startPoint, const GfVec3d &direction) {
71 SetPointAndDirection(startPoint, direction);
72 }
73
75 GF_API
76 void SetPointAndDirection(const GfVec3d &startPoint,
77 const GfVec3d &direction);
78
80 GF_API
81 void SetEnds(const GfVec3d &startPoint, const GfVec3d &endPoint);
82
84 const GfVec3d & GetStartPoint() const {
85 return _startPoint;
86 }
87
90 const GfVec3d & GetDirection() const {
91 return _direction;
92 }
93
96 GfVec3d GetPoint(double distance) const {
97 return _startPoint + distance * _direction;
98 }
99
101 GF_API
102 GfRay & Transform(const GfMatrix4d &matrix);
103
107 GF_API
109 double *rayDistance = NULL) const;
110
113 bool operator ==(const GfRay &r) const {
114 return (_startPoint == r._startPoint &&
115 _direction == r._direction);
116 }
117
120 bool operator !=(const GfRay &r) const {
121 return ! (*this == r);
122 }
123
129
151 GF_API
152 bool Intersect(const GfVec3d &p0,
153 const GfVec3d &p1,
154 const GfVec3d &p2,
155 double *distance = NULL,
156 GfVec3d *barycentricCoords = NULL,
157 bool *frontFacing = NULL,
158 double maxDist = std::numeric_limits<double>::infinity())
159 const;
160
168 GF_API
169 bool Intersect(const GfPlane &plane, double *distance = NULL,
170 bool *frontFacing = NULL) const;
171
176 GF_API
177 bool Intersect(const GfRange3d &box,
178 double *enterDistance = NULL,
179 double *exitDistance = NULL) const;
180
185 GF_API
186 bool Intersect(const GfBBox3d &box,
187 double *enterDistance = NULL,
188 double *exitDistance = NULL) const;
189
194 GF_API
195 bool Intersect(const GfVec3d &center, double radius,
196 double *enterDistance = NULL,
197 double *exitDistance = NULL ) const;
198
207 GF_API
208 bool Intersect(const GfVec3d &origin,
209 const GfVec3d &axis,
210 const double radius,
211 double *enterDistance = NULL,
212 double *exitDistance = NULL) const;
213
223 GF_API
224 bool Intersect(const GfVec3d &origin,
225 const GfVec3d &axis,
226 const double radius,
227 const double height,
228 double *enterDistance = NULL,
229 double *exitDistance = NULL) const;
231
232 private:
233 GF_API
234 friend bool GfFindClosestPoints( const GfRay &, const GfLine &,
235 GfVec3d *, GfVec3d *,
236 double *, double * );
237 GF_API
238 friend bool GfFindClosestPoints( const GfRay &, const GfLineSeg &,
239 GfVec3d *, GfVec3d *,
240 double *, double * );
241
245 bool _SolveQuadratic(const double a,
246 const double b,
247 const double c,
248 double *enterDistance = NULL,
249 double *exitDistance = NULL) const;
250
252 GfVec3d _startPoint;
254 GfVec3d _direction;
255};
256
264GF_API
265bool GfFindClosestPoints( const GfRay &ray, const GfLine &line,
266 GfVec3d *rayPoint = nullptr,
267 GfVec3d *linePoint = nullptr,
268 double *rayDistance = nullptr,
269 double *lineDistance = nullptr );
270
278GF_API
279bool GfFindClosestPoints( const GfRay &ray, const GfLineSeg &seg,
280 GfVec3d *rayPoint = nullptr,
281 GfVec3d *segPoint = nullptr,
282 double *rayDistance = nullptr,
283 double *segDistance = nullptr );
284
287GF_API std::ostream& operator<<(std::ostream&, const GfRay&);
288
289PXR_NAMESPACE_CLOSE_SCOPE
290
291#endif // PXR_BASE_GF_RAY_H
Basic type: arbitrarily oriented 3D bounding box.
Definition: bbox3d.h:84
Basic type: 3D line.
Definition: line.h:49
Basic type: 3D line segment.
Definition: lineSeg.h:47
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type: 3-dimensional plane.
Definition: plane.h:54
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
Basic type: Ray used for intersection testing.
Definition: ray.h:61
GfRay(const GfVec3d &startPoint, const GfVec3d &direction)
This constructor takes a starting point and a direction.
Definition: ray.h:70
GF_API GfVec3d FindClosestPoint(const GfVec3d &point, double *rayDistance=NULL) const
Returns the point on the ray that is closest to point.
GF_API bool Intersect(const GfVec3d &origin, const GfVec3d &axis, const double radius, const double height, double *enterDistance=NULL, double *exitDistance=NULL) const
Intersects the ray with an infinite non-double cone, centered at origin, with axis axis,...
bool operator!=(const GfRay &r) const
Component-wise inequality test.
Definition: ray.h:120
GfVec3d GetPoint(double distance) const
Returns the point that is distance units from the starting point along the direction vector,...
Definition: ray.h:96
const GfVec3d & GetDirection() const
Returns the direction vector of the segment.
Definition: ray.h:90
GF_API void SetPointAndDirection(const GfVec3d &startPoint, const GfVec3d &direction)
Sets the ray by specifying a starting point and a direction.
GF_API bool Intersect(const GfVec3d &origin, const GfVec3d &axis, const double radius, double *enterDistance=NULL, double *exitDistance=NULL) const
Intersects the ray with an infinite cylinder, with axis axis, centered at the origin,...
GF_API bool Intersect(const GfPlane &plane, double *distance=NULL, bool *frontFacing=NULL) const
Intersects the ray with a plane, returning true if the ray is not parallel to the plane and the inter...
GF_API friend bool GfFindClosestPoints(const GfRay &, const GfLine &, GfVec3d *, GfVec3d *, double *, double *)
Computes the closest points between a ray and a line.
GF_API GfRay & Transform(const GfMatrix4d &matrix)
Transforms the ray by the given matrix.
GfRay()
The default constructor leaves the ray parameters undefined.
Definition: ray.h:66
const GfVec3d & GetStartPoint() const
Returns the starting point of the segment.
Definition: ray.h:84
bool operator==(const GfRay &r) const
Component-wise equality test.
Definition: ray.h:113
GF_API bool Intersect(const GfRange3d &box, double *enterDistance=NULL, double *exitDistance=NULL) const
Intersects the ray with an axis-aligned box, returning true if the ray intersects it at all within bo...
GF_API bool Intersect(const GfBBox3d &box, double *enterDistance=NULL, double *exitDistance=NULL) const
Intersects the ray with an oriented box, returning true if the ray intersects it at all within bounds...
GF_API bool Intersect(const GfVec3d &center, double radius, double *enterDistance=NULL, double *exitDistance=NULL) const
Intersects the ray with a sphere, returning true if the ray intersects it at all within bounds.
GF_API void SetEnds(const GfVec3d &startPoint, const GfVec3d &endPoint)
Sets the ray by specifying a starting point and an ending point.
GF_API bool Intersect(const GfVec3d &p0, const GfVec3d &p1, const GfVec3d &p2, double *distance=NULL, GfVec3d *barycentricCoords=NULL, bool *frontFacing=NULL, double maxDist=std::numeric_limits< double >::infinity()) const
Intersects the ray with the triangle formed by points p0, p1, and p2, returning true if it hits.
GF_API friend bool GfFindClosestPoints(const GfRay &, const GfLineSeg &, GfVec3d *, GfVec3d *, double *, double *)
Computes the closest points between a ray and a line segment.
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GF_API bool GfFindClosestPoints(const GfRay &ray, const GfLine &line, GfVec3d *rayPoint=nullptr, GfVec3d *linePoint=nullptr, double *rayDistance=nullptr, double *lineDistance=nullptr)
Computes the closest points between a ray and a line.