Created
April 26, 2020 03:33
-
-
Save witoong623/6d40de8f51d7aa2d0427c3738e45b498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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