Skip to content

Instantly share code, notes, and snippets.

@witoong623
Created April 26, 2020 03:33
Show Gist options
  • Save witoong623/6d40de8f51d7aa2d0427c3738e45b498 to your computer and use it in GitHub Desktop.
Save witoong623/6d40de8f51d7aa2d0427c3738e45b498 to your computer and use it in GitHub Desktop.
import math
class D2Vector:
def __init__(self, X, Y):
self.X = X
self.Y = Y
def __add__(self, other):
X = self.X + other.X
Y = self.Y + other.Y
return D2Vector(X, Y)
def magnitude(self):
return math.sqrt(self.X**2 + self.Y**2)
def __str__(self):
return f'X={self.X}, Y={self.Y}, magnitude={self.magnitude()}'
def get_vector_from_angle(angle, magnitude):
opp = magnitude*math.sin(math.radians(angle))
adj = magnitude*math.cos(math.radians(angle))
return D2Vector(adj, opp)
v = get_vector_from_angle(30, 8)
w = get_vector_from_angle(160, 5)
vec_sum = v + w
print(vec_sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment