Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
DavPilot committed Jan 8, 2025
1 parent 01b2700 commit 1cea90a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def __mul__(self, other: Union[float, "Vector"]) -> Union[float, "Vector"]:
return Vector(self.coord_x * other, self.coord_y * other)

dot_product = (
self.coord_x * other.coord_x + self.coord_y * other.coord_y
self.coord_x * other.coord_x +
self.coord_y * other.coord_y
)
return round(dot_product, 4)

Expand Down Expand Up @@ -52,7 +53,10 @@ def get_normalized(self) -> "Vector":
def angle_between(self, other: "Vector") -> int:
cos_angle = max(
-1.0,
min(1.0, (self * other) / (self.get_length() * other.get_length())),
min(
1.0,
(self * other) / (self.get_length() * other.get_length())
),
)
return round(math.degrees(math.acos(cos_angle)))

Expand All @@ -65,11 +69,12 @@ def rotate(self, degrees: int) -> "Vector":
sin_angle = math.sin(radians)

coord_x_rotated = (
self.coord_x * cos_angle - self.coord_y * sin_angle
self.coord_x * cos_angle -
self.coord_y * sin_angle
)
coord_y_rotated = (
self.coord_x * sin_angle + self.coord_y * cos_angle
self.coord_x * sin_angle +
self.coord_y * cos_angle
)

return Vector(coord_x_rotated, coord_y_rotated)

0 comments on commit 1cea90a

Please sign in to comment.