All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lineSeg.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_LINESEG_H
25 #define GF_LINESEG_H
26 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/base/gf/line.h"
32 #include "pxr/base/gf/vec3d.h"
33 #include "pxr/base/gf/api.h"
34 
35 #include <float.h>
36 #include <iosfwd>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
47 class GfLineSeg {
48 
49  public:
50 
53  }
54 
56  GfLineSeg(const GfVec3d &p0, const GfVec3d &p1 ) {
57  _length = _line.Set( p0, p1 - p0 );
58  }
59 
62  GfVec3d GetPoint( double t ) const {return _line.GetPoint( t * _length );}
63 
65  const GfVec3d &GetDirection() const { return _line.GetDirection(); }
66 
68  double GetLength() const { return _length; }
69 
73  GF_API
74  GfVec3d FindClosestPoint(const GfVec3d &point, double *t = NULL) const;
75 
78  bool operator ==(const GfLineSeg &l) const {
79  return (_line == l._line && _length == l._length);
80  }
81 
85  bool operator !=(const GfLineSeg &r) const {
86  return ! (*this == r);
87  }
88 
89  private:
90  GF_API
91  friend bool GfFindClosestPoints( const GfLine &, const GfLineSeg &,
92  GfVec3d *, GfVec3d *,
93  double *, double * );
94  GF_API
95  friend bool GfFindClosestPoints( const GfLineSeg &, const GfLineSeg &,
96  GfVec3d *, GfVec3d *,
97  double *, double * );
98 
99  GfLine _line;
100  double _length; // distance from p0 to p1
101 };
102 
112 GF_API
113 bool GfFindClosestPoints( const GfLine &line, const GfLineSeg &seg,
114  GfVec3d *p1 = nullptr, GfVec3d *p2 = nullptr,
115  double *t1 = nullptr, double *t2 = nullptr );
116 
124 GF_API
125 bool GfFindClosestPoints( const GfLineSeg &seg1, const GfLineSeg &seg2,
126  GfVec3d *p1 = nullptr, GfVec3d *p2 = nullptr,
127  double *t1 = nullptr, double *t2 = nullptr );
128 
131 GF_API std::ostream &operator<<(std::ostream&, const GfLineSeg&);
132 
133 PXR_NAMESPACE_CLOSE_SCOPE
134 
135 #endif // GF_LINESEG_H
const GfVec3d & GetDirection() const
Return the normalized direction of the line.
Definition: line.h:73
GF_API bool GfFindClosestPoints(const GfLine &l1, const GfLine &l2, GfVec3d *p1=nullptr, GfVec3d *p2=nullptr, double *t1=nullptr, double *t2=nullptr)
Computes the closets points between two lines.
GfLineSeg()
The default constructor leaves line parameters undefined.
Definition: lineSeg.h:52
bool operator!=(const GfLineSeg &r) const
Component-wise inequality test.
Definition: lineSeg.h:85
GfLineSeg(const GfVec3d &p0, const GfVec3d &p1)
Construct a line segment that spans two points.
Definition: lineSeg.h:56
bool operator==(const GfLineSeg &l) const
Component-wise equality test.
Definition: lineSeg.h:78
const GfVec3d & GetDirection() const
Return the normalized direction of the line.
Definition: lineSeg.h:65
Basic type: 3D line.
Definition: line.h:49
GfVec3d GetPoint(double t) const
Return the point on the segment specified by the parameter t.
Definition: lineSeg.h:62
GF_API GfVec3d FindClosestPoint(const GfVec3d &point, double *t=NULL) const
Returns the point on the line that is closest to point.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
double GetLength() const
Return the length of the line.
Definition: lineSeg.h:68
Basic type: 3D line segment.
Definition: lineSeg.h:47
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
GfVec3d GetPoint(double t) const
Return the point on the line at ( p0 + t * dir ).
Definition: line.h:70
GF_API friend bool GfFindClosestPoints(const GfLine &, const GfLineSeg &, GfVec3d *, GfVec3d *, double *, double *)
Computes the closets points on line and seg.