-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.

6
  • 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? Commented Jan 29, 2021 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 Commented Jan 29, 2021 at 18:43
  • Can you post the code so we can look at that ? Commented Jan 29, 2021 at 18:46
  • @JayPatel I updated the code. Does that help? Commented Jan 29, 2021 at 18:51
  • Does this help: stackoverflow.com/a/53116010/8881141 - your code is not reproducible, so I don't know what exactly the problem is. Commented Jan 29, 2021 at 20:37

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.