import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def draw_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3):
# Create the figure and the 3D axis
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Create the 3 points that define the plane
point1 = np.array([x1, y1, z1])
point2 = np.array([x2, y2, z2])
point3 = np.array([x3, y3, z3])
# Calculate the normal vector of the plane
normal_vector = np.cross(point2 - point1, point3 - point1)
# Calculate the equation of the plane in the form ax + by + cz + d = 0
a, b, c = normal_vector
d = -(a*x1 + b*y1 + c*z1)
# Create the x, y coordinate arrays for the grid
x_grid = np.linspace(min(x1, x2, x3) - 1, max(x1, x2, x3) + 1, 10)
y_grid = np.linspace(min(y1, y2, y3) - 1, max(y1, y2, y3) + 1, 10)
# Create the grid of z values on the plane
z_grid = (d - a*x_grid - b*y_grid) / c
# Plot the grid on the x-y plane
ax.plot_surface(x_grid, y_grid, z_grid, alpha=0.2, color='gray')
# Plot the 3 points that define the plane
ax.scatter(x1, y1, z1, color='r')
ax.scatter(x2, y2, z2, color='g')
ax.scatter(x3, y3, z3, color='b')
# Add labels and title
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('Plane in 3D space')
# Show the plot
plt.show()
You can use this function to draw a plane in 3D space by calling it with the 6 floating point coordinates that represent the x, y, z coordinates of the 3 points that define the plane:
draw_plane(1, 1, 1, 1, 3, 2, 3, 1, 3)
This will draw a plane defined by the points (1, 1, 1), (1, 3, 2), and (3, 1, 3).