def cylinder(cls, **kwargs):
        """ Returns a cylinder.
            
            Kwargs:
                start (list): Start of cylinder, default [0, -1, 0].
                
                end (list): End of cylinder, default [0, 1, 0].
                
                radius (float): Radius of cylinder, default 1.0.
                
                slices (int): Number of slices, default 16.
        """
        s = kwargs.get('start', Vector(0.0, -1.0, 0.0))
        e = kwargs.get('end', Vector(0.0, 1.0, 0.0))
        if isinstance(s, list):
            s = Vector(*s)
        if isinstance(e, list):
            e = Vector(*e)
        r = kwargs.get('radius', 1.0)
        slices = kwargs.get('slices', 16)
        ray = e.minus(s)

        axisZ = ray.unit()
        isY = (math.fabs(axisZ.y) > 0.5)
        axisX = Vector(float(isY), float(not isY), 0).cross(axisZ).unit()
        axisY = axisX.cross(axisZ).unit()
        start = Vertex(s, axisZ.negated())
        end = Vertex(e, axisZ.unit())
        polygons = []
        
        def point(stack, angle, normalBlend):
            out = axisX.times(math.cos(angle)).plus(
                axisY.times(math.sin(angle)))
            pos = s.plus(ray.times(stack)).plus(out.times(r))
            normal = out.times(1.0 - math.fabs(normalBlend)).plus(
                axisZ.times(normalBlend))
            return Vertex(pos, normal)
            
        dt = math.pi * 2.0 / float(slices)
        for i in range(0, slices):
            t0 = i * dt
            i1 = (i + 1) % slices
            t1 = i1 * dt
            polygons.append(Polygon([start.clone(), 
                                     point(0., t0, -1.), 
                                     point(0., t1, -1.)]))
            polygons.append(Polygon([point(0., t1, 0.), 
                                     point(0., t0, 0.),
                                     point(1., t0, 0.), 
                                     point(1., t1, 0.)]))
            polygons.append(Polygon([end.clone(), 
                                     point(1., t1, 1.), 
                                     point(1., t0, 1.)]))
        
        return CSG.fromPolygons(polygons)
def cylinder ( cls , ** kwargs ) : s = kwargs . get ( 'start' , Vector ( 0.0 , - 1.0 , 0.0 ) ) e = kwargs . get ( 'end' , Vector ( 0.0 , 1.0 , 0.0 ) ) if isinstance ( s , list ) : s = Vector ( * s ) if isinstance ( e , list ) : e = Vector ( * e ) r = kwargs . get ( 'radius' , 1.0 ) slices = kwargs . get ( 'slices' , 16 ) ray = e . minus ( s ) axisZ = ray . unit ( ) isY = ( math . fabs ( axisZ . y ) > 0.5 ) axisX = Vector ( float ( isY ) , float ( not isY ) , 0 ) . cross ( axisZ ) . unit ( ) axisY = axisX . cross ( axisZ ) . unit ( ) start = Vertex ( s , axisZ . negated ( ) ) end = Vertex ( e , axisZ . unit ( ) ) polygons = [ ] def point ( stack , angle , normalBlend ) : out = axisX . times ( math . cos ( angle ) ) . plus ( axisY . times ( math . sin ( angle ) ) ) pos = s . plus ( ray . times ( stack ) ) . plus ( out . times ( r ) ) normal = out . times ( 1.0 - math . fabs ( normalBlend ) ) . plus ( axisZ . times ( normalBlend ) ) return Vertex ( pos , normal ) dt = math . pi * 2.0 / float ( slices ) for i in range ( 0 , slices ) : t0 = i * dt i1 = ( i + 1 ) % slices t1 = i1 * dt polygons . append ( Polygon ( [ start . clone ( ) , point ( 0. , t0 , - 1. ) , point ( 0. , t1 , - 1. ) ] ) ) polygons . append ( Polygon ( [ point ( 0. , t1 , 0. ) , point ( 0. , t0 , 0. ) , point ( 1. , t0 , 0. ) , point ( 1. , t1 , 0. ) ] ) ) polygons . append ( Polygon ( [ end . clone ( ) , point ( 1. , t1 , 1. ) , point ( 1. , t0 , 1. ) ] ) ) return CSG . fromPolygons ( polygons )
Returns a cylinder.
            
            Kwargs:
                start (list): Start of cylinder, default [0, -1, 0].
                
                end (list): End of cylinder, default [0, 1, 0].
                
                radius (float): Radius of cylinder, default 1.0.
                
                slices (int): Number of slices, default 16.