This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
line.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_H
8#define PXR_BASE_GF_LINE_H
9
12
13#include "pxr/pxr.h"
14#include "pxr/base/gf/vec3d.h"
15
16#include <float.h>
17#include <iosfwd>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
32class GfLine {
33
34 public:
35
38 }
39
41 GfLine(const GfVec3d &p0, const GfVec3d &dir ) {
42 Set( p0, dir );
43 }
44
45 double Set(const GfVec3d &p0, const GfVec3d &dir ) {
46 _p0 = p0;
47 _dir = dir;
48 return _dir.Normalize();
49 }
50
53 GfVec3d GetPoint( double t ) const { return _p0 + _dir * t; }
54
56 const GfVec3d &GetDirection() const { return _dir; }
57
61 GF_API
62 GfVec3d FindClosestPoint(const GfVec3d &point, double *t = NULL) const;
63
66 bool operator ==(const GfLine &l) const {
67 return _p0 == l._p0 && _dir == l._dir;
68 }
69
72 bool operator !=(const GfLine &r) const {
73 return ! (*this == r);
74 }
75
76 private:
77 GF_API
78 friend bool GfFindClosestPoints( const GfLine &, const GfLine &,
79 GfVec3d *, GfVec3d *,
80 double *, double * );
81 // Parametric description:
82 // l(t) = _p0 + t * _length * _dir;
83 GfVec3d _p0;
84 GfVec3d _dir;
85};
86
95GF_API
96bool GfFindClosestPoints(const GfLine &l1, const GfLine &l2,
97 GfVec3d *p1 = nullptr, GfVec3d *p2 = nullptr,
98 double *t1 = nullptr, double *t2 = nullptr);
99
102GF_API std::ostream &operator<<(std::ostream&, const GfLine&);
103
104PXR_NAMESPACE_CLOSE_SCOPE
105
106#endif // PXR_BASE_GF_LINE_H
Basic type: 3D line.
Definition: line.h:32
GfLine(const GfVec3d &p0, const GfVec3d &dir)
Construct a line from a point and a direction.
Definition: line.h:41
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
GfLine()
The default constructor leaves line parameters undefined.
Definition: line.h:37
GF_API friend bool GfFindClosestPoints(const GfLine &, const GfLine &, GfVec3d *, GfVec3d *, double *, double *)
Computes the closets points between two lines.
bool operator!=(const GfLine &r) const
Component-wise inequality test.
Definition: line.h:72
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 GfLine &l) const
Component-wise equality test.
Definition: line.h:66
Basic type for a vector of 3 double components.
Definition: vec3d.h:46
double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
Definition: vec3d.h:252
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
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.