taxpon / openpyscad

Python library to generate OpenSCAD source code. This library provides intuitive interface when you handle 3D data.
https://pypi.org/project/openpyscad/
MIT License
119 stars 21 forks source link

New custom objects #6

Closed jpoullet2000 closed 7 years ago

jpoullet2000 commented 7 years ago

Would be great to have a class with some custom objects. See some illustration below... It can be called by

from openpyscad.custom2dshapes import Custom2dShapes as c2d
triangle = c2d.regular_polygon(3,10)
triangle.write('triangle.scad')
from math import cos, sin, pi
from openpyscad.shapes_2d import *

class Custom2dShapes(object):
    @staticmethod
    def regular_polygon(num, r):
        points = list()
        for i in range(num):
            a_deg = i * 360 / num
            a_rad = a_deg * 2 * pi / 360
            points += [[r * cos(a_rad), r * sin(a_rad)]]
        regular_poly = Polygon(points)
        return(regular_poly)

What do you think... at the moment I just put it in a separate file custom2dshapes.py but was wondering if you think of a better way to organize this kind of objects....

jpoullet2000 commented 7 years ago

this has been included in the last pull request ;)

taxpon commented 7 years ago

Thanks!