def cvxHull(shape_list_or_scene, color=Green): """create a convex hull enveloppe :param Scene scene: a scene with shapes to process :param color color: a PGL Material to place on the convex hull :return: a PGL shape :: scene = Scene() scene += shapes hull = cvxhull(scene, color=Material(0,255,0)) scene += hull Viewer.display(hull) .. figure:: convex.png :width: 50% Example of convex hull enveloppe (of the leaves) added on top of a tree generated with pruning.lpy """ group = pgl.Group([sh.geometry for sh in shape_list_or_scene]) tglSet = pgl.fit('convexhull', group) hull = pgl.Shape(tglSet, color) return hull
def Unileaflet(length=1., width=1.): disc = pgl.Translated((-0.5,0,0), pgl.Disc()) disc = pgl.Scaled((length, width,1), disc) disc = pgl.AxisRotated(axis=(0,1,0), angle=radians(90.), geometry=disc) d3 = pgl.AxisRotated(axis=(1,0,0), angle=0., geometry=disc) shape = pgl.Group([d3]) return shape
def arrow(x,y,z,length,az=0, el=0, radius=None, color=color(255,255,255),id=0): if radius==None: radius=length*0.05 rad_az = math.radians(az) rad_el = math.pi/2 - math.radians(el) v = pgl.Vector3( x, y, z ) c = pgl.Cylinder(radius, length*0.8, 10) con =pgl.Translated(pgl.Vector3(0,0,length*0.7), pgl.Cone(2*radius, length*0.3)) arr = pgl.Group([c,con]) dir_arr = pgl.EulerRotated(rad_az,rad_el,0,arr) tr_dir_arr = pgl.Translated(v,dir_arr) return pgl.Shape(tr_dir_arr, color, id)
def stolon2d(g, v, turtle): scale= 1./5 cyl = pgl.Cylinder(0.01,0.5) cyl2 = pgl.Cylinder(0.01,0.2) cyl3 = pgl.Cylinder(0.01,0.2) cyl = pgl.AxisRotated(axis=(0,1,0), angle= radians(30.), geometry= cyl) cyl2 = pgl.AxisRotated(axis=(0,1,0), angle= -radians(120.), geometry= cyl2) cyl3 = pgl.AxisRotated(axis=(0,1,0), angle= -radians(180.), geometry= cyl3) cyl2= pgl.Translated((0.26,0,0.45),cyl2) cyl3= pgl.Translated((0.26,0,0.45),cyl3) sto= pgl.Group([cyl,cyl2,cyl3]) turtle.customGeometry(sto)
def computeBoundingShape(scene, shape='ellipsoid'): """ Compute a bounding volume for the given `scene`. The `shape` of this volume can be one of these keyword Note that the `pgl.fit` could deliver different shapes by using one of the following keyword instead of 'ellipsoid': EXTRUDEDHULL ; ASYMMETRICHULL ; EXTRUSION ; SPHERE ; ASPHERE ; BSPHERE CYLINDER ; ACYLINDER ; BCYLINDER ; ELLIPSOID ; BELLIPSOID2 ; AELLIPSOID BELLIPSOID ; AALIGNEDBOX ; BALIGNEDBOX ; BOX ; ABOX ; BBOX ; CONVEXHULL """ gr = pgl.Group([sh.geometry for sh in scene]) tglset = pgl.fit(shape, gr) #hull = pgl.Shape( tglSet, __Green ) return tglset
def __init__( self, radius=absolute_shapes.AARROW_STANDARD_RADIUS, axis=absolute_shapes.AARROW_STANDARD_AXIS, **keys ): """ Default constructor. """ #if keys.has_key("height"): # self._height = keys[ "height" ] #else: # self._height = pgl.norm( axis ) #self._radius = radius # #self.shaft = pgl.Scaled(pgl.Vector3(1, 1, AARROW_SHAFT_PROPORTION), ACYLINDER_PRIMITIVE ) #self.head = pgl.Translated(pgl.Vector3(0, 0, AARROW_SHAFT_PROPORTION), pgl.Scaled(pgl.Vector3( # AARROW_HEAD_PROPORTION,AARROW_HEAD_PROPORTION,1-AARROW_SHAFT_PROPORTION), ACONE_PRIMITIVE) ) keys.update( {"radius": radius, "axis": axis} ) self._common_init( **keys ) AIShape3D.__init__( self, scale=pgl.Vector3( 2*self.radius, 2*self.radius, self.height), geometry=pgl.Group([self.shaft,self.head]), **keys )
def leaflet(length=1., width=1.): """ return ------ a strawberry leaf composed of three discs """ disc = pgl.Translated((-0.5, 0, 0), pgl.Disc()) disc = pgl.Scaled((length, width, 1), disc) disc = pgl.AxisRotated(axis=(0, 1, 0), angle=radians(90.), geometry=disc) d1 = pgl.AxisRotated(axis=(1, 0, 0), angle=-radians(60.), geometry=disc) d2 = pgl.AxisRotated(axis=(1, 0, 0), angle=-radians(-60.), geometry=disc) d3 = pgl.AxisRotated(axis=(1, 0, 0), angle=0., geometry=disc) shape = pgl.Group([d1, d2, d3]) return shape
def unileaflet(length=1., width=1.): """Generates a unileaflet shape :param length: length of the shape, defaults to 1. :type length: float, optional :param width: width of the shape, defaults to 1. :type width: float, optional :return: the shape :rtype: pgl.Group """ disc = pgl.Translated((-0.5,0,0), pgl.Disc()) disc = pgl.Scaled((length, width,1), disc) disc = pgl.AxisRotated(axis=(0,1,0), angle=radians(90.), geometry=disc) d3 = pgl.AxisRotated(axis=(1,0,0), angle=0., geometry=disc) shape = pgl.Group([d3]) return shape
def __init__( self, radius=AARROW_STANDARD_RADIUS, axis=AARROW_STANDARD_AXIS, **keys ): """ Default constructor. Parameters: pos : Vector3 convertable the center of the lower basis, axis : Vector3 convertable the vector which is a symetry axis of an arrow. If no height is given the height of an arrow is the axis magnitude. height : Real the height of an arrow, radius : Real the radius of the lower basis """ keys.update( {"radius": radius, "axis": axis} ) self._common_init( **keys ) AShape3D.__init__( self, scale=pgl.Vector3(2*self.radius,2*self.radius,self.height), geometry=pgl.Group([self.shaft,self.head]), **keys )
def leaflet(length=1., width=1.): """Generate a strawberry leaf :param length: length of the leaflet, defaults to 1. :type length: float, optional :param width: width of the leaflet, defaults to 1. :type width: float, optional :return: A strawberry leaf composed of three discs :rtype: pgl.Group """ disc = pgl.Translated((-0.5,0,0), pgl.Disc()) disc = pgl.Scaled((length, width,1), disc) disc = pgl.AxisRotated(axis=(0,1,0), angle=radians(90.), geometry=disc) d1 = pgl.AxisRotated(axis=(1,0,0), angle=-radians(60.), geometry=disc) d2 = pgl.AxisRotated(axis=(1,0,0), angle=-radians(-60.), geometry=disc) d3 = pgl.AxisRotated(axis=(1,0,0), angle=0., geometry=disc) shape = pgl.Group([d1, d2, d3]) return shape
def cvxHull( scene ): #work with scene or shape list group = pgl.Group( [ sh.geometry for sh in scene ] ) tglSet = pgl.fit( 'convexhull', group ) hull = pgl.Shape( tglSet, __Green ) return hull