-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathspeed.py
More file actions
34 lines (29 loc) · 1.03 KB
/
speed.py
File metadata and controls
34 lines (29 loc) · 1.03 KB
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
from PyQt5 import QtWidgets, uic
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtGui import QCursor
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QTextEdit, QFileDialog, QScrollBar, QComboBox, QColorDialog, QCheckBox, QSlider, QMenu
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QTimer, QFile, QTextStream
import sys
import math
import time
from pyqtgraph import PlotWidget
import pyqtgraph as pg
class Frame:
def __init__ (self, position, time):
self.position = position
self.time = time
def speed (self, frame):
d = distance (*self.position, *frame.position)
time_delta = abs (frame.time - self.time)
if time_delta == 0:
return None
else:
return d / time_delta
def distance (x1, y1, x2, y2):
return math.sqrt ((x2 - x1) ** 2 + (y2 - y1) ** 2)
def get_current_cursor_position ():
pos = QCursor.pos ()
return pos.x (), pos.y ()
def get_current_frame ():
return Frame (get_current_cursor_position (), time.time ())