3 vecteur.py is a module of pymecavideo.
4 pymecavideo
is a program to track moving points
in a video frameset
5 Copyright (C) 2007 Jean-Baptiste Butet <ashashiwa
@gmail.com>
7 This program
is free software: you can redistribute it
and/
or modify
8 it under the terms of the GNU General Public License
as published by
9 the Free Software Foundation, either version 3 of the License,
or
10 (at your option) any later version.
12 This program
is distributed
in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License
for more details.
17 You should have received a copy of the GNU General Public License
18 along
with this program. If
not, see <http://www.gnu.org/licenses/>.
22vecteur.py implements some operations
for 2D vectors, using tuples
30from PyQt6.QtCore import QPointF
34 une classe pour des vecteurs 2D ; les coordonnées sont flottantes, et
35 on peut accéder à celles-ci par les propriétés self.xx et self.yy
37 Paramètres du constructeur
39 @param x une abscisse, nulle par défaut
40 @param y une ordonnée, nulle par défaut
41 @param qPoint (
None par défaut) ; si ce paramètre est d
'un type
42 qui possède les méthodes .x() et .y(), il sert à créer le vecteur
45 def __init__(self, x=0, y=0, qPoint=None):
47 self.
value = (qPoint.x(), qPoint.y())
67 @return la longueur « de mahattan »
69 return abs(self.
xx) + abs(self.
yy)
73 change le signe de l'ordonnée ; utile comme l'axe y de l
'écran
74 est dirigé vers le bas.
81 ajuste les signes des coordonnées
82 @param video un objet qui a les propriétés sens_X et sens_Y (+-1)
85 - video.sens_Y * self.value[1])
88 def __getitem__(self, i):
92 def setValue(self, x=None, y=None):
101 self.
value = (math.floor(
102 self.
value[0] + 0.5), math.floor(self.
value[1] + 0.5))
104 def __add__(self, v):
110 return v
is not None and self.
xx == v.x
and self.
yy == v.y
112 def __sub__(self, v):
117 def __mul__(self, v):
118 if type(v) == type(self):
120 return self.
xx * v.x + self.
yy + v.y
123 x = float(v) * self.
xx
124 y = float(v) * self.
yy
128 return "(%5f, %5f)" % (self.
xx, self.
yy)
131 return f
"({round(self.x)}, {round(self.y)})"
134 return "vecteur %s" % self
138 return math.sqrt(self.
xx * self.
xx + self.
yy * self.
yy)
141 def anglePolaire(self):
142 return math.atan2(self.
yy, self.
xx)
172 def rotate(self, angle, largeur, hauteur):
173 x1, y1 = self.
xx, self.
yy
174 if angle % 360 == 90:
176 elif angle % 360 == 270:
178 elif angle % 360 == 0:
180 elif angle % 360 == 180:
183 def signif(self, x, digit):
186 return round(x, digit - int(math.floor(math.log10(abs(x)))) - 1)
188 def homothetie(self, ratio):
193 transformation en QPointF
195 return QPointF(self.
xx, self.
yy)
une classe pour des vecteurs 2D ; les coordonnées sont flottantes, et on peut accéder à celles-ci par...
def toQPointF(self)
transformation en QPointF
def signif(self, x, digit)
def manhattanLength(self)
def redresse(self, video)
ajuste les signes des coordonnées
def miroirY(self)
change le signe de l'ordonnée ; utile comme l'axe y de l'écran est dirigé vers le bas.