2

I am trying to plot a plane that is parallel to both of x-axis and z-axis (xz-plane).

This code

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

point  = np.array([1, 2, 3])
normal = np.array([1, 1, 2])

# a plane is a*x+b*y+c*z+d=0
# [a,b,c] is the normal. Thus, we have to calculate
# d and we're set
d = -point.dot(normal)

# create x,y
xx, yy = np.meshgrid(range(10), range(10))

# calculate corresponding z
z = (-normal[0] * xx - normal[1] * yy - d) * 1. /normal[2]

# plot the surface
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(xx, yy, z)
plt.show()

is to plot a similar plane.

to have the plane parallel to the xz-plane, the params a and c in a*x+b*y+c*z+d=0 needs to be 0.

when I set normal = np.array([0, 2, 0]), the plane disappeared.

How to fix that?

1 Answers1

1

In your code, you divide by 0 when you calculate z. You can try this:

plt3d = plt.figure().gca(projection='3d')
xx, zz = np.meshgrid(range(10), range(10))
yy = 2 
plt3d.plot_surface(xx, yy, zz)
plt.show()
Joe
  • 12,057
  • 5
  • 39
  • 55