Skip to content

Commit 7a6c082

Browse files
committed
Matrix interface and functionality is ready.
TODO: - Examples comboBox
1 parent b577a24 commit 7a6c082

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

MatrixButtons.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def __init__(self):
4040
self.addToLayout(self.matrix22,[2,2],[1,1])
4141

4242
# Button for plot the grid transformed by the matrix
43-
plotButton = QtWidgets.QPushButton('Plot')
44-
self.addToLayout(plotButton,[1,3],[1,1])
43+
self.plotButton = QtWidgets.QPushButton('Plot')
44+
self.addToLayout(self.plotButton,[1,3],[1,1])
4545

4646

4747
def addToLayout(self, widget, position:list, size:list):
@@ -63,4 +63,4 @@ def setMatrix(self,matrix):
6363
# Third row
6464
self.matrix02.setText(str(matrix[2,0]))
6565
self.matrix12.setText(str(matrix[2,1]))
66-
self.matrix22.setText(str(matrix[2,2]))
66+
self.matrix22.setText(str(matrix[2,2]))

main.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
Date: January 27 2021
55
"""
66
from sympy.matrices import Matrix #It's easier work with matrices in sympy than numpy
7-
from sympy import sin,cos,pi #Trigonometric functions
7+
from sympy import sin,cos,pi,N #Trigonometric functions
88
import matplotlib.pyplot as plt #Plotting
99
from numpy import linspace,column_stack,array #For create the linspace for the plotting
1010

1111
import PyQt5.QtWidgets as QtWidgets #Python GUI
1212

1313
from Plotting import PlotWidget #The plot object
1414

15-
from MatrixButtons import MatrixButtons
15+
from MatrixButtons import MatrixButtons # Interface class
1616

17-
def transformPoint(x,y,z):
17+
def transformPoint(x,y,z,transformationMatrix):
1818
"""Return the vector transformed
1919
2020
"""
@@ -60,7 +60,8 @@ def get_transformedGrid(originalGrid, transformationMatrix):
6060
transformationMatrix
6161
6262
"""
63-
transformedGrid = transformPoint(originalGrid[0],originalGrid[1],originalGrid[2])
63+
transformedGrid = transformPoint(originalGrid[0],originalGrid[1],originalGrid[2],transformationMatrix)
64+
6465
return array([transformedGrid[0,:][0,:], #
6566
transformedGrid[1,:][0,:], # Save the transformed grid as a numpy array
6667
transformedGrid[2,:][0,:]]) #
@@ -73,14 +74,37 @@ def adjust_plot(axes):
7374
axes.set_xlabel('x') #
7475
axes.set_ylabel('y') # Axes names
7576
axes.set_zlabel('z') #
76-
axes.grid(False) # Don't show the grid
77+
axes.grid(True) # Don't show the grid
7778
axes.view_init(10,5) # View init at 15 and 5 degrees
7879

80+
def exceptionDialog(msg):
81+
dlg = QtWidgets.QErrorMessage()
82+
dlg.showMessage(msg)
83+
dlg.exec_()
84+
85+
86+
def transformAndPlot(interface, plot):
87+
try:
88+
transformationMatrix = Matrix([[N(interface.matrix00.text()), N(interface.matrix10.text()), N(interface.matrix20.text())],
89+
[N(interface.matrix01.text()), N(interface.matrix11.text()), N(interface.matrix21.text())],
90+
[N(interface.matrix02.text()), N(interface.matrix12.text()), N(interface.matrix22.text())]])
91+
92+
93+
xyzgrid = get_transformedGrid(originalGrid, transformationMatrix) # get a transformed grid
94+
95+
plot.scatter(xyzgrid,colors)
96+
adjust_plot(plot.axes)
97+
plot.fig.canvas.draw()
98+
plot.fig.canvas.flush_events()
99+
except ValueError as err:
100+
print(err)
101+
exceptionDialog('An error has ocurred. Remember that you only can write operations between numbers or trigonometric functions in the matrix boxes. ex. sin(3*pi/2) or 30+0.5')
102+
79103
if __name__ == "__main__":
80104
"""Transformation matrix"""
81105
transformationMatrix = Matrix([[1, 0, 0],
82106
[0, 1, 0],
83-
[0, 1, 1]])
107+
[0, 0, 1]])
84108

85109
originalGrid = get_grid(-2,2) # Create a straigh grid
86110
xyzgrid = get_transformedGrid(originalGrid, transformationMatrix) # get a transformed grid
@@ -94,10 +118,14 @@ def adjust_plot(axes):
94118

95119
adjust_plot(plot.axes) # Set the limits of the axes
96120

121+
plot.addToLayout(QtWidgets.QLabel('Titulo'),[11,0],[1,1])
122+
97123
interface = MatrixButtons() # Get the interface
98124
plot.addToLayout(interface,[11,4],[10,2]) # add the interface to the plot layout
99125

100126
interface.setMatrix(transformationMatrix)
101127

128+
interface.plotButton.clicked.connect(lambda: transformAndPlot(interface,plot))
129+
102130
plot.show()
103131
app.exec()

0 commit comments

Comments
 (0)