Skip to content

Instantly share code, notes, and snippets.

@adamelso
Last active September 16, 2021 11:49
Show Gist options
  • Save adamelso/b9c9288f5e252d8f99784f1cf23aa112 to your computer and use it in GitHub Desktop.
Save adamelso/b9c9288f5e252d8f99784f1cf23aa112 to your computer and use it in GitHub Desktop.
from math import cos, sin, pi
import c4d
from c4d import gui
VENUS_YEAR_DURATION = 224.7
EARTH_YEAR_DURATION = 365.25
VENUS_ORBIT_RADIUS = 108.2
EARTH_ORBIT_RADIUS = 149.6
# Script state in the menu or the command palette
# Return True or c4d.CMD_ENABLED to enable, False or 0 to disable
# Alternatively return c4d.CMD_ENABLED|c4d.CMD_VALUE to enable and check/mark
#def state():
# return True
# Main function
def main():
draw()
gui.MessageDialog('The path was successfully generated.')
def draw():
points = generate_vector_points()
spline = c4d.SplineObject(len(points), c4d.SPLINETYPE_BEZIER)
spline.SetAllPoints(points)
#t = {'vl': c4d.Vector(0, -83, 0), 'vr': c4d.Vector(0, 83, 0)}
#spline.SetTangent(1, t['vl'], t['vr'])
#spline.SetTangent(2, t['vl'], t['vr'])
doc.InsertObject(spline)
c4d.EventAdd()
def generate_vector_points():
points = []
eight_years_in_days = 365 * 8
for t in range(eight_years_in_days):
coordinates = calculate_coordinates_of_venus_path_at(t)
vector = generate_vector_from_coordinates(coordinates)
points.append(vector)
return points
def generate_vector_from_coordinates(coordinates):
return c4d.Vector(coordinates[0], coordinates[1], coordinates[2])
def calculate_coordinates_of_venus_path_at(t):
xPos = x(t)
yPos = y(t)
zPos = 0
return (xPos, yPos, zPos)
def x(t):
return (EARTH_ORBIT_RADIUS * cos(2 * pi * t / EARTH_YEAR_DURATION)) + (VENUS_ORBIT_RADIUS * cos(2 * pi * t / VENUS_YEAR_DURATION))
def y(t):
return (EARTH_ORBIT_RADIUS * sin(2 * pi * t / EARTH_YEAR_DURATION)) + (VENUS_ORBIT_RADIUS * sin(2 * pi * t / VENUS_YEAR_DURATION))
# Execute main()
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment