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