All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ray.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_RAY_H
8#define PXR_BASE_GF_RAY_H
9
12
13#include "pxr/pxr.h"
15#include "pxr/base/gf/api.h"
16
17#include <float.h>
18#include <limits>
19#include <iosfwd>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23class GfBBox3d;
24class GfLine;
25class GfLineSeg;
26class GfPlane;
27class GfRange3d;
28
44class GfRay {
45
46 public:
47
50 }
51
53 GfRay(const GfVec3d &startPoint, const GfVec3d &direction) {
54 SetPointAndDirection(startPoint, direction);
55 }
56
58 GF_API
59 void SetPointAndDirection(const GfVec3d &startPoint,
60 const GfVec3d &direction);
61
63 GF_API
64 void SetEnds(const GfVec3d &startPoint, const GfVec3d &endPoint);
65
67 const GfVec3d & GetStartPoint() const {
68 return _startPoint;
69 }
70
73 const GfVec3d & GetDirection() const {
74 return _direction;
75 }
76
79 GfVec3d GetPoint(double distance) const {
80 return _startPoint + distance * _direction;
81 }
82
84 GF_API
85 GfRay & Transform(const GfMatrix4d &matrix);
86
90 GF_API
92 double *rayDistance = NULL) const;
93
96 bool operator ==(const GfRay &r) const {
97 return (_startPoint == r._startPoint &&
98 _direction == r._direction);
99 }
100
103 bool operator !=(const GfRay &r) const {
104 return ! (*this == r);
105 }
106
112
134 GF_API
135 bool Intersect(const GfVec3d &p0,
136 const GfVec3d &p1,
137 const GfVec3d &p2,
138 double *distance = NULL,
139 GfVec3d *barycentricCoords = NULL,
140 bool *frontFacing = NULL,
141 double maxDist = std::numeric_limits<double>::infinity())
142 const;
143
151 GF_API
152 bool Intersect(const GfPlane &plane, double *distance = NULL,
153 bool *frontFacing = NULL) const;
154
159 GF_API
160 bool Intersect(const GfRange3d &box,
161 double *enterDistance = NULL,
162 double *exitDistance = NULL) const;
163
168 GF_API
169 bool Intersect(const GfBBox3d &box,
170 double *enterDistance = NULL,
171 double *exitDistance = NULL) const;
172
177 GF_API
178 bool Intersect(const GfVec3d &center, double radius,
179 double *enterDistance = NULL,
180 double *exitDistance = NULL ) const;
181
190 GF_API
191 bool Intersect(const GfVec3d &origin,
192 const GfVec3d &axis,
193 const double radius,
194 double *enterDistance = NULL,
195 double *exitDistance = NULL) const;
196
206 GF_API
207 bool Intersect(const GfVec3d &origin,
208 const GfVec3d &axis,
209 const double radius,
210 const double height,
211 double *enterDistance = NULL,
212 double *exitDistance = NULL) const;
214
215 private:
216 GF_API
217 friend bool GfFindClosestPoints( const GfRay &, const GfLine &,
218 GfVec3d *, GfVec3d *,
219 double *, double * );
220 GF_API
221 friend bool GfFindClosestPoints( const GfRay &, const GfLineSeg &,
222 GfVec3d *, GfVec3d *,
223 double *, double * );
224
228 bool _SolveQuadratic(const double a,
229 const double b,
230 const double c,
231 double *enterDistance = NULL,
232 double *exitDistance = NULL) const;
233
235 GfVec3d _startPoint;
237 GfVec3d _direction;
238};
239
247GF_API
248bool GfFindClosestPoints( const GfRay &ray, const GfLine &line,
249 GfVec3d *rayPoint = nullptr,
250 GfVec3d *linePoint = nullptr,
251 double *rayDistance = nullptr,
252 double *lineDistance = nullptr );
253
261GF_API
262bool GfFindClosestPoints( const GfRay &ray, const GfLineSeg &seg,
263 GfVec3d *rayPoint = nullptr,
264 GfVec3d *segPoint = nullptr,
265 double *rayDistance = nullptr,
266 double *segDistance = nullptr );
267
270GF_API std::ostream& operator<<(std::ostream&, const GfRay&);
271
272PXR_NAMESPACE_CLOSE_SCOPE
273
274#endif // PXR_BASE_GF_RAY_H
Basic type: arbitrarily oriented 3D bounding box.
Definition: bbox3d.h:67
Basic type: 3D line.
Definition: line.h:32
Basic type: 3D line segment.
Definition: lineSeg.h:30
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type: 3-dimensional plane.
Definition: plane.h:37
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
Basic type: Ray used for intersection testing.
Definition: ray.h:44
GfRay(const GfVec3d &startPoint, const GfVec3d &direction)
This constructor takes a starting point and a direction.
Definition: ray.h:53
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:103
GfVec3d GetPoint(double distance) const
Returns the point that is distance units from the starting point along the direction vector,...
Definition: ray.h:79
const GfVec3d & GetDirection() const
Returns the direction vector of the segment.
Definition: ray.h:73
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:49
const GfVec3d & GetStartPoint() const
Returns the starting point of the segment.
Definition: ray.h:67
bool operator==(const GfRay &r) const
Component-wise equality test.
Definition: ray.h:96
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:46
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.