@@ -15,7 +15,11 @@ $Radius = 10,
1515
1616# The angle of the arc
1717[double ]
18- $Angle = 60
18+ $Angle = 60 ,
19+
20+ # The number of steps. If not provided, will default to half of the angle.
21+ [int ]
22+ $StepCount
1923)
2024
2125# Determine the absolute angle, for this operation
@@ -26,23 +30,30 @@ if ($absAngle -eq 0) { return $this }
2630# Determine the circumference of a circle of this radius
2731$Circumference = ((2 * $Radius ) * [Math ]::PI)
2832
29- # Clamp the angle, as arcs beyond 360 just continue to circle
30- $ClampedAngle =
31- if ($absAngle -gt 360 ) { 360 }
32- elseif ($absAngle -lt -360 ) { -360 }
33- else { $absAngle }
34- # The circumference step is the circumference divided by our clamped angle
35- $CircumferenceStep = $Circumference / [Math ]::Floor($ClampedAngle )
33+ # The circumference step is the circumference times
34+ # the number of revolutions
35+ $revolutionCount = $angle / 360
36+ # divided by the angle
37+ $CircumferenceStep = ($Circumference * $revolutionCount ) / $Angle
38+
3639# The iteration is as close to one or negative one as possible
3740$iteration = $angle / [Math ]::Floor($absAngle )
38- # Start off at iteration 1
39- $angleDelta = $iteration
40- # while we have not reached the angle
41- while ([Math ]::Abs($angleDelta ) -le $absAngle ) {
42- # Rotate and move forward
43- $null = $this.Rotate ($iteration ).Forward($CircumferenceStep )
44- $angleDelta += $iteration
41+
42+ # If we have no step count
43+ if (-not $StepCount ) {
44+ # default to half of the angle.
45+ $StepCount = [Math ]::Round($absAngle / 2 )
46+ }
47+ # Turn this into a ratio (by default, this ratio would be `2`).
48+ $stepSize = $absAngle / $StepCount
49+
50+ # Starting at zero, keep turning until we have reached the number.
51+ # Increase our angle by iteration * stepSize each time.
52+ for ($angleDelta = 0 ; [Math ]::Abs($angleDelta ) -lt $absAngle ; $angleDelta += ($iteration * $stepSize )) {
53+ $this = $this . # In each step,
54+ Forward($CircumferenceStep * $StepSize ). # move forward a fraction of the circumference,
55+ Rotate($iteration * $StepSize ) # and rotate a fraction of the total angle.
4556}
4657
47- # Return this so we can keep the chain.
58+ # When we are done, return $ this so we never break the chain.
4859return $this
0 commit comments