So I have a hobby project of strapping a USB microscope onto a 3D printer to take pictures of an object at different X, Y, and Z locations, which are then stitched into a full image. I started with the code from this stack to generate a 2D rectangular raster pattern, and then upgraded that to do 2.5 D imaging (stacking and stitching) by looping repeatedly to move the Z axis after each 2D scan, and finally doing the same with a 4th axis to enable 3D imaging.
The problem is that most things are not rectangles, and the scan can end up becoming very wasteful, stopping to take pictures in areas that are not object or obviously out of focus. I would love to be able to 1: shift the "scan plane", for instance to scan a flat object tilted upwards, and 2: Just in general be able to generate arbitrary scan patterns, or at least simple ideal shapes.
How would you take information about a 3-dimensional shape (for instance, from an STL), and wrap an otherwise 2D "dot matrix" raster pattern around the surface (or at least the part pointing up)?