Loading...
Searching...
No Matches
lineSeg2d.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_SEG2D_H
8#define PXR_BASE_GF_LINE_SEG2D_H
9
12
13#include "pxr/pxr.h"
14#include "pxr/base/gf/line2d.h"
15#include "pxr/base/gf/vec2d.h"
16#include "pxr/base/gf/api.h"
17
18#include <float.h>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
30
31 public:
32
35 }
36
38 GfLineSeg2d(const GfVec2d &p0, const GfVec2d &p1 ) {
39 _length = _line.Set( p0, p1 - p0 );
40 }
41
44 GfVec2d GetPoint( double t ) const {return _line.GetPoint( t * _length );}
45
47 const GfVec2d &GetDirection() const { return _line.GetDirection(); }
48
50 double GetLength() const { return _length; }
51
55 GF_API
56 GfVec2d FindClosestPoint(const GfVec2d &point, double *t = NULL) const;
57
60 bool operator ==(const GfLineSeg2d &l) const {
61 return (_line == l._line && _length == l._length);
62 }
63
67 bool operator !=(const GfLineSeg2d &r) const {
68 return ! (*this == r);
69 }
70
71 private:
72 GF_API
73 friend bool GfFindClosestPoints( const GfLine2d &, const GfLineSeg2d &,
74 GfVec2d *, GfVec2d *,
75 double *t1, double *t2 );
76 GF_API
77 friend bool GfFindClosestPoints( const GfLineSeg2d &, const GfLineSeg2d &,
78 GfVec2d *, GfVec2d *,
79 double *, double * );
80
81 GfLine2d _line;
82 double _length; // distance from p0 to p1
83};
84
94GF_API
95bool GfFindClosestPoints( const GfLine2d &line, const GfLineSeg2d &seg,
96 GfVec2d *p1 = nullptr, GfVec2d *p2 = nullptr,
97 double *t1 = nullptr, double *t2 = nullptr );
98
107GF_API
108bool GfFindClosestPoints( const GfLineSeg2d &seg1, const GfLineSeg2d &seg2,
109 GfVec2d *p1 = nullptr, GfVec2d *p2 = nullptr,
110 double *t1 = nullptr, double *t2 = nullptr );
111
112PXR_NAMESPACE_CLOSE_SCOPE
113
114#endif // PXR_BASE_GF_LINE_SEG2D_H
Basic type: 2D line.
Definition: line2d.h:32
const GfVec2d & GetDirection() const
Return the normalized direction of the line.
Definition: line2d.h:56
GfVec2d GetPoint(double t) const
Return the point on the line at ( p0 + t * dir ).
Definition: line2d.h:53
Basic type: 2D line segment.
Definition: lineSeg2d.h:29
const GfVec2d & GetDirection() const
Return the normalized direction of the line.
Definition: lineSeg2d.h:47
bool operator!=(const GfLineSeg2d &r) const
Component-wise inequality test.
Definition: lineSeg2d.h:67
GF_API friend bool GfFindClosestPoints(const GfLineSeg2d &, const GfLineSeg2d &, GfVec2d *, GfVec2d *, double *, double *)
Computes the closets points on two line segments, seg1 and seg2.
GfLineSeg2d()
The default constructor leaves line parameters undefined.
Definition: lineSeg2d.h:34
GfVec2d GetPoint(double t) const
Return the point on the segment specified by the parameter t.
Definition: lineSeg2d.h:44
GF_API friend bool GfFindClosestPoints(const GfLine2d &, const GfLineSeg2d &, GfVec2d *, GfVec2d *, double *t1, double *t2)
Computes the closets points on line and seg.
double GetLength() const
Return the length of the line.
Definition: lineSeg2d.h:50
bool operator==(const GfLineSeg2d &l) const
Component-wise equality test.
Definition: lineSeg2d.h:60
GF_API GfVec2d FindClosestPoint(const GfVec2d &point, double *t=NULL) const
Returns the point on the line that is closest to point.
GfLineSeg2d(const GfVec2d &p0, const GfVec2d &p1)
Construct a line segment that spans two points.
Definition: lineSeg2d.h:38
Basic type for a vector of 2 double components.
Definition: vec2d.h:46
GF_API bool GfFindClosestPoints(const GfLine2d &line, const GfLineSeg2d &seg, GfVec2d *p1=nullptr, GfVec2d *p2=nullptr, double *t1=nullptr, double *t2=nullptr)
Computes the closets points on line and seg.