Skip to content

Instantly share code, notes, and snippets.

@justinfx
Last active October 10, 2022 11:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinfx/b257dc162680978786ed4fd45409c997 to your computer and use it in GitHub Desktop.
Save justinfx/b257dc162680978786ed4fd45409c997 to your computer and use it in GitHub Desktop.
python_inside_maya: Plotting spheres in an ellipse shape over a given angle
# https://groups.google.com/g/python_inside_maya/c/EI2d7PrpKMk/m/zeYuI216AQAJ
# Plotting spheres in an ellipse shape over a given angle.
import math
from collections import namedtuple
import maya.cmds as cmds
Point = namedtuple("Point", "x y")
Ellipse = namedtuple("Ellipse", "a b origin")
def point_on_ellipse(ellipse, angle):
# https://stackoverflow.com/questions/17762077/how-to-find-the-point-on-ellipse-given-the-angle
x = ellipse.origin.x + ellipse.a * math.cos(angle * math.pi / 180.0)
y = ellipse.origin.y + ellipse.b * math.sin(angle * math.pi / 180.0)
x, y = round(x, 3), round(y, 3)
return Point(x, y)
origin = Point(0, 0)
my_ellipse = Ellipse(6, 3, origin)
degrees = 180
max_iterations = 21
for i in range(max_iterations):
if degrees % 360 == 0:
rot = float(degrees) / max_iterations * i
else:
rot = float(degrees) * i / (max_iterations-1)
pt = point_on_ellipse(my_ellipse, rot)
print(i, rot, pt)
my_sphere = cmds.polySphere(r=0.15)
cmds.move(pt.x, pt.y, my_sphere, xy=True, absolute=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment