3
$\begingroup$

Is it possible to render the following equation in Blender to make a 3d visual?

$$z^2 + (x-y-1)(z) + y = 0$$

$\endgroup$
2
  • 3
    $\begingroup$ I sincerely hope you don't have a hundred more equations you want to render and ask a question for each of them :D $\endgroup$ Commented Aug 12, 2022 at 12:05
  • 1
    $\begingroup$ Yeah no it's because I'm new to blender and I wanted to use the software to create a visual for a project. I tried plotting the explicit function and it worked but I wanted to create a visual of better quality, and so I thought an implicit equation may be better. $\endgroup$
    – Arsh
    Commented Aug 13, 2022 at 4:09

4 Answers 4

5
$\begingroup$

You cannot plot an Implicit function in Blender. You will need another software to do that. You can plot an Implicit function using Volume Cube. However, your equation is not implicit because there is a way to convert it into an Explicit function. Implicit means that there is no way to convert it into explicit form. Here's a solution using Geometry Nodes that shows the graph for your original equation $z^2+(x−y−1)(z)+y=0$ using an explicit function that was derived from that original equation in my solution in the other answer:

$$z = \frac{1}{2}(y-x+1)\pm \frac{1}{2}\sqrt{\left(x−y−1\right)^{2} - 4y}$$

enter image description here

Take note that the jagged edges between the upper and lower graph are the exact representation of the boundary between real and imaginary (complex) numbers.

enter image description here

$\endgroup$
4
$\begingroup$

The equation $z^2 + (x-y-1)(z) + y = 0$ has the form of a Quadratic Equation so you can derive an explicit equation in the form $z=z(x,y)$

$$Az^2+Bz+C=0$$ where: $$A=1$$ $$B=(x-y-1)$$ $$C=y$$


and $z$ can be explicitly defined as: $$z=\frac{-B\pm\sqrt{B^2-4AC}}{2A}$$ substituting we get: $$z = \frac{-(x−y−1)\pm \sqrt{\left(x−y−1\right)^{2} - 4(1)(y)}}{2(1)}$$

$$z = \frac{1}{2}(y-x+1)\pm \frac{1}{2}\sqrt{x^2 - 2xy - 2x + y^2 + 2y + 1 - 4y}$$

There are two (2) solutions:

z = (y-x+1)*0.5 + ((x**2 - 2*x*y - 2*x + y**2 + 2*y + 1 - 4*y)**(0.5))*0.5
z = (y-x+1)*0.5 - ((x**2 - 2*x*y - 2*x + y**2 + 2*y + 1 - 4*y)**(0.5))*0.5

Take note that we have an imaginary component, where, $x^2 - 2xy - 2x + y^2 + 2y + 1$ has to be greater than $4y$ or else we have a negative value in the square root function ($\sqrt{value}=value^{0.5}$) which would result to an imaginary number and cannot be visualized so we have to add a check to ignore these points. We can easily plot that in python without any problems:

import bpy

def get_object(name):
    objects = bpy.context.scene.objects
    if name in objects:
        return objects[name]
    m = bpy.data.meshes.new(name + "-mesh")
    o = bpy.data.objects.new(name, m)
    #o.modifiers.new(name, 'SKIN')
    bpy.context.collection.objects.link(o)
    return o 
 
# ==================================================================================================
# Equation:
# Descritpion: plot z = (y-x+1)*0.5 +/- ((x**2 - 2*x*y - 2*x + y**2 + 2*y + 1 - 4*y)**(0.5))*0.5
# ==================================================================================================

def get_range(start, end, step = 2):
    return [x * 0.1 for x in range(start * 10, end * 10, step)]

def get_graph_z_real(x, y):
    return x**2 - 2*x*y - 2*x + y**2 + 2*y + 1 - 4*y

def get_graph_z(x, y, real, sign = 1):
    return (y-x+1)*0.5 + (real**0.5)*0.5 * sign

def create_verts(verts, sign):
    for py in get_range(-5, 5, 2):
        for px in get_range(-5, 5, 2):
            real = get_graph_z_real(px, py)
            if real < 0:
                continue
            pz = get_graph_z(px, py, real, sign)
            verts.append([px, py, pz])

def draw_graph():
    verts = []

    create_verts(verts, 1)
    create_verts(verts, -1)

    o = get_object("graph")
    m = o.data
    m.clear_geometry()
    m.from_pydata(verts, (), ())

draw_graph()

enter image description here

And then you can use the method described in How can I convert a complex point cloud to mesh to convert it to a mesh.

We can also use the Z Math Surface but unfortunately there we have to add an if/else check and evaluate the square root part to zero or some other value for the imaginary component which will add an additional unwanted region in the 3d surface:

z = (y-x+1)*0.5 + ((x**2 - 2*x*y - 2*x + y**2 + 2*y + 1 - 4*y if x**2 - 2*x*y - 2*x + y**2 + 2*y + 1 > 4*y else 0)**(0.5))*0.5
z = (y-x+1)*0.5 - ((x**2 - 2*x*y - 2*x + y**2 + 2*y + 1 - 4*y if x**2 - 2*x*y - 2*x + y**2 + 2*y + 1 > 4*y else 0)**(0.5))*0.5

First make sure to have Extra Objects addon enabled in menu Edit > Preferences > Add-ons:

enter image description here

Then add the surface function under object menu Add > Math Function > Z Math Surface to plot the 2 solutions.

enter image description here

If I didn't make any mistake in my calculation then the graph should look like this. Notice that the imaginary part is plotted with the square root part evaluated to zero. Anyway you get the idea :)

enter image description here

$\endgroup$
0
2
$\begingroup$

You can also use Volume Cube node.

enter image description here

There's a small mistake in the above screenshot: Instead of X it should be Z into the Math (Power) node. Thanks StefLAncien for spotting the mistake. Here's the correct output:

enter image description here

$\endgroup$
2
  • $\begingroup$ @StefLAncien I was wondering why it looked different. Now I have it correct thanks for the correction! snipboard.io/2NiEP5.jpg $\endgroup$
    – Harry McKenzie
    Commented Jun 1 at 5:15
  • $\begingroup$ @StefLAncien thanks for ur answer additional things to learn +1. I also updated my post. $\endgroup$
    – Harry McKenzie
    Commented Jun 1 at 21:47
1
$\begingroup$

(Using Blender 3.6.8)

Analysis

Let $f(x,y,z)$ be the function of $\mathbb{R}^3$ defined by: $$ f(x,y,z) = z^2 + (x-y-1)z + y $$

$f(x,y,z)=0$ can be interpreted as the following quadratic equation in $(x,z)$: $$ (0) \times x^2 + (1) \times xz + (1) \times z^2 + (-y-1) \times z + (0) \times x + (y) = 0 $$ The graph of such an equation is always a conic section. Its discriminant being greater than 0, this equation represents a hyperbola, parametrized by $y$, the remaining coordinate. Consequently (see the Mathematics subsection thereafter), it can be converted to canonical form in transformed variables $(X,Y,Z)$ as: $$ F(X,Y,Z) = X Z + Y = 0 \Longleftrightarrow X Z = -Y $$ with: $$ \left\{ \begin{array}{rcl} X & = & x-y+z-1 \\ Y & = & y \\ Z & = & z \end{array} \right. $$

Results The figure above illustrates with planes and cylinders the transformed coordinate system $(X,Y,Z)$. It shows how the surface of interest is divided in four parts of hyperbola shape, according the sign of $Y$ which is determining if the sign of $X$ and $Z$ is the same. (NB: A Boolean modifier is used to keep only points in a cube spanning $[-5,5]^3$)

Approach

The proposed approach is to mesh the surface of interest in the $(X,Y,Z)$ coordinate system, then to transform it to the $(x,y,z)$ coordinate system. Sampling the $(X,Z)$ plane yields $Y=-XZ$ without singularities, like division by zero or square root of negative number.

GeometryNodes modifier

GN Graph

Bottom graph: $(X,Y,Z)$ grid generation
1. A 101x101 points Grid spanning 20x20 $m^2$ is generated, then rotated by 90 degrees around the X axis to discretize the $(X,0,Z)$ plane.
2. After recovery of $X$ and $Z$ coordinates through a Separate XYZ node, the vector $(0,-XZ,0)$ is computed and assembled with a Combine XYZ node.
3. It is used to offset grid points to coordinates $(X,-XZ,Z)$ with a Set Position node.
4. Eventually, $(x,y,z)$ coordinates are computed from $(X,Y,Z)$ by the XYZ to xyz group node.

Top graph: $(X,Y,Z)$ to $(x,y,z)$ conversion
$(x,y,z)$ are defined as (see the Mathematics subsection thereafter): $$ \left[ \begin{array}{r} x \\ y \\ z \end{array} \right] = \left[ \begin{array}{rrr} 1 & 1 & -1 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array} \right] \left[ \begin{array}{r} X \\ Y \\ Z \end{array} \right] + \left[ \begin{array}{r} 1 \\ 0 \\ 0 \end{array} \right] $$ 5. The product of the lines of the matrix with the Position vector is computed using Dot Product vector math nodes.
6. The offset of the origin is computed using an Add vector math nodes.
7. Eventually, $(x,y,z)$ coordinates are substituted to $(X,Y,Z)$ by a Set Position node.

Mathematics

Canonical form

The expression of $f(x,y,z)$ is simple enough to write: $$ \begin{array}{rcl} f(x,y,z) & = & z^2 + (x-y-1)z + y \\ \mbox{} & = & (x-y+z-1)z + y \end{array} $$

Let the coordinates $(X,Y,Z)$ and the function $F$ be defined as: $$ \left\{ \begin{array}{rcl} X & = & x-y+z-1 \\ Y & = & y \\ Z & = & z \end{array} \right. \\ F(X,Y,Z)=XZ+Y $$ Consequently, $f(x,y,z) = F(X,Y,Z)$.

Change-of-basis matrix

In linear algebra formalism, the above expression of $(X,Y,Z)$ as a function of $(x,y,z)$ is written: $$ \left[ \begin{array}{r} X \\ Y \\ Z \\ 1 \end{array} \right] = \left[ \begin{array}{rrrr} 1 & -1 & 1 & -1 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{array} \right] \left[ \begin{array}{r} x \\ y \\ z \\ 1 \end{array} \right] $$

The change-of-basis matrix from $(X,Y,Z)$ to $(x,y,z)$ is calculated by inverting the previous matrix. It is written: $$ \left[ \begin{array}{r} x \\ y \\ z \\ 1 \end{array} \right] = \left[ \begin{array}{rrrr} 1 & 1 & -1 & 1 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{array} \right] \left[ \begin{array}{r} X \\ Y \\ Z \\ 1 \end{array} \right] $$

Resources

Blender file:

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .