Skip to content

Commit c617fa0

Browse files
committed
String bugs fixed
It was a because i was using the Matrix function from sympy Just changed the matrices to arrays from numpy and convert it to Matrix for plotting only
1 parent e00583e commit c617fa0

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

MatrixButtons.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import PyQt5.QtWidgets as QtWidgets
22
from matplotlib.figure import Figure
33
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
4+
from sympy import Matrix
45

56
class MatrixButtons(QtWidgets.QWidget):
67
"""Widget for PyQt5 with the Matrix input and the buttons

main.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ def exceptionDialog(msg):
8383
dlg.exec_()
8484

8585

86-
def transformAndPlot(interface, plot):
86+
def transformAndPlot(plot,matrix):
8787
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
88+
matrix = array(matrix)
89+
print(matrix)
90+
interface.setMatrix(matrix)
91+
xyzgrid = get_transformedGrid(originalGrid, Matrix([[N(matrix[0,0]),N(matrix[0,1]),N(matrix[0,2])],
92+
[N(matrix[1,0]),N(matrix[1,1]),N(matrix[1,2])],
93+
[N(matrix[2,0]),N(matrix[2,1]),N(matrix[2,2])]])) # get a transformed grid
9494

9595
plot.scatter(xyzgrid,colors)
9696
adjust_plot(plot.axes)
@@ -100,14 +100,28 @@ def transformAndPlot(interface, plot):
100100
print(err)
101101
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')
102102

103+
def examplesComboBox(window,comboBox):
104+
examples = {
105+
'Original Grid' :[[1, 0, 0],[0, 1, 0],[0, 0, 1]],
106+
'X rotation 45º' :[[1, 0, 0],[0, 'cos(45*pi/180)', -sin(45*pi/180)],[0, sin(45*pi/180), cos(45*pi/180)]],
107+
'Y rotation 45º' :[[cos(45*pi/180), -sin(45*pi/180), 0],[sin(45*pi/180), cos(45*pi/180), 0],[0, 0, 1]],
108+
'Z rotation 45º' :[[cos(45*pi/180), 0, -sin(45*pi/180)],[0, 1, 0],[sin(45*pi/180), 0, cos(45*pi/180)]]
109+
}
110+
for key in examples:
111+
examplesWidget.addItem(key)
112+
113+
examplesWidget.activated[str].connect(lambda str: transformAndPlot(window,examples.get(str)))
114+
115+
window.addToLayout(examplesWidget, [11,1],[3,1])
116+
103117
if __name__ == "__main__":
104118
"""Transformation matrix"""
105-
transformationMatrix = Matrix([[1, 0, 0],
106-
[0, 1, 0],
107-
[0, 0, 1]])
119+
transformationMatrix = [[1, 0, 0],
120+
[0, 1, 0],
121+
[0, 0, 1]]
108122

109123
originalGrid = get_grid(-2,2) # Create a straigh grid
110-
xyzgrid = get_transformedGrid(originalGrid, transformationMatrix) # get a transformed grid
124+
xyzgrid = get_transformedGrid(originalGrid, Matrix(transformationMatrix)) # get a transformed grid
111125

112126
colors = list(map(colorizer, originalGrid[0], originalGrid[1], originalGrid[2])) # Asign the colors to the points
113127

@@ -117,15 +131,20 @@ def transformAndPlot(interface, plot):
117131
plot.scatter(xyzgrid,colors) # Scatter
118132

119133
adjust_plot(plot.axes) # Set the limits of the axes
120-
121-
plot.addToLayout(QtWidgets.QLabel('Titulo'),[11,0],[1,1])
134+
135+
plot.addToLayout(QtWidgets.QLabel('Examples'),[11,0],[1,1])
136+
examplesWidget = QtWidgets.QComboBox()
137+
examplesComboBox(plot,examplesWidget)
122138

123139
interface = MatrixButtons() # Get the interface
124140
plot.addToLayout(interface,[11,4],[10,2]) # add the interface to the plot layout
125141

126-
interface.setMatrix(transformationMatrix)
142+
interface.setMatrix(array(transformationMatrix))
127143

128-
interface.plotButton.clicked.connect(lambda: transformAndPlot(interface,plot))
144+
interface.plotButton.clicked.connect(
145+
lambda: transformAndPlot(plot,[[interface.matrix00.text(), interface.matrix10.text(), interface.matrix20.text()],
146+
[interface.matrix01.text(), interface.matrix11.text(), interface.matrix21.text()],
147+
[interface.matrix02.text(), interface.matrix12.text(), interface.matrix22.text()]]))
129148

130149
plot.show()
131150
app.exec()

0 commit comments

Comments
 (0)