Skip to content

Commit

Permalink
chore: use :math library from erlang
Browse files Browse the repository at this point in the history
  • Loading branch information
tvillegas98 committed Dec 18, 2024
1 parent 042a833 commit de29c4a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions apps/bot_manager/lib/math/vector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ defmodule BotManager.Math.Vector do

# Using the rotation matrix
def rotate_by_degrees(%{x: x, y: y}, angle_in_degrees) do
angle_in_radians = Math.deg2rad(angle_in_degrees)
x = x * Math.cos(angle_in_radians) - y * Math.sin(angle_in_radians)
y = x * Math.sin(angle_in_radians) + y * Math.cos(angle_in_radians)
angle_in_radians = deg2rad(angle_in_degrees)
x = x * :math.cos(angle_in_radians) - y * :math.sin(angle_in_radians)
y = x * :math.sin(angle_in_radians) + y * :math.cos(angle_in_radians)

%{
x: x,
Expand All @@ -51,4 +51,9 @@ defmodule BotManager.Math.Vector do
y: y / distance
}
end


def deg2rad(deg) do
deg * :math.pi / 180
end
end

0 comments on commit de29c4a

Please sign in to comment.