# Convert Formula to xyz Function (blender python) - Pisot Triaxial Surface

Two sources: (See end result there as well)

http://www.atlantis23.com/ei_parmsurf/images/63.html

and

http://paulbourke.net/geometry/toroidal/ (scroll down)

Trying to get a handle on the process of converting readily available math formulas into mesh.

The formula (from the first source):

[general]
name = Pisot Triaxial;

comments = Charles Pisot (1910-1984).;

a1_min = 0;
a1_max = 6.28318530718;
a1_steps = 50;

a2_min = 0;
a2_max = 6.28318530718;
a2_steps = 50;

[formula]

X = 0.5 * 0.655866 * cos(deg(1.03002 + A1)) * (2 + cos(deg(A2)));
Y = 0.5 * 0.74878 * cos(deg(1.40772 - A1)) * (2 + 0.868837 * cos(deg(2.43773 + A2)));
Z = 0.5 * 0.868837 * cos(deg(2.43773 + A1)) * (2 + 0.495098 * cos(deg(0.377696 - A2)));

I'm guessing A1 and A2 translate to U and V respectively. Some of the other variables may perhaps translate to a, b, c, etc variables.

After that, I'm lost.

Eureka!

Based on Batfinger's input below, I put together this:

Literal copy paste.

# Pisot Triaxial Surface

### Math Function XYZ

X = 0.5 * 0.655866 * cos((1.03002 + u)) * (2 + cos((v)))
Y = 0.5 * 0.74878 * cos((1.40772 - u)) * (2 + 0.868837 * cos((2.43773 + v)))
Z = 0.5 * 0.868837 * cos((2.43773 + u)) * (2 + 0.495098 * cos((0.377696 -v)))

U Min = 0
U Max = 6.28
U Step = 50

V Min = 0
VMax = 6.28
V Step = 50

That works! There just seems to be so much out there that readily translates. Useful to know.

• Appears the equation on (legendary) Paul Bourke site are already in parameterized to u, v. Do not use degrees. – batFINGER Dec 22 '20 at 3:34
• Are you writing a script to generate the mesh? – HISEROD Dec 22 '20 at 4:37
• Nope. That's another endeavor for another time. This is using the XYZ Math Function. I'm guessing there are some differences in the code and the process. The XYZ functions would still be filtered through Blender Python wouldn't they? Or not? – unkerjay Dec 22 '20 at 4:46
• @BatFINGER re: "(legendary) Paul Bourke" indeed – unkerjay Dec 22 '20 at 4:48

## 1 Answer

Make a Script.

Seems you have already got there, started answer, thought I'd post as crunching in the equation via the text editor is IMO way simpler The equations are in parametric form on the Paul Bourke site linked to question.

To make them python expressions only requires adding an asterisk * to represent multiplication.

I find crunching formulas into blender's text boxes a little tedious, so have written as a script. Enable the Add Mesh Extra Objects addon to have the operator available.

Note: This is the script to run in object mode to create the Pisot Surface (Equations from Paul Bourke link in question) Simply copy script, paste into text editor and press run script. import bpy
from math import pi

# run in object mode
if context.mode != 'OBJECT':
bpy.ops.object.mode_set()

bpy.ops.mesh.primitive_xyz_function_surface(
x_eq="0.655866 * cos(1.03002 + u) * (2 + cos(v))",
y_eq="0.754878 * cos(1.40772 - u) * (2 + 0.868837 * cos(2.43773 + v))",
z_eq="0.868837 * cos(2.43773 + u) * (2 + 0.495098 * cos(0.377696 - v))",
range_u_max=2 * pi,
range_u_step=32,
range_v_max=2 * pi,
range_v_step=32,
edit_mode=False,
)


Notes. The defaults of the operator on first run can also be seen by bpy.ops.mesh.primitive_add_xyz_function_surface(Tab in blenders python console. There is no need to add a value to call above that is already a default.

The code below is the (expanded) result of auto completing the operator in the python console. It shows the default settings of the operator that create the sea shell. It is not the Tisot surface

>>> bpy.ops.mesh.primitive_xyz_function_surface(
primitive_xyz_function_surface()
bpy.ops.mesh.primitive_xyz_function_surface(
x_eq="cos(v)*(1+cos(u))*sin(v/8)",
y_eq="sin(u)*sin(v/8)+cos(v/8)*1.5",
z_eq="sin(v)*(1+cos(u))*sin(v/8)",
range_u_min=0,
range_u_max=6.28319,
range_u_step=32,
wrap_u=True,
range_v_min=0,
range_v_max=12.5664,
range_v_step=128,
wrap_v=False,
close_v=False,
n_eq=1,
a_eq="0",
b_eq="0",
c_eq="0",
f_eq="0",
g_eq="0",
h_eq="0",
show_wire=True,
edit_mode=True
)
Add a surface defined defined by 3 functions:
x=F1(u,v), y=F2(u,v) and z=F3(u,v)


Tip to more easily change some of the constants eg 0.868837 could assign them to a helper method.

    x_eq="A + u",
a_eq="0.868837"

• I plugged in the code, all but the part that begins "Add a surface" into the XYZ presets in 2.92a, and it bombed: imgur.com/a/6rQfLvF I'm going to try it in 2.91 stable and see if there's a difference. Not sure if I should be including the "Add a surface" code. Not sure how to incorporate the "Tip". It plugs into the presets fine, shows up, click on it, error. – unkerjay Dec 23 '20 at 6:28
• All I did was copy the code into blender and save it as a preset under "Application_Support/Blender/2.9x/Operator/Presets/XYZ_Surfaces" (might've fudged the exact location, don't have it in front of me). You get the idea. – unkerjay Dec 23 '20 at 6:35
• Simply copy code above, paste into text editor, and press run script. It is not a preset. – batFINGER Dec 23 '20 at 6:40
• I see the difference, the code in presets is formatted different. "x_eq" in the preset is "op.x_eq". Going to try reformatting the code. See if that works. – unkerjay Dec 23 '20 at 6:44
• Yeah, I tried that. I get a syntax error: imgur.com/a/VfIzpWB -- I copied and pasted all of it as shown above. Should I not have? If not, what to leave out? – unkerjay Dec 23 '20 at 6:49