-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask3_Test1.py
134 lines (116 loc) · 5.23 KB
/
Task3_Test1.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import sys
import os
import math
from math import *
from PyQt4 import QtGui, QtCore
#https://uk.mathworks.com/help/vision/ref/undistortimage.html
# http://www.tannerhelland.com/4743/simple-algorithm-correcting-lens-distortion/
#https://stackoverflow.com/questions/11790504/about-a-pyqt-example-program
#I THINK I SHOULD CREATE SEPRATE BOXES FOR PROCESS INFORMATION AND SEND INFORMATION
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
self.RequiredDistance=70.6
self.y_cordinate=0
self.x_cordinate=0
self.X2=0
self.Y2=0
self.X_Coordinate=0
self.new_X=0
self.new_Y=0
self.pipe_multiplier=1
self.setGeometry(300, 200, 1000, 500)
self.setWindowTitle('TASK 3')
self.buttonStore1()
self.btn.clicked.connect(self.StoreValue1)
self.btn1.clicked.connect(self.StoreValue2)
self.btn2.clicked.connect(self.Calculate)
self.btn3.clicked.connect(self.SlopeCalculate)
self.show()
def mouseReleaseEvent(self, QMouseEvent):
cursor =QtGui.QCursor()
current=QtGui.QWidget.mapFromGlobal(self,cursor.pos())
self.x_cordinate = current.x()
self.y_cordinate = current.y()
def buttonStore1(self):
self.btn=QtGui.QPushButton("R",self)
self.btn.resize(50,50)
self.btn.move(100,50)
self.btn.setStyleSheet("QPushButton { background-color: white }""QPushButton:pressed { background-color: lightgreen }" )
self.btn1=QtGui.QPushButton("P",self)
self.btn1.resize(50,50)
self.btn1.move(200,50)
self.btn1.setStyleSheet("QPushButton { background-color: white }""QPushButton:pressed { background-color: lightgreen }" )
self.btn2=QtGui.QPushButton("CALCULATE",self)
self.btn2.resize(100,50)
self.btn2.move(400,20)
self.btn2.setStyleSheet("QPushButton { background-color: white }""QPushButton:pressed { background-color: lightgreen }" )
self.btn3=QtGui.QPushButton("SLOPE",self)
self.btn3.resize(100,50)
self.btn3.move(700,20)
self.btn3.setStyleSheet("QPushButton { background-color: white }""QPushButton:pressed { background-color: lightgreen }" )
self.show()
def initUI(self):
qbtn = QtGui.QPushButton('Quit', self)
qbtn.resize(100,50)
qbtn.move(800, 50)
def Calculate(self): # Assumes that the x-cordinate is constant
objectDistance=math.sqrt((self.X2-self.X1)**2 + ((self.Y2-self.Y1)**2)) # This is a more accurate way to calculate distance than Y2-Y1
# print(objectDistance)
actualDistance=42
scale=actualDistance/(objectDistance)
X_ReferenceObject=self.X2
# self.X_Coordinate = (self.RequiredDistance/scale)+ X_ReferenceObject
# print(self.X_Coordinate)
# QtGui.QWidget.update(self,self.X2,self.Y2, self.rect().width() -self.X_Coordinate , self.Y2)
self.X_Coordinate = X_ReferenceObject + (self.RequiredDistance/scale)
# self.radius=(self.X_Coordinate-self.X2)*(math.cos(self.angle))
#IS RADIUS X2_COORDINATE-X2 OR USING THE RADIUS METHOD???
self.new_X=self.X2+self.pipe_multiplier*((self.X_Coordinate-self.X2)*math.cos(self.angle))
self.new_Y=self.Y2-self.pipe_multiplier*((self.X_Coordinate-self.X2)*math.sin(self.angle))
print(self.new_Y)
print(self.new_X)
QtGui.QWidget.update(self)
def SlopeCalculate(self):
self.slope=(self.Y1-self.Y2)/(self.X2-self.X1)#Y1-Y2 as the Y Axis start from top and move to bottom so sign was reversed
self.pipe_orientation= (self.X2-self.X1)
if(self.pipe_orientation>0):
self.pipe_multiplier=1
else:
self.pipe_multiplier=-1
self.angle=(math.atan(self.slope))
print(self.angle)
# -math.radians(80)+
# print((self.angle)*180/math.pi)
# self.angle=math.degrees(math.atan2(self.Y2 - self.Y1,self.X2 - self.X1))
# print(math.degrees(self.angle))
#CHECK IF IT IS 'X1' OR 'X2' DEPENDS ON WHAT USER PRESSES
def paintEvent(self, event):
painter = QtGui.QPainter(self)
pixmap = QtGui.QPixmap("cal1.png")
painter.drawPixmap(10, 100,640,480, pixmap)
# painter.drawPixmap(self,10, pixmap)
pen = QtGui.QPen(QtCore.Qt.blue, 3)
painter.setPen(pen)
painter.drawLine(self.X2,self.Y2, self.new_X,self.new_Y)
# pen2 = QtGui.QPen(QtCore.Qt.green, 3)
# pen2.setStyle(QtCore.Qt.DashLine)
# painter.setPen(pen2)
# painter.drawLine(self.X_Coordinate, self.Y2, self.X_Coordinate, 100)
# painter.drawLine(self.X_Coordinate, self.Y2, self.X_Coordinate, 400)
#Change the coordinate to the one required
def StoreValue1(self):
self.Y1=self.y_cordinate
self.X1=self.x_cordinate
print("Value 1 Stored",self.X1,self.Y1)
def StoreValue2(self):
self.Y2=self.y_cordinate
self.X2=self.x_cordinate
print("Value 2 Stored",self.X2,self.Y2)
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()