I have a Graphics3D object. I want to export it as a bitmap, and to calculate the bitmap-pixel coordinates of certain 3D points.
Mathematica obviously does a projection from 3D objects to 2D pixel coordinates when it draws the 3D graphic. How can I find out what this projection is?
I’d rather avoid doing lots of tricky geometrical calculations based on ViewVector and ViewAngle and ImageSize and BoundingBox. Is there a shortcut?
Damon.
You could
GeometricTransformusing the option"Transformation" -> "Perspective". Suppose your projected chess board looks something like thisTo find the projection you will need the coordinates of at least 4 control points in
imgfor which you know the {x,y}-coordinates. There probably are methods to have Mathematica find these coordinates automatically but you can select them manually by right-clicking onimgand choosing “Get Coordinates”. Click on the control points of your choice (in this case I chose the 4 corners of the chessboard) andcopy/paste their coordinates to a new line. You should get something like
The projection function and matrix then become
Note that I chose the chessboard to be an 8×8 square centred at {4,4}, but you can choose any square.
A point {x,y} on the chessboard will now correspond to the point in
imgwith pixel coordinatestransform[{x,y}]or, using the projection matrix,(transfMat[[{1,2}]].{x,y,1})/(transfMat[[3]].{x,y,1}). So for example, to put a marker on D6, which would be at position {x,y}={4-1/2,6-1/2} in my 8×8 square, you could do something like