# Example for creating and rotating of a mathematical function in a script

I want to make a body by rotating of this function in a script:

# Function

### X equation

(ln( ((v*pi)/1)-(pi/2) ) *(1/pi)+3)*sin(u)

### Y equation

(ln( ((v*pi)/1)-(pi/2) )*(1/pi)+3)*cos(u)

### Z equation

v

Are there any examples how I can do this?

• Please use the search function first. You have a parenthesis mismatch. I have not figured out how to use log with this addon. – Leander Jun 4 '18 at 9:47
• As it stands, your expressions have mismatched brackets - (e.g. the right bracket just before +3 in the X equation) - so they are ambiguous .. – Robin Betts Jun 4 '18 at 9:47
• try animation nodes. I already tried it and it works for this type of things. – HenrikD Jun 4 '18 at 10:02
• @Hen Would you mind writing that into an answer with easy to follow steps how one could create this mathematical surface? – Leander Jun 4 '18 at 10:59
• @Leander I am currently not at my PC but in 3h I could do that. – HenrikD Jun 4 '18 at 11:15

Your Animation Nodes Node Setup would look like this:

Basically it takes a generated grid mesh and deforms it with your functions to your 3D object which also gets constructed at the end. I used Math Nodes everywhere, but if you find out how you could use expressions or phython scripts to do that. The problem which I faced with expressions was the type being a list. Math Nodes handle that automatically so you dont have to worry about that. The generated Object would look like this:

For Python scripting, you might look first at Spin mesh (to create solid of revolution)

Then with your formulae, observe the x and y are of the form

x = r * sin, y = r * cos

with r as function of v --- r(v) = (ln( ((v*pi)/1)-(pi/2) ) *(1/pi)+3)

So build a 'mesh' of single joined lines, say in the y, z plane.

To get the vertices (0,y,z), pick a series of z values and find the y's

y = r(v) same here as y = r(z).

Then use spin() to get your body of rotation.

# Add an XYZ Math Surface

With the addon Add Mesh: Extra Objects enabled, you can add with Add > Mesh > Math Function > XYZ Math Surface lots of different mathematical surfaces.

You will see a lot of options for this operator also x, y and z. But just pasting the terms you stated in your question doesn't work: There is an error because there are 3 things wrong with you python code:

1. The python function for the natural logarithm $$\ln$$ in Blender is log(), not ln()
2. As @Leander pointed out there is a paranthesis mismatch. In this explanation I will just assume that closure of the first "(" is on the very end of each term.
3. $$\ln(x)$$ is not defined for values of $$x<0$$. Your code without sine/cosine part in maths is $$\frac{1}{\pi}\ln(\frac{v\pi}{1}-\frac{\pi}{2})) +3$$ or simplyfied $$\frac{\ln(\pi(v-0.5))}{\pi} +3$$. Here we easily spot that we have to prevent $$v$$ from being less or equal than $$0.5$$, because otherwise the $$\ln$$ is undefined and an error will be raised. Unfortunately the V min value in the options of the Add XYZ Math Surface operator cannot be set to a number greater 0 so we have to hack a bit:

The solution is to use a helper function in which v is checked if it is greater than 0.5. If not, the helper function will set the result to 0. In the following image you can see all the options used to plot

• I never knew Math Function exists and I am seeing Mechanical beneath. I will explore them today. Thank you for posting this. – Rita Geraghty May 13 at 9:15