Point Cloud Library (PCL)  1.14.1-dev
opennurbs_line.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(ON_LINE_INC_)
18 #define ON_LINE_INC_
19 
20 class ON_CLASS ON_Line
21 {
22 public:
23 
25  ON_Line( const ON_3dPoint& start, const ON_3dPoint& end );
27 
28  /*
29  Returns:
30  True if from != to.
31  */
32  bool IsValid() const;
33 
34  // line[0] = start point line[1] = end point
36  const ON_3dPoint& operator[](int) const;
37 
38 
39  // Description:
40  // Create a line from two points.
41  // Parameters:
42  // start - [in] point at start of line segment
43  // end - [in] point at end of line segment
44  // Returns:
45  // true if start and end are distinct points.
46  bool Create(
47  const ON_3dPoint& start,
48  const ON_3dPoint& end
49  );
50 
51  /*
52  Description:
53  Get line's 3d axis aligned bounding box.
54  Returns:
55  3d bounding box.
56  */
58 
59  /*
60  Description:
61  Get line's 3d axis aligned bounding box or the
62  union of the input box with the object's bounding box.
63  Parameters:
64  bbox - [in/out] 3d axis aligned bounding box
65  bGrowBox - [in] (default=false)
66  If true, then the union of the input bbox and the
67  object's bounding box is returned in bbox.
68  If false, the object's bounding box is returned in bbox.
69  Returns:
70  true if object has bounding box and calculation was successful.
71  */
73  ON_BoundingBox& bbox,
74  int bGrowBox = false
75  ) const;
76 
77  /*
78  Description:
79  Get tight bounding box.
80  Parameters:
81  tight_bbox - [in/out] tight bounding box
82  bGrowBox -[in] (default=false)
83  If true and the input tight_bbox is valid, then returned
84  tight_bbox is the union of the input tight_bbox and the
85  line's tight bounding box.
86  xform -[in] (default=NULL)
87  If not NULL, the tight bounding box of the transformed
88  line is calculated. The line is not modified.
89  Returns:
90  True if a valid tight_bbox is returned.
91  */
93  ON_BoundingBox& tight_bbox,
94  int bGrowBox = false,
95  const ON_Xform* xform = 0
96  ) const;
97 
98  /*
99  Description:
100  Get a plane that contains the line.
101  Parameters:
102  plane - [out] a plane that contains the line. The orgin
103  of the plane is at the start of the line. The distance
104  from the end of the line to the plane is <= tolerance.
105  If possible a plane parallel to the world xy, yz or zx
106  plane is returned.
107  tolerance - [in]
108  Returns:
109  true if a coordinate of the line's direction vector is
110  larger than tolerance.
111  */
112  bool InPlane( ON_Plane& plane, double tolerance = 0.0 ) const;
113 
114  // Returns:
115  // Length of line
116  double Length() const;
117 
118  // Returns:
119  // direction vector = line.to - line.from
120  // See Also:
121  // ON_Line::Tangent
123 
124  // Returns:
125  // Unit tangent vector.
126  // See Also:
127  // ON_Line::Direction
129 
130  /*
131  Description:
132  Evaluate point on (infinite) line.
133  Parameters:
134  t - [in] evaluation parameter. t=0 returns line.from
135  and t=1 returns line.to.
136  Returns:
137  (1-t)*line.from + t*line.to.
138  See Also:
139  ON_Line::Direction
140  ON_Line::Tangent
141  */
143  double t
144  ) const;
145 
146  /*
147  Description:
148  Find the point on the (infinite) line that is
149  closest to the test_point.
150  Parameters:
151  test_point - [in]
152  t - [out] line.PointAt(*t) is the point on the line
153  that is closest to test_point.
154  Returns:
155  true if successful.
156  */
158  const ON_3dPoint& test_point,
159  double* t
160  ) const;
161 
162  /*
163  Description:
164  Find the point on the (infinite) line that is
165  closest to the test_point.
166  Parameters:
167  test_point - [in]
168  Returns:
169  The point on the line that is closest to test_point.
170  */
172  const ON_3dPoint& test_point
173  ) const;
174 
175  /*
176  Description:
177  Find the point on the (infinite) line that is
178  closest to the test_point.
179  Parameters:
180  test_point - [in]
181  Returns:
182  distance from the point on the line that is closest
183  to test_point.
184  See Also:
185  ON_3dPoint::DistanceTo
186  ON_Line::ClosestPointTo
187  */
188  double DistanceTo( ON_3dPoint test_point ) const;
189 
190 
191  /*
192  Description:
193  Finds the shortest distance between the line as a finite
194  chord and the other object.
195  Parameters:
196  P - [in]
197  L - [in] (another finite chord)
198  Returns:
199  A value d such that if Q is any point on
200  this line and P is any point on the other object,
201  then d <= Q.DistanceTo(P).
202  */
203  double MinimumDistanceTo( const ON_3dPoint& P ) const;
204  double MinimumDistanceTo( const ON_Line& L ) const;
205 
206  /*
207  Description:
208  Finds the longest distance between the line as a finite
209  chord and the other object.
210  Parameters:
211  P - [in]
212  L - [in] (another finite chord)
213  Returns:
214  A value d such that if Q is any point on this line and P is any
215  point on the other object, then d >= Q.DistanceTo(P).
216  */
217  double MaximumDistanceTo( const ON_3dPoint& P ) const;
218  double MaximumDistanceTo( const ON_Line& other ) const;
219 
220 
221  /*
222  Description:
223  Quickly determine if the shortest distance from
224  this line to the other object is greater than d.
225  Parameters:
226  d - [in] distance (> 0.0)
227  P - [in]
228  L - [in]
229  Returns:
230  True if if the shortest distance from this line
231  to the other object is greater than d.
232  */
233  bool IsFartherThan( double d, const ON_3dPoint& P ) const;
234  bool IsFartherThan( double d, const ON_Line& L ) const;
235 
236 
237  // For intersections see ON_Intersect();
238 
239  // Description:
240  // Reverse line by swapping from and to.
241  void Reverse();
242 
243  bool Transform(
244  const ON_Xform& xform
245  );
246 
247  // rotate line about a point and axis
248  bool Rotate(
249  double sin_angle,
250  double cos_angle,
251  const ON_3dVector& axis_of_rotation,
252  const ON_3dPoint& center_of_rotation
253  );
254 
255  bool Rotate(
256  double angle_in_radians,
257  const ON_3dVector& axis_of_rotation,
258  const ON_3dPoint& center_of_rotation
259  );
260 
261  bool Translate(
262  const ON_3dVector& delta
263  );
264 
265 public:
266  ON_3dPoint from; // start point
267  ON_3dPoint to; // end point
268 };
269 
270 #endif
double MaximumDistanceTo(const ON_3dPoint &P) const
ON_3dPoint to
ON_3dVector Tangent() const
double Length() const
ON_BoundingBox BoundingBox() const
double MaximumDistanceTo(const ON_Line &other) const
bool Rotate(double angle_in_radians, const ON_3dVector &axis_of_rotation, const ON_3dPoint &center_of_rotation)
ON_3dPoint from
bool IsFartherThan(double d, const ON_3dPoint &P) const
bool IsFartherThan(double d, const ON_Line &L) const
bool GetBoundingBox(ON_BoundingBox &bbox, int bGrowBox=false) const
bool Create(const ON_3dPoint &start, const ON_3dPoint &end)
double MinimumDistanceTo(const ON_Line &L) const
bool Rotate(double sin_angle, double cos_angle, const ON_3dVector &axis_of_rotation, const ON_3dPoint &center_of_rotation)
bool IsValid() const
ON_3dPoint PointAt(double t) const
bool Transform(const ON_Xform &xform)
ON_3dVector Direction() const
ON_Line(const ON_3dPoint &start, const ON_3dPoint &end)
bool InPlane(ON_Plane &plane, double tolerance=0.0) const
ON_3dPoint ClosestPointTo(const ON_3dPoint &test_point) const
const ON_3dPoint & operator[](int) const
bool Translate(const ON_3dVector &delta)
bool ClosestPointTo(const ON_3dPoint &test_point, double *t) const
bool GetTightBoundingBox(ON_BoundingBox &tight_bbox, int bGrowBox=false, const ON_Xform *xform=0) const
ON_3dPoint & operator[](int)
void Reverse()
double DistanceTo(ON_3dPoint test_point) const
double MinimumDistanceTo(const ON_3dPoint &P) const