All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lineSeg.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_LINE_SEG_H
8#define PXR_BASE_GF_LINE_SEG_H
9
12
13#include "pxr/pxr.h"
14#include "pxr/base/gf/line.h"
15#include "pxr/base/gf/vec3d.h"
16#include "pxr/base/gf/api.h"
17
18#include <float.h>
19#include <iosfwd>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
30class GfLineSeg {
31
32 public:
33
36 }
37
39 GfLineSeg(const GfVec3d &p0, const GfVec3d &p1 ) {
40 _length = _line.Set( p0, p1 - p0 );
41 }
42
45 GfVec3d GetPoint( double t ) const {return _line.GetPoint( t * _length );}
46
48 const GfVec3d &GetDirection() const { return _line.GetDirection(); }
49
51 double GetLength() const { return _length; }
52
56 GF_API
57 GfVec3d FindClosestPoint(const GfVec3d &point, double *t = NULL) const;
58
61 bool operator ==(const GfLineSeg &l) const {
62 return (_line == l._line && _length == l._length);
63 }
64
68 bool operator !=(const GfLineSeg &r) const {
69 return ! (*this == r);
70 }
71
72 private:
73 GF_API
74 friend bool GfFindClosestPoints( const GfLine &, const GfLineSeg &,
75 GfVec3d *, GfVec3d *,
76 double *, double * );
77 GF_API
78 friend bool GfFindClosestPoints( const GfLineSeg &, const GfLineSeg &,
79 GfVec3d *, GfVec3d *,
80 double *, double * );
81
82 GfLine _line;
83 double _length; // distance from p0 to p1
84};
85
95GF_API
96bool GfFindClosestPoints( const GfLine &line, const GfLineSeg &seg,
97 GfVec3d *p1 = nullptr, GfVec3d *p2 = nullptr,
98 double *t1 = nullptr, double *t2 = nullptr );
99
107GF_API
108bool GfFindClosestPoints( const GfLineSeg &seg1, const GfLineSeg &seg2,
109 GfVec3d *p1 = nullptr, GfVec3d *p2 = nullptr,
110 double *t1 = nullptr, double *t2 = nullptr );
111
114GF_API std::ostream &operator<<(std::ostream&, const GfLineSeg&);
115
116PXR_NAMESPACE_CLOSE_SCOPE
117
118#endif // PXR_BASE_GF_LINE_SEG_H
Basic type: 3D line.
Definition: line.h:32
GfVec3d GetPoint(double t) const
Return the point on the line at ( p0 + t * dir ).
Definition: line.h:53
const GfVec3d & GetDirection() const
Return the normalized direction of the line.
Definition: line.h:56
Basic type: 3D line segment.
Definition: lineSeg.h:30
GfLineSeg(const GfVec3d &p0, const GfVec3d &p1)
Construct a line segment that spans two points.
Definition: lineSeg.h:39
GfVec3d GetPoint(double t) const
Return the point on the segment specified by the parameter t.
Definition: lineSeg.h:45
GF_API friend bool GfFindClosestPoints(const GfLine &, const GfLineSeg &, GfVec3d *, GfVec3d *, double *, double *)
Computes the closets points on line and seg.
const GfVec3d & GetDirection() const
Return the normalized direction of the line.
Definition: lineSeg.h:48
bool operator==(const GfLineSeg &l) const
Component-wise equality test.
Definition: lineSeg.h:61
GfLineSeg()
The default constructor leaves line parameters undefined.
Definition: lineSeg.h:35
GF_API friend bool GfFindClosestPoints(const GfLineSeg &, const GfLineSeg &, GfVec3d *, GfVec3d *, double *, double *)
Computes the closets points on two line segments, seg1 and seg2.
GF_API GfVec3d FindClosestPoint(const GfVec3d &point, double *t=NULL) const
Returns the point on the line that is closest to point.
bool operator!=(const GfLineSeg &r) const
Component-wise inequality test.
Definition: lineSeg.h:68
double GetLength() const
Return the length of the line.
Definition: lineSeg.h:51
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 GfLine &line, const GfLineSeg &seg, GfVec3d *p1=nullptr, GfVec3d *p2=nullptr, double *t1=nullptr, double *t2=nullptr)
Computes the closets points on line and seg.