Distribute spheres on ellipse pattern with python

29 views
Skip to first unread message

joão chaves

unread,
Oct 9, 2022, 4:52:24 PM10/9/22
to python_in...@googlegroups.com

Hey all.

I have a simple script that distributes spheres in a circular pattern (fixed by Justin Israel), and was looking for a solution that would distribute them in an ellipse/oval pattern. I am also trying to do this in bifrost, but as I have done for the circular pattern I need to understand the math first in python.

I also found this formula “(x2/a2) + (y2/b2) = 1” but not sure how to apply it.

Thank you!

import maya.cmds as cmds

degrees = 180
max_iterations = 21
t_x = 6
radius=0.15


for i in range(max_iterations):
    
    print(i)
    

    if degrees % 360 == 0:
        rotation = float(degrees) / max_iterations * i
    else:
        rotation = float(degrees) * i / (max_iterations-1)
    
    my_sphere = cmds.polySphere(r=radius)
    cmds.move(t_x,my_sphere, x=1 , absolute=1)  
    cmds.move( 0,0,0, [ my_sphere[0]+'.scalePivot', my_sphere[0]+'.rotatePivot' ], xyz=1, absolute=1 )

    cmds.rotate(rotation, my_sphere, y=1)

Justin Israel

unread,
Oct 10, 2022, 3:38:18 AM10/10/22
to python_in...@googlegroups.com
Full disclosure, I am not a math guy and I didn't know the solution straight away. But I wanted to look it up and see if I could apply it, given a known max and min radius, and an angle.
I found this to be the most useful of all the links I had found: https://stackoverflow.com/a/17762156/496445

What do you think of this solution I came up with based on that? 


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAEuwZHykcUm1Oc%2BQc%2BdU3BBt4rzP8wvLwvv3ckx2C%3DWo4CVHkg%40mail.gmail.com.

johancc

unread,
Oct 10, 2022, 6:41:51 AM10/10/22
to Python Programming for Autodesk Maya
Hey Justin. That's awesome! Thanks a lot for looking into it. The only issue I have is that it doesn't evenly distribute the spheres along the ellipse, maybe that's not easy to accomplish?
But this helps me a lot anyways. :)


ellipse.jpg

Marcus Ottosson

unread,
Oct 10, 2022, 10:30:18 AM10/10/22
to python_in...@googlegroups.com
> The only issue I have is that it doesn't evenly distribute the spheres along the ellipse, maybe that's not easy to accomplish?

Got an interesting thought-experiment for you. :) What would it look like to only distribute 3 or 4 spheres in an ellipse, with even spacing? Pen and paper is allowed.

joão chaves

unread,
Oct 10, 2022, 11:30:25 AM10/10/22
to python_in...@googlegroups.com
Hey. I believe it would like a diamond in case of 4.

Justin Israel

unread,
Oct 10, 2022, 3:04:07 PM10/10/22
to python_in...@googlegroups.com
On Tue, Oct 11, 2022 at 4:30 AM joão chaves <joao.c...@gmail.com> wrote:
Hey. I believe it would like a diamond in case of 4.

In the current implementation, you would have a diamond. But if the 4 points were evenly spaced, you would have a square.

Reply all
Reply to author
Forward
0 new messages