00001 /* $NoKeywords: $ */ 00002 /* 00003 // 00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved. 00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert 00006 // McNeel & Associates. 00007 // 00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED. 00011 // 00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>. 00013 // 00015 */ 00016 00017 #if !defined(ON_ARC_INC_) 00018 #define ON_ARC_INC_ 00019 00020 /* 00021 Description: 00022 An ON_Arc is a subcurve of 3d circle. 00023 Details: 00024 The curve is parameterized by an angle expressed in radians. For an IsValid() arc 00025 the total subtended angle AngleRadians() = Domain()(1) - Domain()(0) must satisfy 00026 0< AngleRadians() <2*Pi . 00027 00028 The parameterization of the ON_Arc is inherited from the ON_Circle it is derived from. 00029 In particular 00030 t -> center + cos(t)*radius*xaxis + sin(t)*radius*yaxis 00031 where xaxis and yaxis, (part of ON_Circle::m_plane) form an othonormal frame of the plane 00032 containing the circle. 00033 */ 00034 class ON_CLASS ON_Arc : public ON_Circle 00035 { 00036 public: 00037 // Create a radius one arc with angle = 2*pi 00038 ON_Arc(); 00039 00040 /* 00041 Description: 00042 Construct an arc from a circle and an angle in radians 00043 Parameters: 00044 circle - [in] 00045 angle_in_radians - [in] 00046 */ 00047 ON_Arc( 00048 const ON_Circle& circle, 00049 double angle_in_radians 00050 ); 00051 00052 /* 00053 Parameters: 00054 circle - [in] 00055 angle_interval_in_radians - [in] increasing angle interval 00056 in radians with angle_interval_in_radians.Length() <= 2.0*ON_PI. 00057 */ 00058 ON_Arc( 00059 const ON_Circle& circle, 00060 ON_Interval angle_interval_in_radians 00061 ); 00062 00063 /* 00064 Description: 00065 Construct an arc from a plane, radius and an angle in radians. 00066 The center of the arc is at the plane's origin. 00067 Parameters: 00068 plane - [in] 00069 circle is in this plane with center at m_origin 00070 center - [in] 00071 circle's center point 00072 radius - [in] 00073 angle_in_radians - [in] 00074 */ 00075 ON_Arc( 00076 const ON_Plane& plane, 00077 double radius, 00078 double angle_in_radians 00079 ); 00080 00081 /* 00082 Description: 00083 Construct an arc parallel to the world XY plane from a 00084 center point, radius, and angle in radians. 00085 The arc starts at center+(radius,0,0). 00086 Parameters: 00087 center - [in] 00088 radius - [in] 00089 angle_in_radians - [in] 00090 */ 00091 ON_Arc( 00092 const ON_3dPoint& center, 00093 double radius, 00094 double angle_in_radians 00095 ); 00096 00097 /* 00098 Description: 00099 Construct an arc parallel to plane from a center point, 00100 radius, and angle in radians. 00101 The arc starts at center+radius*plane.xaxis. 00102 Parameters: 00103 plane - [in] 00104 The plane x, y and z axis are used to defines the circle 00105 plane's x, y and z axis. The plane origin is ignorned. 00106 center - [in] 00107 circle's center point 00108 radius - [in] 00109 angle_in_radians - [in] 00110 */ 00111 ON_Arc( 00112 const ON_Plane& plane, 00113 const ON_3dPoint& center, 00114 double radius, 00115 double angle_in_radians 00116 ); 00117 00118 /* 00119 Description: 00120 Construct an arc that passes through three 2d points. 00121 Parameters: 00122 start_point - [in] 00123 interior_point - [in] 00124 end_point - [in] 00125 */ 00126 ON_Arc( 00127 const ON_2dPoint& start_point, 00128 const ON_2dPoint& interior_point, 00129 const ON_2dPoint& end_point 00130 ); 00131 00132 /* 00133 Description: 00134 Construct an arc that passes through three 3d points. 00135 Parameters: 00136 start_point - [in] 00137 interior_point - [in] 00138 end_point - [in] 00139 */ 00140 ON_Arc( 00141 const ON_3dPoint& start_point, 00142 const ON_3dPoint& interior_point, 00143 const ON_3dPoint& end_point 00144 ); 00145 00146 /* 00147 Description: 00148 Create an arc from a circle and an angle in radians 00149 Parameters: 00150 circle - [in] 00151 angle_in_radians - [in] 00152 Returns: 00153 true if input is valid and a valid arc is created. 00154 */ 00155 bool Create( 00156 const ON_Circle& circle, 00157 double angle_in_radians 00158 ); 00159 00160 /* 00161 Description: 00162 Create an arc from a circle and an increasing angle interval 00163 Parameters: 00164 circle - [in] 00165 angle_interval_in_radians - [in] increasing angle interval in radians 00166 with angle_interval_in_radians.Length() <= 2.0*ON_PI 00167 Returns: 00168 true if input is valid and a valid arc is created. 00169 */ 00170 bool Create( 00171 const ON_Circle& circle, 00172 ON_Interval angle_interval_in_radians 00173 ); 00174 00175 /* 00176 Description: 00177 Create an arc from a plane, radius and an angle in radians. 00178 The center of the arc is at the plane's origin. 00179 Parameters: 00180 plane - [in] 00181 circle is in this plane with center at m_origin 00182 center - [in] 00183 circle's center point 00184 radius - [in] 00185 angle_in_radians - [in] 00186 */ 00187 bool Create( 00188 const ON_Plane& plane, 00189 double radius, 00190 double angle_in_radians 00191 ); 00192 00193 /* 00194 Description: 00195 Create an arc parallel to the world XY plane from a 00196 center point, radius, and angle in radians. 00197 The arc starts at center+(radius,0,0). 00198 Parameters: 00199 center - [in] 00200 radius - [in] 00201 angle_in_radians - [in] 00202 */ 00203 bool Create( 00204 const ON_3dPoint& center, 00205 double radius, 00206 double angle_in_radians 00207 ); 00208 00209 /* 00210 Description: 00211 Create an arc parallel to plane from a center point, 00212 radius, and angle in radians. 00213 The arc starts at center+radius*plane.xaxis. 00214 Parameters: 00215 plane - [in] 00216 The plane x, y and z axis are used to defines the circle 00217 plane's x, y and z axis. The plane origin is ignorned. 00218 center - [in] 00219 circle's center point 00220 radius - [in] 00221 angle_in_radians - [in] 00222 */ 00223 bool Create( 00224 const ON_Plane& plane, 00225 const ON_3dPoint& center, 00226 double radius, 00227 double angle_in_radians 00228 ); 00229 00230 /* 00231 Description: 00232 Create an arc that passes through three 2d points. 00233 Parameters: 00234 start_point - [in] 00235 interior_point - [in] 00236 end_point - [in] 00237 */ 00238 bool Create( 00239 const ON_2dPoint& start_point, 00240 const ON_2dPoint& interior_point, 00241 const ON_2dPoint& end_point 00242 ); 00243 00244 /* 00245 Description: 00246 Create an arc that passes through three 3d points. 00247 Parameters: 00248 start_point - [in] 00249 interior_point - [in] 00250 end_point - [in] 00251 */ 00252 bool Create( 00253 const ON_3dPoint& start_point, 00254 const ON_3dPoint& interior_point, 00255 const ON_3dPoint& end_point 00256 ); 00257 00258 /* 00259 Description: 00260 Create an arc from a 2d start point, 2d start direction 00261 and a 2d end point. 00262 Parameters: 00263 start_point - [in] 00264 dir_at_start - [in] 00265 end_point - [in] 00266 */ 00267 bool Create( 00268 const ON_2dPoint& start_point, 00269 const ON_2dVector& dir_at_start, 00270 const ON_2dPoint& end_point 00271 ); 00272 00273 /* 00274 Description: 00275 Create an arc from a 3d start point, 3d start direction 00276 and a 3d end point. 00277 Parameters: 00278 start_point - [in] 00279 dir_at_start - [in] 00280 end_point - [in] 00281 */ 00282 bool Create( 00283 const ON_3dPoint& start_point, 00284 const ON_3dVector& dir_at_start, 00285 const ON_3dPoint& end_point 00286 ); 00287 00288 ON_Arc& operator=( const ON_Circle& ); 00289 00290 00291 ~ON_Arc(); 00292 00293 // Description: 00294 // Creates a text dump of the arc listing the normal, center 00295 // radius, start point, end point, and angle. 00296 // Remarks: 00297 // Dump() is intended for debugging and is not suitable 00298 // for creating high quality text descriptions of an 00299 // arc. 00300 void Dump( ON_TextLog& dump ) const; 00301 00302 // Description: 00303 // Checks an arc to make sure it is valid. 00304 // Detail: 00305 // Radius>0 and 0<AngleRadians()<=2 ON_PI 00306 // Returns: 00307 // true if the arc is valid. 00308 bool IsValid() const; 00309 00310 // Description: 00311 // Get arc's 3d axis aligned bounding box. 00312 // Returns: 00313 // 3d bounding box. 00314 ON_BoundingBox BoundingBox() const; 00315 00316 // Description: 00317 // Get arc's 3d axis aligned bounding box or the 00318 // union of the input box with the arc's bounding box. 00319 // Parameters: 00320 // bbox - [in/out] 3d axis aligned bounding box 00321 // bGrowBox - [in] (default=false) 00322 // If true, then the union of the input bbox and the 00323 // arc's bounding box is returned in bbox. 00324 // If false, the arc's bounding box is returned in bbox. 00325 // Returns: 00326 // true if arc has bounding box and calculation was successful. 00327 bool GetBoundingBox( 00328 ON_BoundingBox& bbox, 00329 int bGrowBox = false 00330 ) const; 00331 00332 /* 00333 Description: 00334 Get tight bounding box. 00335 Parameters: 00336 tight_bbox - [in/out] tight bounding box 00337 bGrowBox -[in] (default=false) 00338 If true and the input tight_bbox is valid, then returned 00339 tight_bbox is the union of the input tight_bbox and the 00340 arc's tight bounding box. 00341 xform -[in] (default=NULL) 00342 If not NULL, the tight bounding box of the transformed 00343 arc is calculated. The arc is not modified. 00344 Returns: 00345 True if a valid tight_bbox is returned. 00346 */ 00347 bool GetTightBoundingBox( 00348 ON_BoundingBox& tight_bbox, 00349 int bGrowBox = false, 00350 const ON_Xform* xform = 0 00351 ) const; 00352 00353 // Returns: 00354 // true if the arc is a complete circle; i.e., the arc's 00355 // angle is 360 degrees. 00356 bool IsCircle() const; 00357 00358 // Returns: 00359 // The arc's subtended angle in radians. 00360 double AngleRadians() const; 00361 00362 // Returns: 00363 // The arc's subtended angle in degrees. 00364 double AngleDegrees() const; 00365 00366 00367 /* 00368 Description: 00369 Get evaluation domain. 00370 Returns: 00371 Evaluation domain (same as DomainRadians()). 00372 */ 00373 ON_Interval Domain() const; 00374 00375 // Returns: 00376 // The arc's domain in radians. 00377 ON_Interval DomainRadians() const; 00378 00379 // Returns: 00380 // The arc's domain in degrees. 00381 ON_Interval DomainDegrees() const; 00382 00383 // Description: 00384 // Set arc's subtended angle in radians. 00385 // Parameters: 00386 // angle_in_radians - [in] 0 <= angle_in_radians <= 2.0*ON_PI 00387 // 00388 bool SetAngleRadians( 00389 double angle_in_radians 00390 ); 00391 00392 /* 00393 Description: 00394 Set arc's angle interval in radians. 00395 Parameters: 00396 angle_in_radians - [in] increasing interval with 00397 start and end angle in radians. 00398 Length of the interval <= 2.0*ON_PI. 00399 Returns: 00400 true if successful. 00401 */ 00402 bool SetAngleIntervalRadians( 00403 ON_Interval angle_in_radians 00404 ); 00405 00406 // Description: 00407 // Set arc's domain as a subdomain of the circle. 00408 // Parameters: 00409 // domain_radian - [in] 0 < domain_radian[1] - domain_radian[0] <= 2.0 * ON*PI 00410 // 00411 bool Trim( 00412 ON_Interval domain_radian 00413 ); 00414 00415 // Description: 00416 // Set arc's subtended angle in degrees. 00417 // Parameters: 00418 // angle_in_degrees - [in] 0 < angle_in_degrees <= 360 00419 bool SetAngleDegrees( 00420 double angle_in_degrees 00421 ); 00422 00423 // Returns: 00424 // Point at start of the arc. 00425 ON_3dPoint StartPoint() const; 00426 00427 00428 // Returns: 00429 // Point at middle of the arc. 00430 ON_3dPoint MidPoint() const; 00431 00432 // Returns: 00433 // Point at end of the arc. 00434 ON_3dPoint EndPoint() const; 00435 00436 // Description: 00437 // Get the point on the arc that is closest to test_point. 00438 // Parameters: 00439 // test_point - [in] 00440 // t - [out] parameter (in radians) of the point on the arc that 00441 // is closest to test_point. If test_point is the center 00442 // of the arc, then the starting point of the arc is 00443 // (arc.Domain()[0]) returned. 00444 bool ClosestPointTo( 00445 const ON_3dPoint& test_point, 00446 double* t 00447 ) const; 00448 00449 // Description: 00450 // Get the point on the arc that is closest to test_point. 00451 // Parameters: 00452 // test_point - [in] 00453 // Returns: 00454 // The point on the arc that is closest to test_point. 00455 // If test_point is the center of the arc, then the 00456 // starting point of the arc is returned. 00457 ON_3dPoint ClosestPointTo( 00458 const ON_3dPoint& test_point 00459 ) const; 00460 00461 // Returns: 00462 // Length of the arc = radius*(subtended angle in radians). 00463 double Length() const; 00464 00465 /* 00466 Returns: 00467 Area of the arc's sector. 00468 Remarks: 00469 The arc's sector is the region bounded by the arc, 00470 the line segment from the arc's end to the center, 00471 and the line segment from the center to the arc's 00472 start. 00473 */ 00474 double SectorArea() const; 00475 00476 /* 00477 Returns: 00478 Area centroid of the arc's sector. 00479 Remarks: 00480 The arc's sector is the region bounded by the arc, 00481 the line segment from the arc's end to the center, 00482 and the line segment from the center to the arc's 00483 start. 00484 */ 00485 ON_3dPoint SectorAreaCentroid() const; 00486 00487 /* 00488 Returns: 00489 Area of the arc's segment. 00490 Remarks: 00491 The arc's segment is the region bounded by the arc and 00492 the line segment from the arc's end to the arc's start. 00493 */ 00494 double SegmentArea() const; 00495 00496 /* 00497 Returns: 00498 Area centroid of the arc's segment. 00499 Remarks: 00500 The arc's segment is the region bounded by the arc and 00501 the line segment from the arc's end to the arc's start. 00502 */ 00503 ON_3dPoint SegmentAreaCentroid() const; 00504 00505 // Description: 00506 // Reverse the orientation of the arc. Changes the domain 00507 // from [a,b] to [-b.-a]. 00508 bool Reverse(); 00509 00510 // Description: 00511 // Get a rational degree 2 NURBS curve representation 00512 // of the arc. Note that the parameterization of NURBS curve 00513 // does not match arc's transcendental paramaterization. 00514 // Use GetRadianFromNurbFormParameter() and 00515 // GetParameterFromRadian() to convert between the NURBS curve 00516 // parameter and the transcendental parameter 00517 // Parameters: 00518 // nurbs_curve - [out] nurbs_curve returned here. 00519 // Returns: 00520 // 0 for failure and 2 for success. 00521 int GetNurbForm( 00522 ON_NurbsCurve& nurbs_curve 00523 ) const; 00524 00525 /* 00526 Description: 00527 Convert a NURBS curve arc parameter to a arc radians parameter. 00528 Parameters: 00529 nurbs_parameter - [in] 00530 arc_radians_parameter - [out] 00531 Example: 00532 00533 ON_Arc arc = ...; 00534 double nurbs_t = 1.2345; // some number in interval (0,2.0*ON_PI). 00535 double arc_t; 00536 arc.GetRadianFromNurbFormParameter( nurbs_t, &arc_t ); 00537 00538 ON_NurbsCurve nurbs_curve; 00539 arc.GetNurbsForm( nurbs_curve ); 00540 arc_pt = arc.PointAt(arc_t); 00541 nurbs_pt = nurbs_curve.PointAt(nurbs_t); 00542 // arc_pt and nurbs_pt will be the same 00543 00544 Remarks: 00545 The NURBS curve parameter is with respect to the NURBS curve 00546 created by ON_Arc::GetNurbForm. At nurbs parameter values of 00547 0.0, 0.5*ON_PI, ON_PI, 1.5*ON_PI, and 2.0*ON_PI, the nurbs 00548 parameter and radian parameter are the same. At all other 00549 values the nurbs and radian parameter values are different. 00550 See Also: 00551 ON_Arc::GetNurbFormParameterFromRadian 00552 */ 00553 bool GetRadianFromNurbFormParameter( 00554 double nurbs_parameter, 00555 double* arc_radians_parameter 00556 ) const; 00557 00558 /* 00559 Description: 00560 Convert a arc radians parameter to a NURBS curve arc parameter. 00561 Parameters: 00562 arc_radians_parameter - [in] 0.0 to 2.0*ON_PI 00563 nurbs_parameter - [out] 00564 Example: 00565 00566 ON_Arc arc = ...; 00567 double arc_t = 1.2345; // some number in interval (0,2.0*ON_PI). 00568 double nurbs_t; 00569 arc.GetNurbFormParameterFromRadian( arc_t, &nurbs_t ); 00570 00571 ON_NurbsCurve nurbs_curve; 00572 arc.GetNurbsForm( nurbs_curve ); 00573 arc_pt = arc.PointAt(arc_t); 00574 nurbs_pt = nurbs_curve.PointAt(nurbs_t); 00575 // arc_pt and nurbs_pt will be the same 00576 00577 Remarks: 00578 The NURBS curve parameter is with respect to the NURBS curve 00579 created by ON_Arc::GetNurbForm. At radian values of 00580 0.0, 0.5*ON_PI, ON_PI, 1.5*ON_PI, and 2.0*ON_PI, the nurbs 00581 parameter and radian parameter are the same. At all other 00582 values the nurbs and radian parameter values are different. 00583 See Also: 00584 ON_Arc::GetNurbFormParameterFromRadian 00585 */ 00586 bool GetNurbFormParameterFromRadian( 00587 double arc_radians_parameter, 00588 double* nurbs_parameter 00589 ) const; 00590 00591 private: 00592 friend bool ON_BinaryArchive::ReadArc( ON_Arc& ); 00593 friend bool ON_BinaryArchive::WriteArc( const ON_Arc& ); 00594 00595 // increasing interval with start and end angle in radians 00596 ON_Interval m_angle; 00597 }; 00598 00599 #endif 00600