#๐Ÿ”’ Matplotlib linear algebra 3D planes: I cannot find a solution to plot a vertical plane

8 messages ยท Page 1 of 1 (latest)

worn shadow
#

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)
fair pierBOT
#

@worn shadow

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

worn shadow
#

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)
#

Correct plane with the normal vector shown

#

Incorrect plane with the correct normal vector. My problem is that I cannot figure out how to make the plane perpendicular to the normal vector, like what should be occuring.

#

**The sliders show the values in the equation Ax + By + Cz + D **

fair pierBOT
#

@worn shadow

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.