Is it possible to render the following equation in Blender to make a 3d visual?
$$z^2 + (x-y-1)(z) + y = 0$$
Is it possible to render the following equation in Blender to make a 3d visual?
$$z^2 + (x-y-1)(z) + y = 0$$
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 +/- ((x2 - 2xy - 2x + y2 + 2y + 1 - 4y)(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 x2 - 2xy - 2*x + y2 + 2y + 1 - 4y
def get_graph_z(x, y, real, sign = 1):
return (y-x+1)0.5 + (real0.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()
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:
Then add the surface function under object menu Add > Math Function > Z Math Surface to plot the 2 solutions.
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 :)
You cannot plot an Implicit function in Blender. You will need another software to do that. 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}$$
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.