3

In Carrara 4.0 Pro, I am able to create various modeling objects using math. The UI comes with 4 sliders (p1, p2, p3, p4), with values varying from -1 to +1 or -pi to +pi, and a text area for the logic loops that describe the formula, similar to the following:

r2=20*p1;
r1=10*p2;
t=2*PI*u;
p=PI*(v-0.5);
x=r1*cos(t)*cos(p);
y=r1*sin(t)*cos(p);
z=r1*sin(p);
x=x+r2*cos(t);
y=y+r2*sin(t);

So something like this would be nice to have, in Blender, as well.

David
  • 49,291
  • 38
  • 159
  • 317

1 Answers1

7

There's a Mesh Function add-on:

enter image description here

generates a UI for making parametric surfaces:

enter image description here


Blender 2.79-

Or use Sverchok's scripted node. This may be more complicated at first but allows a lot of customization.

import math
from math import pi as PI
from math import cos, sin

def sv_main(p1=0.3, p2=0.7, vdivs=20, points=200):
    verts_out = []

    in_sockets = [
        ['s', 'p1', p1],
        ['s', 'p2', p2],
        ['s', 'vdivs', vdivs],
        ['s', 'points', points]
    ]

    r2=20*p1
    r1=10*p2
    theta = 1/points
    vtheta = 1/vdivs

    for v in range(vdivs):
        v_points = []
        for i in range(points):
            t = 2 * PI * (theta * i)
            p = PI * ((vtheta*v) - 0.5)
            x = r1 * cos(t) * cos(p)
            y = r1 * sin(t) * cos(p)
            z = r1 * sin(p)
            x = x + r2 * cos(t)
            y = y + r2 * sin(t)
            v_points.append([x,y,z])

        verts_out.append(v_points)

    out_sockets = [
        ['v', 'verts', [verts_out]]
    ]

    return in_sockets, out_sockets

enter image description here

Because the script makes a nested list of each V ring of verts, the UV Connection node can make the appropriate "UV edge-surf".

For help with Sverchok in general see the documentation.
For help with Scripted Node specifically first have a look at the dedicated document about it


Blender 2.8+

for Blender 2.8 and Sverchok you will use ScriptedNode Lite, and it requires a small modification to the above script. I think you'll agree it's less verbose.

"""
in p1 s d=0.3 n=2
in p2 s d=0.7 n=2
in vdivs s d=20 n=2
in points s d=200 n=2
out verts_out v
"""

import math
from math import pi as PI
from math import cos, sin

r2 = 20 * p1
r1 = 10 * p2
theta = 1/points
vtheta = 1/vdivs

for v in range(vdivs):
    v_points = []
    for i in range(points):
        t = 2 * PI * (theta * i)
        p = PI * ((vtheta*v) - 0.5)
        x = r1 * cos(t) * cos(p)
        y = r1 * sin(t) * cos(p)
        z = r1 * sin(p)
        x = x + r2 * cos(t)
        y = y + r2 * sin(t)
        v_points.append([x,y,z])

    verts_out.append(v_points)
zeffii
  • 39,634
  • 9
  • 103
  • 186