I am trying to make a tool for visualizing the stuff I learn in linear algebra. I am able to plot points and vectors very easily in 3D space, but I cannot for the life of me figure out planes. Everything works fine, until the Z coordinate is equal to 0. I am using the equation for a plane Ax + By + Cz + D. I have looked through (I think at this point) every article there is about my very specific problem, and I even used ChatGPT to try to work this out. Nothing works, and can't plot vertical planes. My code is below. As a placeholder, I have Z set to a matrix of 0s, if the Z coordinate is equal to zero. I have commented the parts in the function tasand (this word means "plane" in Estonian).
import numpy as np
class Graaf:
def __init__(self, ax):
self.ax = ax
self.x_vals = np.arange(-6, 6)
self.y_vals = np.arange(-6, 6)
self.z_vals = np.arange(-6, 6)
self.X, self.Y = np.meshgrid(self.x_vals, self.y_vals)
def punkt(self, x, y, z):
self.ax.scatter(x, y, z, color='r', s=100)
def vektor(self, x, y, z, u=0, v=0, w=0):
self.ax.quiver(u, v, w, x, y, z, color='b', arrow_length_ratio=0.1)
def tasand(self, A, B, C, D):
if C != 0:
# Regular plane case: Ax + By + Cz + D = 0 (THIS PART WORKS FINE)
Z = (-A * self.X - B * self.Y - D) / C
self.plane = self.ax.plot_surface(self.X, self.Y, Z, alpha=0.7)
else:
# THIS PART DOES NOT WORK
Z = np.zeros_like(self.X)
self.plane = self.ax.plot_surface(self.X, self.Y, Z, alpha=0.7)