File tree Expand file tree Collapse file tree 1 file changed +28
-8
lines changed
Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Original file line number Diff line number Diff line change 44. DESCRIPTION
55 Determines the angle from the turtle's current heading towards a point.
66#>
7- param (
8- # The X-coordinate
9- [double ]$X = 0 ,
10- # The Y-coordinate
11- [double ]$Y = 0
12- )
7+ param ()
8+
9+ $towards = $args
10+
11+ $tx = 0.0
12+ $ty = 0.0
13+
14+ $nCount = 0
15+ foreach ($toward in $towards ) {
16+ if ($toward -is [double ] -or $toward -is [float ] -or $toward -is [int ]) {
17+ if (-not ($nCount % 2 )) {
18+ $tx = $toward
19+ } else {
20+ $ty = $toward
21+ }
22+ $nCount ++
23+ }
24+ elseif ($null -ne $toward.X -and $null -ne $toward.Y ) {
25+ $tx = $toward.x
26+ $ty = $toward.y
27+ $nCount += 2
28+ }
29+ }
30+
31+ $tx /= ($nCount / 2 )
32+ $ty /= ($nCount / 2 )
1333
1434# Determine the delta from the turtle's current position to the specified point
15- $deltaX = $X - $this.Position.X
16- $deltaY = $Y - $this.Position.Y
35+ $deltaX = $tx - $this.Position.X
36+ $deltaY = $ty - $this.Position.Y
1737# Calculate the angle in radians and convert to degrees
1838$angle = [Math ]::Atan2($deltaY , $deltaX ) * 180 / [Math ]::PI
1939# Return the angle minus the current heading (modulo 360)
You can’t perform that action at this time.
0 commit comments