Skip to content

Commit 3820425

Browse files
StartAutomatingStartAutomating
authored andcommitted
fix: Turtle.Towards relative angle ( Fixes #123 )
1 parent aa70204 commit 3820425

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Turtle.types.ps1xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,11 @@ param(
346346
)
347347

348348
# Determine the delta from the turtle's current position to the specified point
349-
$deltaX = $this.Position.X - $X
350-
$deltaY = $this.Position.Y - $Y
351-
# Calculate the distance using the Pythagorean theorem
352-
return [Math]::Sqrt($deltaX * $deltaX + $deltaY * $deltaY)
349+
$deltaX = $X - $this.Position.X
350+
$deltaY = $Y - $this.Position.Y
353351

352+
# Calculate the distance using the Pythagorean theorem
353+
return [Math]::Sqrt($deltaX*$deltaX + $deltaY*$deltaY)
354354
</Script>
355355
</ScriptMethod>
356356
<ScriptMethod>
@@ -1526,7 +1526,7 @@ return "$($this.SVG.OuterXml)"
15261526
.SYNOPSIS
15271527
Determines the angle towards a point
15281528
.DESCRIPTION
1529-
Determines the angle from the turtle's current position towards a point.
1529+
Determines the angle from the turtle's current heading towards a point.
15301530
#&gt;
15311531
param(
15321532
# The X-coordinate
@@ -1536,12 +1536,12 @@ param(
15361536
)
15371537

15381538
# Determine the delta from the turtle's current position to the specified point
1539-
$deltaX = $this.Position.X - $X
1540-
$deltaY = $this.Position.Y - $Y
1539+
$deltaX = $X - $this.Position.X
1540+
$deltaY = $Y - $this.Position.Y
15411541
# Calculate the angle in radians and convert to degrees
15421542
$angle = [Math]::Atan2($deltaY, $deltaX) * 180 / [Math]::PI
1543-
# Return the angle rotate by 90 to account for the turtle's coordinate system
1544-
return $angle + 90
1543+
# Return the angle minus the current heading (modulo 360)
1544+
return $angle - ($this.Heading % 360)
15451545

15461546
</Script>
15471547
</ScriptMethod>

0 commit comments

Comments
 (0)