6

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.

ManaTree
  • 84
  • 1
  • 10
Arsh
  • 91
  • 1
  • **(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 https://blender.stackexchange.com/questions/270409/how-can-i-plot-this-cartesian-equation-in-geometry-nodes – Harry McKenzie Aug 12 '22 at 06:48
  • 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. – Robin Betts Aug 12 '22 at 07:03
  • @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. – Harry McKenzie Aug 12 '22 at 07:11
  • 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. – Gordon Brinkmann Aug 12 '22 at 07:17
  • 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 – Arsh Aug 12 '22 at 10:06
  • updated my answer to include restriction to domain $0 <= x <= 1$ and $0 <= y <= 1$ at the bottom of my answer. I'm not sure if it is possible with Z Math Surface so I asked this question and also not sure if it's possible with geometry nodes. Let's see what Crantisz comes up with :) – Harry McKenzie Aug 12 '22 at 13:19
  • @HarryMcKenzie It's not directly possible with Z Math Surface, although you could change the domain in a way to avoid the imaginary solutions and make it work. Rather than doing that I explained a way to do it with XYZ Math surface. See my answer there. – Marty Fouts Aug 12 '22 at 19:34

3 Answers3

6

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 - 4y

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 &lt; 0:
            continue
        pz = get_graph_z(px, py, real)
        verts.append([px, py, pz])

o = get_object(&quot;graph&quot;)
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 - 4y

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 &lt; 0:
            continue
        pz = get_graph_z(px, py, real)
        verts.append([px, py, pz])

o = get_object(&quot;graph&quot;)
m = o.data
m.clear_geometry()
m.from_pydata(verts, (), ())

draw_graph()

enter image description here

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
6

This is a Geometry nodes solution:

enter image description here

Crantisz
  • 35,244
  • 2
  • 37
  • 89
3

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

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51