# [旧代码] 生成空间平面

Please refresh the page if equations are not rendered correctly.
---------------------------------------------------------------

Plane类的调用方式：

from polykriging.geometry import Plane


import numpy as np
import trimesh as tm

def cut_plane(point, normal, path = './', plot = False):
# 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)
xx, yy = np.meshgrid(np.arange(-0.7+ 0.15 + point[0], 0.7 + 0.15 + point[0], 1),
np.arange(-1.1 + 0.1 + point[1], 1.1 + 0.1 + point[1], 2.1))
if normal[2] != 0:
# calculate corresponding z
z = (-normal[0] * xx - normal[1] * yy - d) * 1. /normal[2]

print(z)
elif normal[1] != 0 and normal[2] == 0:
length = float(input('Please input the length of the plane:'))
width = float(input('Please input the width of the plane:'))
xx = np.array([point[0]-0.5*length, point[0] + 0.5*length, point[0]-
0.5*length, point[0] + 0.5*length ])
yy = (-normal[0] * xx  - d) * 1. /normal[1]
z = np.array([point[2]-0.5*width, point[2] - 0.5*width, point[2] +
0.5*width, point[2] + 0.5*width ])

elif normal[1] == 0 and normal[2] == 0:
length = float(input('Please input the length of the plane:'))
width = float(input('Please input the width of the plane:'))
xx = np.array([point[0], point[0], point[0], point[0] ])
yy = np.array([point[1]-0.5*length, point[1] + 0.5*length, point[1]-
0.5*length, point[1] + 0.5*length ])
z = np.array([point[2]-0.5*width, point[2] - 0.5*width, point[2] +
0.5*width, point[2] + 0.5*width ])

if plot == True:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# plot the surface
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(xx, yy, z)
plt.show()

# Create the cut plane and save as triangulated mesh.
vertices = np.zeros([4,3])
vertices[:, 0], vertices[:, 1], vertices[:, 2] = xx.flatten(), yy.flatten(), z.flatten()
# mesh objects can be created from existing faces and vertex data
tri_mesh = tm.Trimesh(vertices, faces=[[0, 1, 3], [3, 2, 0]])
tri_mesh.export(path+'perpendicular2.stl', file_type='stl_ascii')

if __name__ == "__main__":