opennurbs_arc.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_ARC_INC_)
18 #define ON_ARC_INC_
19 
20 /*
21 Description:
22  An ON_Arc is a subcurve of 3d circle.
23 Details:
24  The curve is parameterized by an angle expressed in radians. For an IsValid() arc
25  the total subtended angle AngleRadians() = Domain()(1) - Domain()(0) must satisfy
26  0< AngleRadians() <2*Pi .
27 
28  The parameterization of the ON_Arc is inherited from the ON_Circle it is derived from.
29  In particular
30  t -> center + cos(t)*radius*xaxis + sin(t)*radius*yaxis
31  where xaxis and yaxis, (part of ON_Circle::m_plane) form an othonormal frame of the plane
32  containing the circle.
33 */
34 class ON_CLASS ON_Arc : public ON_Circle
35 {
36 public:
37  // Create a radius one arc with angle = 2*pi
38  ON_Arc() = default;
39  ~ON_Arc() = default;
40  ON_Arc(const ON_Arc&) = default;
41  ON_Arc& operator=(const ON_Arc&) = default;
42 
43  ON_Arc& operator=( const ON_Circle& );
44 
45  static const ON_Arc UnitCircle; // unit circle in the xy plane
46 
47  /*
48  Description:
49  Construct an arc from a circle and an angle in radians
50  Parameters:
51  circle - [in]
52  angle_in_radians - [in]
53  */
54  ON_Arc(
55  const ON_Circle& circle,
56  double angle_in_radians
57  );
58 
59  /*
60  Parameters:
61  circle - [in]
62  angle_interval_in_radians - [in] increasing angle interval
63  in radians with angle_interval_in_radians.Length() <= 2.0*ON_PI.
64  */
65  ON_Arc(
66  const ON_Circle& circle,
67  ON_Interval angle_interval_in_radians
68  );
69 
70  /*
71  Description:
72  Construct an arc from a plane, radius and an angle in radians.
73  The center of the arc is at the plane's origin.
74  Parameters:
75  plane - [in]
76  circle is in this plane with center at m_origin
77  center - [in]
78  circle's center point
79  radius - [in]
80  angle_in_radians - [in]
81  */
82  ON_Arc(
83  const ON_Plane& plane,
84  double radius,
85  double angle_in_radians
86  );
87 
88  /*
89  Description:
90  Construct an arc parallel to the world XY plane from a
91  center point, radius, and angle in radians.
92  The arc starts at center+(radius,0,0).
93  Parameters:
94  center - [in]
95  radius - [in]
96  angle_in_radians - [in]
97  */
98  ON_Arc(
99  const ON_3dPoint& center,
100  double radius,
101  double angle_in_radians
102  );
103 
104  /*
105  Description:
106  Construct an arc parallel to plane from a center point,
107  radius, and angle in radians.
108  The arc starts at center+radius*plane.xaxis.
109  Parameters:
110  plane - [in]
111  The plane x, y and z axis are used to defines the circle
112  plane's x, y and z axis. The plane origin is ignorned.
113  center - [in]
114  circle's center point
115  radius - [in]
116  angle_in_radians - [in]
117  */
118  ON_Arc(
119  const ON_Plane& plane,
120  const ON_3dPoint& center,
121  double radius,
122  double angle_in_radians
123  );
124 
125  /*
126  Description:
127  Construct an arc that passes through three 2d points.
128  Parameters:
129  start_point - [in]
130  interior_point - [in]
131  end_point - [in]
132  */
133  ON_Arc(
134  const ON_2dPoint& start_point,
135  const ON_2dPoint& interior_point,
136  const ON_2dPoint& end_point
137  );
138 
139  /*
140  Description:
141  Construct an arc that passes through three 3d points.
142  Parameters:
143  start_point - [in]
144  interior_point - [in]
145  end_point - [in]
146  */
147  ON_Arc(
148  const ON_3dPoint& start_point,
149  const ON_3dPoint& interior_point,
150  const ON_3dPoint& end_point
151  );
152 
153  /*
154  Description:
155  Create an arc from a circle and an angle in radians
156  Parameters:
157  circle - [in]
158  angle_in_radians - [in]
159  Returns:
160  true if input is valid and a valid arc is created.
161  */
162  bool Create(
163  const ON_Circle& circle,
164  double angle_in_radians
165  );
166 
167  /*
168  Description:
169  Create an arc from a circle and an increasing angle interval
170  Parameters:
171  circle - [in]
172  angle_interval_in_radians - [in] increasing angle interval in radians
173  with angle_interval_in_radians.Length() <= 2.0*ON_PI
174  Returns:
175  true if input is valid and a valid arc is created.
176  */
177  bool Create(
178  const ON_Circle& circle,
179  ON_Interval angle_interval_in_radians
180  );
181 
182  /*
183  Description:
184  Create an arc from a plane, radius and an angle in radians.
185  The center of the arc is at the plane's origin.
186  Parameters:
187  plane - [in]
188  circle is in this plane with center at m_origin
189  center - [in]
190  circle's center point
191  radius - [in]
192  angle_in_radians - [in]
193  */
194  bool Create(
195  const ON_Plane& plane,
196  double radius,
197  double angle_in_radians
198  );
199 
200  /*
201  Description:
202  Create an arc parallel to the world XY plane from a
203  center point, radius, and angle in radians.
204  The arc starts at center+(radius,0,0).
205  Parameters:
206  center - [in]
207  radius - [in]
208  angle_in_radians - [in]
209  */
210  bool Create(
211  const ON_3dPoint& center,
212  double radius,
213  double angle_in_radians
214  );
215 
216  /*
217  Description:
218  Create an arc parallel to plane from a center point,
219  radius, and angle in radians.
220  The arc starts at center+radius*plane.xaxis.
221  Parameters:
222  plane - [in]
223  The plane x, y and z axis are used to defines the circle
224  plane's x, y and z axis. The plane origin is ignorned.
225  center - [in]
226  circle's center point
227  radius - [in]
228  angle_in_radians - [in]
229  */
230  bool Create(
231  const ON_Plane& plane,
232  const ON_3dPoint& center,
233  double radius,
234  double angle_in_radians
235  );
236 
237  /*
238  Description:
239  Create an arc that passes through three 2d points.
240  Parameters:
241  start_point - [in]
242  interior_point - [in]
243  end_point - [in]
244  */
245  bool Create(
246  const ON_2dPoint& start_point,
247  const ON_2dPoint& interior_point,
248  const ON_2dPoint& end_point
249  );
250 
251  /*
252  Description:
253  Create an arc that passes through three 3d points.
254  Parameters:
255  start_point - [in]
256  interior_point - [in]
257  end_point - [in]
258  */
259  bool Create(
260  const ON_3dPoint& start_point,
261  const ON_3dPoint& interior_point,
262  const ON_3dPoint& end_point
263  );
264 
265  /*
266  Description:
267  Create an arc from a 2d start point, 2d start direction
268  and a 2d end point.
269  Parameters:
270  start_point - [in]
271  dir_at_start - [in]
272  end_point - [in]
273  */
274  bool Create(
275  const ON_2dPoint& start_point,
276  const ON_2dVector& dir_at_start,
277  const ON_2dPoint& end_point
278  );
279 
280  /*
281  Description:
282  Create an arc from a 3d start point, 3d start direction
283  and a 3d end point.
284  Parameters:
285  start_point - [in]
286  dir_at_start - [in]
287  end_point - [in]
288  */
289  bool Create(
290  const ON_3dPoint& start_point,
291  const ON_3dVector& dir_at_start,
292  const ON_3dPoint& end_point
293  );
294 
295  // Description:
296  // Creates a text dump of the arc listing the normal, center
297  // radius, start point, end point, and angle.
298  // Remarks:
299  // Dump() is intended for debugging and is not suitable
300  // for creating high quality text descriptions of an
301  // arc.
302  void Dump( ON_TextLog& dump ) const;
303 
304  // Description:
305  // Checks an arc to make sure it is valid.
306  // Detail:
307  // Radius>0 and 0<AngleRadians()<=2 ON_PI
308  // Returns:
309  // true if the arc is valid.
310  bool IsValid() const;
311 
312  // Description:
313  // Get arc's 3d axis aligned bounding box.
314  // Returns:
315  // 3d bounding box.
316  ON_BoundingBox BoundingBox() const;
317 
318  // Description:
319  // Get arc's 3d axis aligned bounding box or the
320  // union of the input box with the arc's bounding box.
321  // Parameters:
322  // bbox - [in/out] 3d axis aligned bounding box
323  // bGrowBox - [in] (default=false)
324  // If true, then the union of the input bbox and the
325  // arc's bounding box is returned in bbox.
326  // If false, the arc's bounding box is returned in bbox.
327  // Returns:
328  // true if arc has bounding box and calculation was successful.
329  bool GetBoundingBox(
330  ON_BoundingBox& bbox,
331  int bGrowBox = false
332  ) const;
333 
334  /*
335  Description:
336  Get tight bounding box.
337  Parameters:
338  tight_bbox - [in/out] tight bounding box
339  bGrowBox -[in] (default=false)
340  If true and the input tight_bbox is valid, then returned
341  tight_bbox is the union of the input tight_bbox and the
342  arc's tight bounding box.
343  xform -[in] (default=nullptr)
344  If not nullptr, the tight bounding box of the transformed
345  arc is calculated. The arc is not modified.
346  Returns:
347  True if a valid tight_bbox is returned.
348  */
349  bool GetTightBoundingBox(
350  ON_BoundingBox& tight_bbox,
351  bool bGrowBox = false,
352  const ON_Xform* xform = nullptr
353  ) const;
354 
355  // Returns:
356  // true if the arc is a complete circle; i.e., the arc's
357  // angle is 360 degrees.
358  bool IsCircle() const;
359 
360  // Returns:
361  // The arc's subtended angle in radians.
362  double AngleRadians() const;
363 
364  // Returns:
365  // The arc's subtended angle in degrees.
366  double AngleDegrees() const;
367 
368 
369  /*
370  Description:
371  Get evaluation domain.
372  Returns:
373  Evaluation domain (same as DomainRadians()).
374  */
375  ON_Interval Domain() const;
376 
377  // Returns:
378  // The arc's domain in radians.
379  ON_Interval DomainRadians() const;
380 
381  // Returns:
382  // The arc's domain in degrees.
383  ON_Interval DomainDegrees() const;
384 
385  // Description:
386  // Set arc's subtended angle in radians.
387  // Parameters:
388  // angle_in_radians - [in] 0 <= angle_in_radians <= 2.0*ON_PI
389  //
390  bool SetAngleRadians(
391  double angle_in_radians
392  );
393 
394  /*
395  Description:
396  Set arc's angle interval in radians.
397  Parameters:
398  angle_in_radians - [in] increasing interval with
399  start and end angle in radians.
400  Length of the interval <= 2.0*ON_PI.
401  Returns:
402  true if successful.
403  */
404  bool SetAngleIntervalRadians(
405  ON_Interval angle_in_radians
406  );
407 
408  // Description:
409  // Set arc's domain as a subdomain of the circle.
410  // Parameters:
411  // domain_radian - [in] 0 < domain_radian[1] - domain_radian[0] <= 2.0 * ON*PI
412  //
413  bool Trim(
414  ON_Interval domain_radian
415  );
416 
417  // Description:
418  // Set arc's subtended angle in degrees.
419  // Parameters:
420  // angle_in_degrees - [in] 0 < angle_in_degrees <= 360
421  bool SetAngleDegrees(
422  double angle_in_degrees
423  );
424 
425  // Returns:
426  // Point at start of the arc.
427  ON_3dPoint StartPoint() const;
428 
429 
430  // Returns:
431  // Point at middle of the arc.
432  ON_3dPoint MidPoint() const;
433 
434  // Returns:
435  // Point at end of the arc.
436  ON_3dPoint EndPoint() const;
437 
438  // Description:
439  // Get the point on the arc that is closest to test_point.
440  // Parameters:
441  // test_point - [in]
442  // t - [out] parameter (in radians) of the point on the arc that
443  // is closest to test_point. If test_point is the center
444  // of the arc, then the starting point of the arc is
445  // (arc.Domain()[0]) returned.
446  bool ClosestPointTo(
447  const ON_3dPoint& test_point,
448  double* t
449  ) const;
450 
451  // Description:
452  // Get the point on the arc that is closest to test_point.
453  // Parameters:
454  // test_point - [in]
455  // Returns:
456  // The point on the arc that is closest to test_point.
457  // If test_point is the center of the arc, then the
458  // starting point of the arc is returned.
460  const ON_3dPoint& test_point
461  ) const;
462 
463  // Returns:
464  // Length of the arc = radius*(subtended angle in radians).
465  double Length() const;
466 
467  /*
468  Returns:
469  Area of the arc's sector.
470  Remarks:
471  The arc's sector is the region bounded by the arc,
472  the line segment from the arc's end to the center,
473  and the line segment from the center to the arc's
474  start.
475  */
476  double SectorArea() const;
477 
478  /*
479  Returns:
480  Area centroid of the arc's sector.
481  Remarks:
482  The arc's sector is the region bounded by the arc,
483  the line segment from the arc's end to the center,
484  and the line segment from the center to the arc's
485  start.
486  */
487  ON_3dPoint SectorAreaCentroid() const;
488 
489  /*
490  Returns:
491  Area of the arc's segment.
492  Remarks:
493  The arc's segment is the region bounded by the arc and
494  the line segment from the arc's end to the arc's start.
495  */
496  double SegmentArea() const;
497 
498  /*
499  Returns:
500  Area centroid of the arc's segment.
501  Remarks:
502  The arc's segment is the region bounded by the arc and
503  the line segment from the arc's end to the arc's start.
504  */
505  ON_3dPoint SegmentAreaCentroid() const;
506 
507  // Description:
508  // Reverse the orientation of the arc. Changes the domain
509  // from [a,b] to [-b.-a].
510  bool Reverse();
511 
512  // Description:
513  // Get a rational degree 2 NURBS curve representation
514  // of the arc. Note that the parameterization of NURBS curve
515  // does not match arc's transcendental paramaterization.
516  // Use GetRadianFromNurbFormParameter() and
517  // GetParameterFromRadian() to convert between the NURBS curve
518  // parameter and the transcendental parameter
519  // Parameters:
520  // nurbs_curve - [out] nurbs_curve returned here.
521  // Returns:
522  // 0 for failure and 2 for success.
523  int GetNurbForm(
524  ON_NurbsCurve& nurbs_curve
525  ) const;
526 
527  /*
528  Description:
529  Convert a NURBS curve arc parameter to a arc radians parameter.
530  Parameters:
531  nurbs_parameter - [in]
532  arc_radians_parameter - [out]
533  Example:
534 
535  ON_Arc arc = ...;
536  double nurbs_t = 1.2345; // some number in interval (0,2.0*ON_PI).
537  double arc_t;
538  arc.GetRadianFromNurbFormParameter( nurbs_t, &arc_t );
539 
540  ON_NurbsCurve nurbs_curve;
541  arc.GetNurbsForm( nurbs_curve );
542  arc_pt = arc.PointAt(arc_t);
543  nurbs_pt = nurbs_curve.PointAt(nurbs_t);
544  // arc_pt and nurbs_pt will be the same
545 
546  Remarks:
547  The NURBS curve parameter is with respect to the NURBS curve
548  created by ON_Arc::GetNurbForm. At nurbs parameter values of
549  0.0, 0.5*ON_PI, ON_PI, 1.5*ON_PI, and 2.0*ON_PI, the nurbs
550  parameter and radian parameter are the same. At all other
551  values the nurbs and radian parameter values are different.
552  See Also:
553  ON_Arc::GetNurbFormParameterFromRadian
554  */
556  double nurbs_parameter,
557  double* arc_radians_parameter
558  ) const;
559 
560  /*
561  Description:
562  Convert a arc radians parameter to a NURBS curve arc parameter.
563  Parameters:
564  arc_radians_parameter - [in] 0.0 to 2.0*ON_PI
565  nurbs_parameter - [out]
566  Example:
567 
568  ON_Arc arc = ...;
569  double arc_t = 1.2345; // some number in interval (0,2.0*ON_PI).
570  double nurbs_t;
571  arc.GetNurbFormParameterFromRadian( arc_t, &nurbs_t );
572 
573  ON_NurbsCurve nurbs_curve;
574  arc.GetNurbsForm( nurbs_curve );
575  arc_pt = arc.PointAt(arc_t);
576  nurbs_pt = nurbs_curve.PointAt(nurbs_t);
577  // arc_pt and nurbs_pt will be the same
578 
579  Remarks:
580  The NURBS curve parameter is with respect to the NURBS curve
581  created by ON_Arc::GetNurbForm. At radian values of
582  0.0, 0.5*ON_PI, ON_PI, 1.5*ON_PI, and 2.0*ON_PI, the nurbs
583  parameter and radian parameter are the same. At all other
584  values the nurbs and radian parameter values are different.
585  See Also:
586  ON_Arc::GetNurbFormParameterFromRadian
587  */
589  double arc_radians_parameter,
590  double* nurbs_parameter
591  ) const;
592 
593 private:
594  friend bool ON_BinaryArchive::ReadArc( ON_Arc& );
595  friend bool ON_BinaryArchive::WriteArc( const ON_Arc& );
596 
597  // increasing interval with start and end angle in radians
599 };
600 
601 #endif
602 
bool GetTightBoundingBox(ON_BoundingBox &tight_bbox, bool bGrowBox=false, const ON_Xform *xform=nullptr) const
Get tight bounding box.
bool GetRadianFromNurbFormParameter(double nurbs_parameter, double *circle_radians_parameter) const
Convert a NURBS curve circle parameter to a circle radians parameter.
An ON_Arc is a subcurve of 3d circle.
Definition: opennurbs_arc.h:33
static const ON_Interval ZeroToTwoPi
Definition: opennurbs_point.h:51
bool ReadArc(ON_Arc &)
int GetNurbForm(ON_NurbsCurve &nurbs_curve) const
Get a four span rational degree 2 NURBS circle representation of the circle.
ON_Circle is a circle in 3d. The cirle is represented by a radius and an orthonormal frame of the pla...
Definition: opennurbs_circle.h:32
Definition: opennurbs_point.h:277
bool GetNurbFormParameterFromRadian(double circle_radians_parameter, double *nurbs_parameter) const
Convert a circle radians parameter to a NURBS curve circle parameter.
bool WriteArc(const ON_Arc &)
Definition: opennurbs_bounding_box.h:25
Definition: opennurbs_xform.h:28
ON_BoundingBox BoundingBox() const
bool IsValid() const
A Valid circle has m_radius>0 and m_plane.IsValid().
bool Create(const ON_Plane &plane, double radius)
Definition: opennurbs_nurbscurve.h:26
Definition: opennurbs_textlog.h:20
static const ON_Circle UnitCircle
Definition: opennurbs_circle.h:44
bool ClosestPointTo(const ON_3dPoint &point, double *t) const
returns parameters of point on circle that is closest to given point
Definition: opennurbs_point.h:460
Definition: opennurbs_plane.h:20
Definition: opennurbs_point.h:839
Definition: opennurbs_point.h:1152
Definition: opennurbs_point.h:46
bool Reverse()
ON_Circle & operator=(const ON_Circle &)=default