-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvectors.py
76 lines (53 loc) · 1.39 KB
/
vectors.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding=UTF-8
'''
Created on 13 nov. 2014
@author: pclf
'''
import math
class Polar2D(object):
'''
classdocs
'''
def __init__(self, r, theta):
'''
Constructor
'''
self.r = r
self.theta = theta
def Rotate(self, theta):
return Polar2D(self.r, self.theta + theta)
def RotateSelf(self, theta):
self.theta += theta
def Zoom(self, r):
return Polar2D(self.r * r, self.theta)
def ZoomSelf(self, r):
self.r *= r
def RotateZoom(self, r, theta):
return Polar2D(self.r * r, self.theta + theta)
def RotateZoomSelf(self, r, theta):
self.r *= r
self.theta += theta
def ToXY(self):
theta_rd = math.radians(self.theta)
return Vector2D(self.r * math.sin(theta_rd), - self.r * math.cos(theta_rd))
class Vector2D(object):
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, other):
return Vector2D(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Vector2D(self.x - other.x, self.y - other.y)
# __iadd__ et __isub__ si nécessaire
def __mul__(self, k):
return Vector2D(self.x * k, self.y * k)
def __div__(self, k):
return Vector2D(self.x / k, self.y / k)
def ScalarProduct(self, v):
return self.x*v.x + self.y*v.y
def Det(self, v):
return self.x*v.y - self.y*v.x
def MatrixProduct(self, vx, vy):
return Vector2D(self.ScalarProduct(vx),self.ScalarProduct(vy))
def ToTuple(self):
return (self.x,self.y)