Skip to content

Commit 5331444

Browse files
author
James Brundage
committed
feat: Turtle.Towards ( Fixes #98 )
1 parent f4cc8e3 commit 5331444

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Types/Turtle/Towards.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<#
2+
.SYNOPSIS
3+
Determines the angle towards a point
4+
.DESCRIPTION
5+
Determines the angle from the turtle's current position towards a point.
6+
#>
7+
param(
8+
# The X-coordinate
9+
[double]$X = 0,
10+
# The Y-coordinate
11+
[double]$Y = 0
12+
)
13+
14+
# Determine the delta from the turtle's current position to the specified point
15+
$deltaX = $this.Position.X - $X
16+
$deltaY = $this.Position.Y - $Y
17+
# Calculate the angle in radians and convert to degrees
18+
$angle = [Math]::Atan2($deltaY, $deltaX) * 180 / [Math]::PI
19+
# Return the angle rotate by 90 to account for the turtle's coordinate system
20+
return $angle + 90

0 commit comments

Comments
 (0)