-2

I want to plot multiple 3D planes using plot_surface function of matplotlib. I am using this link as reference.

I have planes that lie completely in ZY, ZX plane. In the link's solution I found that shifting the normal would work. It does not work with my code:

    for k in np.arange(len(t)):
    d[k] = -(np.dot(point[k], normal[k].T))
    xx, yy = np.meshgrid(np.arange(np.amin(t[..., 0]), 
             np.amax(t[..., 0] + 1)),
             np.arange(np.amin(t[..., 1]), np.amax(t[..., 1] + 1)))
    if (normal[k][2] == 0) and (normal[k][0] == 0):
        z = (-normal[k][2] * xx - normal[k][0] * yy - d[k]) * 1. / normal[k][1]
    elif (normal[k][2] == 0) and (normal[k][1] == 0):
        z = (-normal[k][1] * xx - normal[k][2] * yy - d[k]) * 1. / normal[k][0]
    else:
        z = (-normal[k][0] * xx - normal[k][1] * yy - d[k]) * 1. / normal[k][2]

    ax.plot_surface(xx, yy, z, color="black", linewidth=0, alpha=0.5)

xx and yy are a meshgrid of the range I want and k is just the index I am using to loop over all the planes.

Is my code correct? If not, what should be changed for it to work? Is there a better way to achieve this?

Edit: The expected output is a cube from all the planes instead I am only getting the planes in XY coordinate plane.

dee_eeb
  • 7
  • 2
  • `Is my code correct?` I don't understand this question. Do you get the expected output or not? Why do you have to ask us? – Mr. T Jan 29 '21 at 18:38
  • @Mr.T No, the output is incorrect as all planes are being plotted in XY plane. Even planes with XZ and YZ orientation – dee_eeb Jan 29 '21 at 18:43
  • Can you post the code so we can look at that ? – Jay Patel Jan 29 '21 at 18:46
  • @JayPatel I updated the code. Does that help? – dee_eeb Jan 29 '21 at 18:51
  • Does this help: https://stackoverflow.com/a/53116010/8881141 - your code is not reproducible, so I don't know what exactly the problem is. – Mr. T Jan 29 '21 at 20:37
  • @Mr.T thanks I took a look at the link, unfortunately that was not much help. But this helped a bit : https://stackoverflow.com/questions/13464304/how-can-i-plot-a-3d-plane-in-matlab/13473027#13473027 – dee_eeb Jan 29 '21 at 22:31

1 Answers1

0

This as reference, solves the problem. Updating initial reference as the following, will plot the planes when X=0 and Y=0.

    d = (np.dot(point, normal))
    #point is (x0,y0,z0) and normal (a,b,c)

    if normal[0] != 0:
        z, yy = np.meshgrid(zmin,zmax,ymin, ymax)
        xx = (-normal[2] * z - normal[1] * yy + d) * 1. / normal[0]

    elif normal[1] != 0:
        xx, z = np.meshgrid(xmin,xmax,zmin, zmax)
        yy = (-normal[0] * xx - normal[2] * z + d) * 1. / normal[1]

    elif normal[2] != 0:
        xx, yy = np.meshgrid(xmin,xmax,ymin, ymax)
        z = (-normal[0] * xx - normal[1] * yy + d) * 1. / normal[2]

    ax.plot_surface(xx, yy, z, color="yellow", linewidth=0, alpha=0.2)
dee_eeb
  • 7
  • 2