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