opennurbs_circle.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_CIRCLE_INC_)
18 #define ON_CIRCLE_INC_
19 
20 class ON_NurbsCurve;
21 
22 /*
23 Description:
24  ON_Circle is a circle in 3d. The cirle is represented by a radius and an
25  orthonormal frame of the plane containing the circle, with origin at the center.
26 
27  An Is_Valid() circle has positive radius and an Is_ Valid() plane defining the frame.
28 
29  The circle is parameterized by radians from 0 to 2 Pi given by
30  t -> center + cos(t)*radius*xaxis + sin(t)*radius*yaxis
31  where center, xaxis and yaxis define the orthonormal frame of the circle's plane.
32 */
33 class ON_CLASS ON_Circle
34 {
35 public:
36 
38  double radius = 1.0;
39 
40  ON_Circle() = default;
41  ~ON_Circle() = default;
42  ON_Circle(const ON_Circle&) = default;
43  ON_Circle& operator=(const ON_Circle&) = default;
44 
45  static const ON_Circle UnitCircle; // unit circle in the xy plane
46 
47  // Creates a circle in the plane with center at
48  // plane.origin.
49  ON_Circle(
50  const ON_Plane& plane,
51  double radius
52  );
53 
54  // Creates a circle parallel to the world XY plane
55  // with given center and radius
56  ON_Circle(
57  const ON_3dPoint& center,
58  double radius
59  );
60 
61  // Creates a circle parallel to the plane
62  // with given center and radius.
63  ON_Circle(
64  const ON_Plane& plane,
65  const ON_3dPoint& center,
66  double radius
67  );
68 
69  // Create a circle through three 2d points.
70  // The start/end of the circle is at point P.
71  ON_Circle( // circle through 3 2d points
72  const ON_2dPoint& P,
73  const ON_2dPoint& Q,
74  const ON_2dPoint& R
75  );
76 
77  // Create a circle through three 3d points.
78  // The start/end of the circle is at point P.
79  ON_Circle(
80  const ON_3dPoint& P,
81  const ON_3dPoint& Q,
82  const ON_3dPoint& R
83  );
84 
85  // Creates a circle in the plane with center at
86  // plane.origin.
87  bool Create(
88  const ON_Plane& plane,
89  double radius
90  );
91 
92  // Creates a circle parallel to the world XY plane
93  // with given center and radius
94  bool Create(
95  const ON_3dPoint& center,
96  double radius
97  );
98 
99  // Creates a circle parallel to the plane
100  // with given centr and radius.
101  bool Create(
102  const ON_Plane& plane,
103  const ON_3dPoint& center,
104  double radius
105  );
106 
107  // Create a circle through three 2d points.
108  // The start/end of the circle is at point P.
109  bool Create( // circle through 3 2d points
110  const ON_2dPoint& P,
111  const ON_2dPoint& Q,
112  const ON_2dPoint& R
113  );
114 
115  // Create a circle through three 3d points.
116  // The start/end of the circle is at point P.
117  bool Create(
118  const ON_3dPoint& P,
119  const ON_3dPoint& Q,
120  const ON_3dPoint& R
121  );
122 
123  // Create a circle from two 2d points and a
124  // tangent at the first point.
125  // The start/end of the circle is at point P.
126  bool Create(
127  const ON_2dPoint& P,
128  const ON_2dVector& tangent_at_P,
129  const ON_2dPoint& Q
130  );
131 
132  // Create a circle from two 3d points and a
133  // tangent at the first point.
134  // The start/end of the circle is at point P.
135  bool Create(
136  const ON_3dPoint& P,
137  const ON_3dVector& tangent_at_P,
138  const ON_3dPoint& Q
139  );
140 
141  // A Valid circle has m_radius>0 and m_plane.IsValid().
142  bool IsValid() const;
143 
144  //bool UpdatePoints(); // sets m_point[] to have valid points
145 
146  bool IsInPlane( const ON_Plane&, double = ON_ZERO_TOLERANCE ) const;
147 
148  double Radius() const;
149  double Diameter() const;
150  double Circumference() const;
151  const ON_3dPoint& Center() const;
152  const ON_3dVector& Normal() const;
153  const ON_Plane& Plane() const; // plane containing circle
154 
155  ON_BoundingBox BoundingBox() const;
156 
157  /*
158  Description:
159  Get tight bounding box.
160  Parameters:
161  tight_bbox - [in/out] tight bounding box
162  bGrowBox -[in] (default=false)
163  If true and the input tight_bbox is valid, then returned
164  tight_bbox is the union of the input tight_bbox and the
165  arc's tight bounding box.
166  xform -[in] (default=nullptr)
167  If not nullptr, the tight bounding box of the transformed
168  arc is calculated. The arc is not modified.
169  Returns:
170  True if a valid tight_bbox is returned.
171  */
172  bool GetTightBoundingBox(
173  ON_BoundingBox& tight_bbox,
174  bool bGrowBox = false,
175  const ON_Xform* xform = nullptr
176  ) const;
177 
178  bool Transform( const ON_Xform& );
179 
180  // Circles use trigonometric parameterization
181  // t -> center + cos(t)*radius*xaxis + sin(t)*radius*yaxis
182  ON_3dPoint PointAt(
183  double // evaluation parameter
184  ) const;
185  ON_3dVector DerivativeAt(
186  int, // derivative (>=0)
187  double // evaluation parameter
188  ) const;
189 
190  ON_3dVector TangentAt(double) const;
191 
192  // returns parameters of point on circle that is closest to given point
193  bool ClosestPointTo(
194  const ON_3dPoint& point,
195  double* t
196  ) const;
197 
198  // returns point on circle that is closest to given point
199  ON_3dPoint ClosestPointTo(
200  const ON_3dPoint& point
201  ) const;
202 
203  // evaluate circle's implicit equation in plane
204  double EquationAt( const ON_2dPoint& plane_point ) const;
205 
206  ON_2dVector GradientAt( const ON_2dPoint& plane_point ) const;
207 
208  // rotate circle about its center
209  bool Rotate(
210  double sin_angle,
211  double cos_angle,
212  const ON_3dVector& axis_of_rotation
213  );
214 
215  bool Rotate(
216  double angle_in_radians,
217  const ON_3dVector& axis_of_rotation
218  );
219 
220  // rotate circle about a point and axis
221  bool Rotate(
222  double sin_angle,
223  double cos_angle,
224  const ON_3dVector& axis_of_rotation,
225  const ON_3dPoint& center_of_rotation
226  );
227 
228  bool Rotate(
229  double angle_in_radians,
230  const ON_3dVector& axis_of_rotation,
231  const ON_3dPoint& center_of_rotation
232  );
233 
234  bool Translate(
235  const ON_3dVector& delta
236  );
237 
238  bool Reverse();
239 
240  // Description:
241  // Get a four span rational degree 2 NURBS circle representation
242  // of the circle.
243  // Returns:
244  // 2 for success, 0 for failure
245  // Remarks:
246  // Note that the parameterization of NURBS curve
247  // does not match circle's transcendental paramaterization.
248  // Use ON_Circle::GetRadianFromNurbFormParameter() and
249  // ON_Circle::GetParameterFromRadian() to convert between
250  // the NURBS curve parameter and the transcendental parameter.
251  int GetNurbForm(
252  ON_NurbsCurve& nurbs_curve
253  ) const;
254 
255  /*
256  Description:
257  Convert a NURBS curve circle parameter to a circle radians parameter.
258  Parameters:
259  nurbs_parameter - [in]
260  circle_radians_parameter - [out]
261  Example:
262 
263  ON_Circle circle = ...;
264  double nurbs_t = 1.2345; // some number in interval (0,2.0*ON_PI).
265  double circle_t;
266  circle.GetRadianFromNurbFormParameter( nurbs_t, &circle_t );
267 
268  ON_NurbsCurve nurbs_curve;
269  circle.GetNurbsForm( nurbs_curve );
270  circle_pt = circle.PointAt(circle_t);
271  nurbs_pt = nurbs_curve.PointAt(nurbs_t);
272  // circle_pt and nurbs_pt will be the same
273 
274  Remarks:
275  The NURBS curve parameter is with respect to the NURBS curve
276  created by ON_Circle::GetNurbForm. At nurbs parameter values of
277  0.0, 0.5*ON_PI, ON_PI, 1.5*ON_PI, and 2.0*ON_PI, the nurbs
278  parameter and radian parameter are the same. At all other
279  values the nurbs and radian parameter values are different.
280  See Also:
281  ON_Circle::GetNurbFormParameterFromRadian
282  */
283  bool GetRadianFromNurbFormParameter(
284  double nurbs_parameter,
285  double* circle_radians_parameter
286  ) const;
287 
288  /*
289  Description:
290  Convert a circle radians parameter to a NURBS curve circle parameter.
291  Parameters:
292  circle_radians_parameter - [in] 0.0 to 2.0*ON_PI
293  nurbs_parameter - [out]
294  Example:
295 
296  ON_Circle circle = ...;
297  double circle_t = 1.2345; // some number in interval (0,2.0*ON_PI).
298  double nurbs_t;
299  circle.GetNurbFormParameterFromRadian( circle_t, &nurbs_t );
300 
301  ON_NurbsCurve nurbs_curve;
302  circle.GetNurbsForm( nurbs_curve );
303  circle_pt = circle.PointAt(circle_t);
304  nurbs_pt = nurbs_curve.PointAt(nurbs_t);
305  // circle_pt and nurbs_pt will be the same
306 
307  Remarks:
308  The NURBS curve parameter is with respect to the NURBS curve
309  created by ON_Circle::GetNurbForm. At radian values of
310  0.0, 0.5*ON_PI, ON_PI, 1.5*ON_PI, and 2.0*ON_PI, the nurbs
311  parameter and radian parameter are the same. At all other
312  values the nurbs and radian parameter values are different.
313  See Also:
314  ON_Circle::GetNurbFormParameterFromRadian
315  */
316  bool GetNurbFormParameterFromRadian(
317  double circle_radians_parameter,
318  double* nurbs_parameter
319  ) const;
320 
321 };
322 
323 
324 #endif
325 
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
static const ON_Plane World_xy
world plane coordinate system ON_Plane(ON_3dPoint::Origin, ON_3dVector::XAxis, ON_3dVector::YAxis); ...
Definition: opennurbs_plane.h:483
Definition: opennurbs_bounding_box.h:25
Definition: opennurbs_xform.h:28
Definition: opennurbs_nurbscurve.h:26
Definition: opennurbs_point.h:460
Definition: opennurbs_plane.h:20
Definition: opennurbs_point.h:839
Definition: opennurbs_point.h:1152