@@ -304,7 +304,11 @@ $Radius = 10,
304
304
305
305
# The angle of the arc
306
306
[double]
307
- $Angle = 60
307
+ $Angle = 60,
308
+
309
+ # The number of steps. If not provided, will default to half of the angle.
310
+ [int]
311
+ $StepCount
308
312
)
309
313
310
314
# Determine the absolute angle, for this operation
@@ -315,25 +319,32 @@ if ($absAngle -eq 0) { return $this }
315
319
# Determine the circumference of a circle of this radius
316
320
$Circumference = ((2 * $Radius) * [Math]::PI)
317
321
318
- # Clamp the angle, as arcs beyond 360 just continue to circle
319
- $ClampedAngle =
320
- if ($absAngle -gt 360) { 360 }
321
- elseif ($absAngle -lt -360) { -360}
322
- else { $absAngle }
323
- # The circumference step is the circumference divided by our clamped angle
324
- $CircumferenceStep = $Circumference / [Math]::Floor($ClampedAngle)
322
+ # The circumference step is the circumference times
323
+ # the number of revolutions
324
+ $revolutionCount = $angle/360
325
+ # divided by the angle
326
+ $CircumferenceStep = ($Circumference * $revolutionCount) / $Angle
327
+
325
328
# The iteration is as close to one or negative one as possible
326
329
$iteration = $angle / [Math]::Floor($absAngle)
327
- # Start off at iteration 1
328
- $angleDelta = $iteration
329
- # while we have not reached the angle
330
- while ([Math]::Abs($angleDelta) -le $absAngle) {
331
- # Rotate and move forward
332
- $null = $this.Rotate($iteration).Forward($CircumferenceStep)
333
- $angleDelta+=$iteration
330
+
331
+ # If we have no step count
332
+ if (-not $StepCount) {
333
+ # default to half of the angle.
334
+ $StepCount = [Math]::Round($absAngle / 2)
335
+ }
336
+ # Turn this into a ratio (by default, this ratio would be `2`).
337
+ $stepSize = $absAngle / $StepCount
338
+
339
+ # Starting at zero, keep turning until we have reached the number.
340
+ # Increase our angle by iteration * stepSize each time.
341
+ for ($angleDelta = 0; [Math]::Abs($angleDelta) -lt $absAngle; $angleDelta+=($iteration*$stepSize)) {
342
+ $this = $this. # In each step,
343
+ Forward($CircumferenceStep*$StepSize). # move forward a fraction of the circumference,
344
+ Rotate($iteration*$StepSize) # and rotate a fraction of the total angle.
334
345
}
335
346
336
- # Return this so we can keep the chain.
347
+ # When we are done, return $ this so we never break the chain.
337
348
return $this
338
349
</Script >
339
350
</ScriptMethod >
0 commit comments