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 transform_geom(geom, translation, rotation): # force cast to float (pgl does not accept values extracted from numpy arryas translation = map(float, translation) if isinstance(geom, pgl.Geometry): geom = pgl.Translated(translation, pgl.AxisRotated((0, 0, 1), rotation, geom)) elif isinstance(geom, pgl.Shape): geom = pgl.Shape( pgl.Translated(translation, pgl.AxisRotated((0, 0, 1), rotation, geom.geometry))) return geom
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 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 __init__(self, pos=ASHAPE3D_STANDARD_POS, axis=ASHAPE3D_STANDARD_AXIS, roll=ASHAPE3D_STANDARD_ROLL, scale=ASHAPE3D_STANDARD_SCALE, material=ASHAPE3D_STANDARD_MATERIAL, geometry=None, **keys): """Default constructor. Parameters: pos : Vector3 convertable pos of the object (look below), axis : Vector3 convertable main axis of the object, should be defined to describe the rotation. The Z of the primitive geometry would point to axis, roll : Real Property: rotation of the object around main axis, scale : Vector3 convertable to use while resizing the object. While scaling the Z corresponds to main axis of the object, material : pgl.Material describes the appearance of the object, geometry : pgl.Geometry describes the geometry of the object. """ if not geometry: raise Exception("AShape3D: geometry not defined.") self.geometry = geometry #TODO check for custom rotation, scale, transformation objects (shared between shapes) self.scaled = pgl.Scaled(scale, self.geometry) # roll related self._roll = roll #: to keep internal roll self.rolled = pgl.AxisRotated(pgl.Vector3.OZ, self._roll, self.scaled) # axis related (even the object which do not have intuitive axis need to have predefined axis self._axis = axis #: to keep internal axis vector rotation_axis = pgl.cross(pgl.Vector3.OZ, self._axis) rotation_angle = pgl.angle(self._axis, pgl.Vector3.OZ) self.rotated = pgl.AxisRotated(rotation_axis, rotation_angle, self.rolled) # position related self.translated = pgl.Translated(pos, self.rotated) # apperance related self.shape = pgl.Shape(self.translated, material)
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 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 pgl_scene(g, flip=False): geometry = g.property('geometry') scene = pgl.Scene() for id in geometry: if not flip: sh = pgl.Shape(geometry[id]) else: sh = pgl.Shape(pgl.AxisRotated(pgl.Vector3(1, 0, 0), pi, geometry[id])) sh.id = id scene.add(sh) return scene