6
$\begingroup$

I need to render:

$$z = \left( y - x + 1 - \left[\left(y-x+1\right)^2 -4y\,\right]^\left(\frac{1}{2}\right) \right) \div 2$$

as a 3d function in Blender to make a visual using domain $$0<=x<=1$$ $$0<=y<=1$$

The software reports an error when I type **$(1/2)$ to add the square root part.

$\endgroup$
7
  • $\begingroup$ **(1/2) should work. are you using a text editor? and btw you're equation is missing a right side. is this equal to zero? equation = 0? you're equation looks like of implicit type so you cannot use it directly in blender, you need to transform it to something similar as in this thread blender.stackexchange.com/questions/270409/… $\endgroup$
    – Harry McKenzie
    Commented Aug 12, 2022 at 6:48
  • $\begingroup$ Where 4*y > (y-x+1)**2, you are asking for the square root of a negative number .. you would have to work out your own representation of Complex, 'Math Function' deals only with reals. Or restrict your domain. $\endgroup$
    – Robin Betts
    Commented Aug 12, 2022 at 7:03
  • $\begingroup$ @arsh oh or do you mean the form $z = z(x,y)$? so it is explicit and should be plotable, at least the real part of the equation. $\endgroup$
    – Harry McKenzie
    Commented Aug 12, 2022 at 7:11
  • $\begingroup$ Did you use **(1/2) for the square root but ^2 for the square part? That's not clear in your question. It's just that ^ doesn't work. $\endgroup$ Commented Aug 12, 2022 at 7:17
  • $\begingroup$ Thank you. How do I restrict the domain for both x and y? I want to domain to be 0 <= x <= 1 and 0 <= y <= 1 $\endgroup$
    – Arsh
    Commented Aug 12, 2022 at 10:06

4 Answers 4

6
$\begingroup$

This is a Geometry nodes solution:

enter image description here

$\endgroup$
1
  • $\begingroup$ the top part should not be displayed because it is imaginary. see my answer. only 4y <= (y−x+1)^2 can be plotted. $\endgroup$
    – Harry McKenzie
    Commented May 23 at 5:51
6
$\begingroup$

You can easily plot the points using a python script. This script iterates through a list of $x$ & $y$ values from $-70$ to $70$ where as @Robin Betts has pointed out $4y > (y-x+1)^2$ are imaginary values and cannot be plotted. So this script ignores negative values where the term $4y$ is greater than the term $(y-x+1)^2$ and only plots the real points.

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 the graph ( y - x + 1 - ( (y-x+1)^2 -4y )^(1/2) ) / (2)
# ==================================================================================================

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 (y - x + 1)**2 - 4*y

def get_graph_z(x, y, real):
    return ( y - x + 1 - ( real )**(1/2) ) / (2)

def draw_graph():
    verts = []

    for py in range(-70, 70):
        for px in range(-70, 70):
            real = get_graph_z_real(px, py)
            if real < 0:
                continue
            pz = get_graph_z(px, py, real)
            verts.append([px, py, pz])

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


draw_graph()

enter image description here

Or you can use the Z Math Surface under object menu Add > Math Function > Z Math Surface

enter image description here

But since you have that imaginary part you cannot directly use the equation $(y-x+1-((y-x+1)^2-4y)^{1/2} )/(2)$ but instead need to use a condition to filter out the imaginary part. The best you can do is probably set the term $(y-x+1)^2-4y$ to zero if $4y$ is greater than $(y-x+1)^2$ like so (or experiment with other non-imaginary values):

(y-x+1-((y-x+1)**2 -4*y if 4*y < (y-x+1)**2 else 0 )**(1/2) ) / (2)

enter image description here

Another sample to restrict the domain to $0 <= x <= 1$ & $0 <= y <= 1$

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 the graph ( y - x + 1 - ( (y-x+1)^2 -4y )^(1/2) ) / (2)
# ==================================================================================================

def get_range(start, end, step = 2):
    return [x * 0.001 for x in range(start * 1000, end * 1000, step)]
 
def get_graph_z_real(x, y):
    return (y - x + 1)**2 - 4*y

def get_graph_z(x, y, real):
    return ( y - x + 1 - ( real )**(1/2) ) / (2)

def draw_graph():
    verts = []

    for py in get_range(0, 1):
        for px in get_range(0, 1):
            real = get_graph_z_real(px, py)
            if real < 0:
                continue
            pz = get_graph_z(px, py, real)
            verts.append([px, py, pz])

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

draw_graph()

enter image description here

$\endgroup$
0
3
$\begingroup$

Here's a Geometry Nodes solution to cater to math domain $0<=x<=1$ & $0<=y<=1$

enter image description here

Note: In case you are wondering why it has jagged edges, it actually is an accurate representation of the boundary between real and complex numbers. See comments in GN: How to smooth out jagged edges after deleting geometry?

This one confirms the output of my python solution in the other answer.

enter image description here

$\endgroup$
1
$\begingroup$

Here's a Geometry Nodes solution using Volume Cube node. Take note that values for $4y > (y-x+1)^2$ are imaginary and cannot be plotted because there is no square root for negative values hence the imaginary check before the Density socket input.

enter image description here

enter image description here

$\endgroup$

You must log in to answer this question.

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