Seeking advice for project involving interactive 3D display of geometric solids/surfaces

I’m thinking of pursuing a personal “hobby” project using Matplotlib, and would like input about the feasibility of doing what I want with Matplotib, and advice about how to approach it.

I have used Matplotlib over the last 10 or so years for 2D plotting for various projects. I’ve mostly done this by (admission of guilt) finding code online and modifying it. I feel I am ready to learn Matplotlib concepts and methods (or at least a portion of it) and write something from scratch.

As a fairly experienced user of OpenSCAD, I do a lot of modeling with it: architectural, for 3D printing, for woodworking projects, etc.

I have long wanted something more interactive than coding directly in OpenSCAD but I don’t want to give up the precision and programmability of it. I want my end result to be an OpenSCAD file with which I can make my final edits. I might just make “chunks” of OpenSCAD code rather than the final model.

I’ve looked around quite a bit. I’m familiar with other, more visual, 3D modeling tools such as Blender, Tinkercad, FreeCad, SolveSpace; I’ve investigated 3D display options such as VPython and Geometry3D.

I’d like to try using Matplotlib’s 3D plotting with the interactive event handling as a basis for developing a set of simple geometric solids. I would be happy to start with just a rectangular prism. I want to write Python code to display this object in Matplotlib and also write the OpenSCAD code for it to a file.

I imagine being able to type: mpBox(xDim, yDim, zDim, xPos, yPos, zPos, xRot, yRot, zRot) as input. I would need to define mpBox in Python/IPython to both display my “box” properly in Matplotlib’s window and simultaneously write a file using OpenSCAD’s cube/translate/rotate primitives and display this in OpenSCAD’s window.

Eventually I want to be able to add sphere, cylinder, etc. The shapes should be able to overlap in one window. Eventually I want to be able to click in the Matplotlib window to select different shape objects. Maybe to enter new values for them. I’m not looking for GUI-based resizing or dragging. I like things parametric. One feature I would like to have is the ability to measure the distance between two objects in the 3D output/display.

Can this be done, or should I keep looking elsewhere for a solution? If using Matplotlib is reasonable, should I be using surfaces or 3D objects? Do I need to learn about Figure? Axes3D? Plot? Artists? mpl_toolkit? Should each of my objects each be a subplot? Something else?

This isn’t really my area, but here are a few things I found. What you describe seems possible, but I don’t know if matplotlib is the right tool.

Thanks! It will take me some time, but these all seem worth a closer look.

I do think I’ll need to learn some basics, e.g., Quick start guide — Matplotlib 3.8.3 documentation

1 Like