Loading...
Searching...
No Matches
line2d.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_LINE2D_H
8#define PXR_BASE_GF_LINE2D_H
9
12
13#include "pxr/pxr.h"
14#include "pxr/base/gf/vec2d.h"
15#include "pxr/base/gf/api.h"
16
17#include <float.h>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
32class GfLine2d {
33
34 public:
35
38 }
39
41 GfLine2d(const GfVec2d &p0, const GfVec2d &dir ) {
42 Set( p0, dir );
43 }
44
45 double Set(const GfVec2d &p0, const GfVec2d &dir ) {
46 _p0 = p0;
47 _dir = dir;
48 return _dir.Normalize();
49 }
50
53 GfVec2d GetPoint( double t ) const { return _p0 + _dir * t; }
54
56 const GfVec2d &GetDirection() const { return _dir; }
57
61 GF_API
62 GfVec2d FindClosestPoint(const GfVec2d &point, double *t = NULL) const;
63
66 bool operator ==(const GfLine2d &l) const {
67 return _p0 == l._p0 && _dir == l._dir;
68 }
69
72 bool operator !=(const GfLine2d &r) const {
73 return ! (*this == r);
74 }
75
76 private:
77 GF_API
78 friend bool GfFindClosestPoints( const GfLine2d &, const GfLine2d &,
79 GfVec2d *, GfVec2d *,
80 double *, double *);
81
82 // Parametric description:
83 // l(t) = _p0 + t * _length * _dir;
84 GfVec2d _p0;
85 GfVec2d _dir;
86};
87
96GF_API
97bool GfFindClosestPoints(const GfLine2d &l1, const GfLine2d &l2,
98 GfVec2d *p1 = nullptr, GfVec2d *p2 = nullptr,
99 double *t1 = nullptr, double *t2 = nullptr);
100
101PXR_NAMESPACE_CLOSE_SCOPE
102
103#endif // PXR_BASE_GF_LINE2D_H
Basic type: 2D line.
Definition: line2d.h:32
bool operator==(const GfLine2d &l) const
Component-wise equality test.
Definition: line2d.h:66
const GfVec2d & GetDirection() const
Return the normalized direction of the line.
Definition: line2d.h:56
GfLine2d(const GfVec2d &p0, const GfVec2d &dir)
Construct a line from a point and a direction.
Definition: line2d.h:41
GfLine2d()
The default constructor leaves line parameters undefined.
Definition: line2d.h:37
bool operator!=(const GfLine2d &r) const
Component-wise inequality test.
Definition: line2d.h:72
GfVec2d GetPoint(double t) const
Return the point on the line at ( p0 + t * dir ).
Definition: line2d.h:53
GF_API friend bool GfFindClosestPoints(const GfLine2d &, const GfLine2d &, GfVec2d *, GfVec2d *, double *, double *)
Computes the closets points between two lines.
GF_API GfVec2d FindClosestPoint(const GfVec2d &point, double *t=NULL) const
Returns the point on the line that is closest to point.
Basic type for a vector of 2 double components.
Definition: vec2d.h:46
double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
Definition: vec2d.h:241
GF_API bool GfFindClosestPoints(const GfLine2d &l1, const GfLine2d &l2, GfVec2d *p1=nullptr, GfVec2d *p2=nullptr, double *t1=nullptr, double *t2=nullptr)
Computes the closets points between two lines.