3D Canvas for Tkinter / by Derek Gregoriev

Several times I have been confronted with wanting to represent 3d data in a quick program I’ve thrown together in python/tkinter and each time I have leveraged the use of an external viewer (Patran, Autocad, Solidworks, etc) to manipulate and edit data once it’s generated. I’ve finally had enough of this patching and I put together a python/tkinter implementation (buggy at the moment and almost useful). I could have used numpy to handle some of the math, but I was trying to avoid the dependency so I put together a matrix handler (it could use some refactoring and cleaning as well), Coordinate system handler and coded in the basics of a point and a line (i.e. wireframe mode…). I have worked on something similar to this in C++ and Java and borrowed from the way Java3d handled the transforms. I’ll put the packages here and update more once it’s cleaner.

The pictures below are from Spyder and its showing the visual transforms performed on the visible/screen geometry. (actual point data remains unchanged after manipulations)

The code set is here: https://sourceforge.net/projects/derekgportfolio/files/PythonTkCanvas3d/

ui_3dviewer.png
Starting geometry. The circled point is transformed to be centered in the middle of the window (<0,0,0>). The transform for the visual spun the coordinate system about its x axis 180 deg to put positive values going up (screen coordinate 0,0 i…

Starting geometry. The circled point is transformed to be centered in the middle of the window (<0,0,0>). The transform for the visual spun the coordinate system about its x axis 180 deg to put positive values going up (screen coordinate 0,0 is top left) then translated to the middle of the screen.

This is a rotate performed on the rotate matrix/coord system along its z axis (out of page)

This is a rotate performed on the rotate matrix/coord system along its z axis (out of page)

This is a rotation of the view about the x axis after having rotated about the z axis. The dilation appearing like we are seeing over the top of the square is what we would expect.

This is a rotation of the view about the x axis after having rotated about the z axis. The dilation appearing like we are seeing over the top of the square is what we would expect.