# Try to draw math functions - questions about AddMesh: extra objects scripts

**URL:** <https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878>\
**Category:** Basics & Interface\
**Created:** [December 22, 2011, 9:01am UTC](https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878 "2011-12-22T09:01:27Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![test-dr](https://blenderartists.org/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@test-dr](https://blenderartists.org/u/test-dr)\
**Post date:** [December 27, 2011, 1:54pm UTC](https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878/21 "2011-12-27T13:54:18Z")

</div>

> [@RickyBlender](#):
>
> code simplification
> 
> i got one class per 3D object and working fine
> 
> but need to remove what is not needed
> 
> like i got this right now but it should possible to call function with only the index i think  
> whch would reduce code lines
> 
> ```auto
> 
>  
> i1=31
> if True or "NoDrop" in samples[i1]["name"]:
>  
> print (" i1=",i1,' param =',samples[i1])
>  
>  
>  
> o = add_xyz_object(helper=h,param=samples[i1],resolution=seg1)
> print(" i1=",i1,"This was 3D shape :", o.name)
>  
> if "Klein_" in o.name:
> print("2 parts .. no move")
> else:
>  
> o.location[0] = -3
> o.location[1] = 5 - (i1 % 5) * 2
> o.location[2] = int(i1/5)
>  
>  
>  
>  
> 
> ```
> 
> are the lines for klein necessary here ?
> 
> and this if line is it necessary too?
> 
> if True or “NoDrop” in samples[i1][“name”]:
> 
> if these lines can be drop it will remove quit a lot of lines
> 
> thanks  
> happy 2.6

there are different samples (not in my posted examples) to create  
types of “klein-bottles” and some need 2 parts and the user has  
to connect those – thats why i had put a “dont set new object to different  
location” for some …  
… and i did not use single indices to select one,  
i did use a loop (thats in the sample code) and did  
select it based on the name …  
(something like a “blender” list to select it not only from the index,  
but too, with the key-name … that would be a “dictionary-list”).

edit: about rendering those meshes, i did use a kind of wireframe setting  
(in the “treadmill” blend), cause i liked the view of the net-surface  
and thats why some will need a bit higher resolution and some will still  
look surprising in low resolution (low, like only 16 or 32 …for the xyz-settings).

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [December 27, 2011, 2:54pm UTC](https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878/22 "2011-12-27T14:54:29Z")

</div>

i see the klein bottle in 2 parts!

i did the snowman shape = 2 spheres  
and made each part as one sample item !

but did not joint the 2 after  
i could do it with bpy.ops afterward !

i removed most of the lines in the class  
and that makes it a lot shorter! LOL

now got to find a way to pass or change parameters functions of the properties !

happy 2.6

---

<div class="post-metadata">

**Author:** ![revolt\_randy](https://blenderartists.org/user_avatar/blenderartists.org/revolt_randy/32/8606_2.png) [@revolt\_randy](https://blenderartists.org/u/revolt_randy)\
**Post date:** [December 27, 2011, 7:57pm UTC](https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878/23 "2011-12-27T19:57:13Z")

</div>

Sorry to but in on this discussion, but I was reading thru this thread and came across this part.

> [@test-dr"](#):
>
> no - there is no menu-entry like generating “suzanne” (the monky-head) -  
> and i will not code one. If you want, you can delete the other entries and use  
> only the values for your desired 3d-shape and create an addon for it … but it will need the 3d-math-addon activated and i dont know how to do this, if the user has not activated it.

Instead of checking to see if the 3d-math-addon is activated, couldn’t you just import the part of the add-on you need into the script you’re working on?

I admit to being a noob at python, so if this can’t be done, could you explain why not?

Thanks,  
Randy

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [December 27, 2011, 8:32pm UTC](https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878/24 "2011-12-27T20:32:54Z")

</div>

that’s what i did in the new script !  
i copied the function i needed in my script  
faster to get it i guess!

dictionnary !  
did not work much with these beast!

how can is select one item and print one of the var ?  
tried this but does not work ?

print (’ j =’,j,’ name =’,samples[j].name)

i can calculate the lenght but how to acces the data per item?

i got to find why i cannot get the last 2 items in that list dic !

thanks  
happy 2.6

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [December 29, 2011, 7:58am UTC](https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878/25 "2011-12-29T07:58:41Z")

</div>

@ test-dr

Moebius problem

i’v been able to pass properties from the class to the dictionnary  
and for the first Moebius i can change the radius  
by changing the 1 for R = radius in formula

i can see the radius of the Moebius change in viewport  
which is working nicely

but i would like to also change the width of the Moebius  
but not certain how to change it ?  
like i need to change bfunc but also the vmin and vmax  
so how to calculate this V var for the S value = width of the Moebius?

did you use the formula from the site or from another site?  
[http://www.3d-meier.de/tut3/Seite13.html](http://www.3d-meier.de/tut3/Seite13.html)

cause the formula does not look the same ?

X= [R s + cos (t / 2)] \* cos (t)  
Y = [R s + cos (t / 2)] \* sin (t)  
Z = s sin (t / 2)

x=(1+v/2 cos(u/2)) \*cos(u)  
y=(1+v/2 \*cos(u/2)) \* sin(u)  
z=v/2 \*sin(u/2)

The constant R determines the radius of the belt.  
The constant s determines the widht of the belt.  
When parameter s = 0 we get a circle with radius R and height z = 0

samples.append( {“name”:“Moebius”,  
“x”:"(1+v/2 \*cos(u/2))\*cos(u)",  
“y”:"(1+v/2 \*cos(u/2))\*sin(u)",  
“z”:"v/2 _sin(u/2)",  
“umin”: 0,  
“umax”: 2_pi,  
“uwrap”: True,  
“vmin”: -1,  
“vmax”: 1,  
“vwrap”: True,  
} )

samples.append( {“name”:“Moebius”,  
“afunc”:“1.0”, # Radius of the Stripe = R  
“bfunc”:“1.0”, # Width of the stripe = s  
“x”:"(a +(b/2.0)\*cos(u/2.0))\*cos(u)",  
“y”:"(a +(b/2.0)\*cos(u/2.0))\*sin(u)",  
“z”:"(b/2.0)_sin(u/2.0)",  
“umin”: 0,  
“umax”: 2_pi,  
“uwrap”: True,  
“vmin”: -1,  
“vmax”: 1,  
“vwrap”: True,  
} )

any feedback appreciated

thanks  
happy 2.6

---

<div class="post-metadata">

**Author:** ![test-dr](https://blenderartists.org/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@test-dr](https://blenderartists.org/u/test-dr)\
**Post date:** [December 29, 2011, 9:21am UTC](https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878/26 "2011-12-29T09:21:04Z")

</div>

about the  
moebius formula

i dont remember,  
i know i searched with google  
and i shure did use some hints from wikipedia-pages,  
some from other - and  
i know, for some formulas, i had to enter those  
into the xyz-math-gui fields and test with changes  
what will happen.  
I am no math-3d-genius and cannot imagine how the output will look…  
… so some are tests and i did not correct some …

btw. this was the cause i did create this simple storage of xyz-surface-settings,  
because i soon noticed i could create some nice shapes and could not remember  
what kind of settings i had used … … (no history-line … )

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [December 29, 2011, 9:52am UTC](https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878/27 "2011-12-29T09:52:38Z")

</div>

ok i’ll check out wiki and some other math sites  
to see if i can find this math forumula

need that for the doc also!

thanks

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [December 29, 2011, 10:08am UTC](https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878/28 "2011-12-29T10:08:53Z")

</div>

looks like wiki has the same equation!

how can pass teh negative sign for v min ?

i tried this and it gives error for thsi

t3=rad1  
t4="-"+str(t3)  
t5=str(t3)

p1[“vmin”]=t4  
p1[“vmax”]=t5

there is a negative in the vmin but not certain why it is giving error on this one !

thanks

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [December 29, 2011, 11:06am UTC](https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878/29 "2011-12-29T11:06:28Z")

</div>

here is the error on console

the first property pass very well but the vmin does not like it !

vmin = -1.5 vmax= 1.5 width = 3.0  
t4 = -3.0 t5= 3.0  
eval = -3.0  
vmin = -3.0 vmax= 3.0 width = 3.0  
samples[i1] moebius = -3.0 samples[i1] moebius = 3.0  
resol = 4  
range\_v\_min= -3.0 range\_v\_max= 3.0  
Traceback (most recent call last):  
File “C:\Users\RJ\0blend25\00airfoilwindimill1\scriptformathfunction1\shapesho  
rt5.blend\shapeshort5.py”, line 1469, in execute  
File “C:\Users\RJ\0blend25\00airfoilwindimill1\scriptformathfunction1\shapesho  
rt5.blend\shapeshort5.py”, line 1335, in add\_xyz\_object  
File “C:\Users\RJ\0blend25\00airfoilwindimill1\scriptformathfunction1\shapesho  
rt5.blend\shapeshort5.py”, line 1128, in xyz\_function\_surface\_faces  
TypeError: unsupported operand type(s) for -: ‘str’ and ‘str’

i can change the value in the dictionary and it works fine

but being refuse if i change it wiht he property!

the string with signe or not is valid i can eval it and no problems!

strange !

thanks

thanks

[Previous page](https://blenderartists.org/t/try-to-draw-math-functions-questions-about-addmesh-extra-objects-scripts/527878.md?page=1)
