1+ """
2+ Visualization of the tranformation matrix
3+ Author: Manuel Garcia
4+ Date: January 27 2021
5+ """
6+ from sympy .matrices import Matrix #It's easier work with matrices in sympy than numpy
7+ from sympy import sin ,cos ,pi #Trigonometric functions
8+ import matplotlib .pyplot as plt #Plotting
9+ from numpy import linspace ,column_stack ,array #For create the linspace for the plotting
10+
11+ import PyQt5 .QtWidgets as QtWidgets #Python GUI
12+
13+ from Plotting import PlotWidget #The plot object
14+
15+ """Transformation matrix"""
16+ transformationMatrix = Matrix ([[1 , 0 , 0 ],
17+ [0 , 0.5 , 0 ],
18+ [0 , 0 , 1 ]])
19+
20+ def transformPoint (x ,y ,z ):
21+ """Return the vector transformed
22+
23+ """
24+ return transformationMatrix * Matrix ([x ,y ,z ])
25+
26+ def colorizer (x , y ,z ):
27+ """Color the points in the space by their position
28+
29+ """
30+ r = min (1 , 1 - y / 3 )
31+ g = min (1 , 1 + y / 3 )
32+ b = 1 / 4 + x / 16
33+ return (r , g , b )
34+
35+
36+ def get_grid (min ,max ):
37+ """Return a grid in x, y and z
38+
39+ ...
40+
41+ Parameters
42+ ----------
43+ min
44+ minimum value in the x,y and z axes
45+ max
46+ maximum value in the x,y and z axes
47+ """
48+ xvals = linspace (min , max , abs (min - max )+ 1 )
49+ yvals = linspace (min , max , abs (min - max )+ 1 )
50+ zvals = linspace (min , max , abs (min - max )+ 1 )
51+ xyzgrid = column_stack ([[x , y ,z ] for x in xvals for y in yvals for z in zvals ])
52+ return xyzgrid
53+
54+ if __name__ == "__main__" :
55+
56+ originalGrid = get_grid (- 2 ,2 )
57+ transformedGrid = transformPoint (originalGrid [0 ],originalGrid [1 ],originalGrid [2 ])
58+ xyzgrid = array ([transformedGrid [0 ,:][0 ,:], #
59+ transformedGrid [1 ,:][0 ,:], # Save the transformed grid as a numpy array
60+ transformedGrid [2 ,:][0 ,:]]) #
61+
62+ colors = list (map (colorizer , originalGrid [0 ], originalGrid [1 ], originalGrid [2 ])) # Asign the colors to the points
63+
64+ app = QtWidgets .QApplication ([])
65+ plot = PlotWidget (xyzgrid [0 ], xyzgrid [1 ], xyzgrid [2 ], colors = colors , alpha = 0.7 )
66+
67+ plot .axes .set_xlim ([- 2 , 2 ]) #
68+ plot .axes .set_ylim ([- 2 , 2 ]) # Set the limits of the plot
69+ plot .axes .set_zlim ([- 2 , 2 ]) #
70+ plot .axes .axis ('on' ) # Show the axis
71+ plot .axes .set_xlabel ('x' ) #
72+ plot .axes .set_ylabel ('y' ) # Axes names
73+ plot .axes .set_zlabel ('z' ) #
74+ plot .axes .grid (False ) # Don't show the grid
75+ plot .axes .view_init (10 ,5 ) # View init at 15 and 5 degrees
76+
77+ plot .show ()
78+ app .exec ()
0 commit comments