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