Skip to content

Instantly share code, notes, and snippets.

@goddoe
Created January 23, 2020 07:13
Show Gist options
  • Select an option

  • Save goddoe/486e6c6afe96710802e328f166731065 to your computer and use it in GitHub Desktop.

Select an option

Save goddoe/486e6c6afe96710802e328f166731065 to your computer and use it in GitHub Desktop.
plot_surface
# Reference : https://stackoverflow.com/questions/3461869/plot-a-plane-based-on-a-normal-vector-and-a-point-in-matlab-or-matplotlib/23006541
# author : Simon Streicher, Alexey Grigorev
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment