-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyVector.py
More file actions
44 lines (30 loc) · 987 Bytes
/
Copy pathMyVector.py
File metadata and controls
44 lines (30 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import math
#Vector에 관련된 실질적인 속성과 기능들만 있음
class MyVector:
def __init__(self, x, y):
self.x = x
self.y = y
norm = 0
def __add__(self, other):
return MyVector(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return MyVector(self.x - other.x, self.y - other.y)
def __mul__(self, scalar):
return MyVector(scalar*self.x, scalar*self.y)
def setPos(self, x, y): #시작점
self.x = x
self.y = y
def normalize(self): #벡터의 정규화
self.norm = self.getMagnitude()
self.x = self.x/self.norm
self.y = self.y/self.norm
def getMagnitude(self): #벡터의 크기
return math.sqrt(math.pow(self.x,2)+math.pow(self.y,2))
def getState(self):
return self.x, self.y
def vec(self):
return [self.x, self.y]
# a = MyVector(1, 2)
# b = MyVector(4, 5)
# c = (b + a)
# print(c.vec())