0

Assume you have drawn a 3D figure in Python.

import matplotlib.pyplot as plt
fig = plt.figure()
ax = plt.axes(projection="3d")
ax.plot3D([0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 1, 0])
plt.show()

You can rotate the picture with the mouse into a position you like.

enter image description here

How can one now obtain a 2D plot that contains a projected version of the 3D object?

In this case, that would be a triangle defined by three (x, y) points. After removing the axes and grid in both the 3D and 2D plot, one would see two figures that are exactly the same (triangle).

I think it is possible to manually calculate the 2D projection, but I wondered if there exists a built-in function that does it for you.

Karlo
  • 1,630
  • 4
  • 33
  • 57

1 Answers1

1

One way to do this is to use ax.view_init(elev = elevation, azim=angle) to get the view angles.

Then use these angles to get the view coordinate system, see the following links:

How to get 3D coordinates from distance, azimuth and elevation

https://www.mathworks.com/help/phased/ug/spherical-coordinates.html#bs9g0ok

Once you have that coordinate system you need the 3d system to project on and remove e.g. the z axis later, e.g.

x: up screen y: left screen z: out of screen (towards you)

(right handed system, right-hand rule)

Then you can use some simple vector calculations to project your data on it, considering the view angles, and plot it in a separate plot.

More info on this can be found here (or search for projection 3d on coordinate system):

https://math.stackexchange.com/questions/2305792/3d-projection-on-a-2d-plane-weak-maths-ressources

https://math.stackexchange.com/questions/236540/2d-coordinates-of-projection-of-3d-vector-onto-2d-plane

https://math.stackexchange.com/questions/3763054/projecting-3d-points-onto-2d-coordinate-system-of-a-plane

https://math.stackexchange.com/questions/1814927/3d-perspective-projection

Joe
  • 6,758
  • 2
  • 26
  • 47