Source code for ddg.datastructures.indexedfaceset.ifs_generator

"""Module 'ifs_generator' generates geometric objects using ifs datastructure"""

import ddg.datastructures.indexedfaceset.ifs as ifs
import ddg.math.geometric_objects as geometric_objects


[docs]def tetrahedron(generate_coordinates=True): """ Create a tetrahedron as an ifs object. By default, standard coordinates of a unit tetrahedron, centered at (0,0,0), will be assigned to the vertices and can be accessed via the attribute coordinate `co`. Parameters ---------- generate_coordinates : bool (default=True) Decides on whether a container like coordinate attribute with default standard coordinates shall be assigned to the vertices. Returns ------- obj : ifs The tetrahedron that has been created. Notes ----- * Coordinate attribute The coordinate attribute `co` assigned to the vertices is of type `numpy.ndarray` and contains the default coordinates of the tetrahedron """ obj = ifs.IndexedFaceSet(geometric_objects.tetrahedron_faces()) if generate_coordinates: obj.set_attribute("co", "verts", geometric_objects.tetrahedron_coordinates()) return obj
[docs]def cube(generate_coordinates=True): """ Create a cube as an ifs object. By default, standard coordinates of a unit cube, centered at (0,0,0), will be assigned to the vertices and can be accessed via the attribute coordinate `co`. Parameters ---------- generate_coordinates : bool (default=True) Decides on whether a container like coordinate attribute with default standard coordinates shall be assigned to the vertices. Returns ------- obj : ifs The cube that has been created. Notes ----- * Coordinate attribute The coordinate attribute `co` assigned to the vertices is of type `numpy.ndarray` and contains the default coordinates of the cube """ obj = ifs.IndexedFaceSet(geometric_objects.cube_faces()) if generate_coordinates: obj.set_attribute("co", "verts", geometric_objects.cube_coordinates()) return obj
[docs]def octahedron(generate_coordinates=True): """ Create an octahedron as an ifs object. By default, standard coordinates of a unit octahedron, centered at (0,0,0), will be assigned to the vertices and can be accessed via the attribute coordinate `co`. Parameters ---------- generate_coordinates : bool (default=True) Decides on whether a container like coordinate attribute with default standard coordinates shall be assigned to the vertices. Returns ------- obj : ifs The octahedron that has been created. Notes ----- * Coordinate attribute The coordinate attribute `co` assigned to the vertices is of type `numpy.ndarray` and contains the default coordinates of the octahedron """ obj = ifs.IndexedFaceSet(geometric_objects.octahedron_faces()) if generate_coordinates: obj.set_attribute("co", "verts", geometric_objects.octahedron_coordinates()) return obj
[docs]def dodecahedron(generate_coordinates=True): """ Create a dodecahedron as an ifs object. By default, standard coordinates of a unit dodecahedron, centered at (0,0,0), will be assigned to the vertices and can be accessed via the attribute coordinate `co`. Parameters ---------- generate_coordinates : bool (default=True) Decides on whether a container like coordinate attribute with default standard coordinates shall be assigned to the vertices. Returns ------- obj : ifs The dodecahedron that has been created. Notes ----- * Coordinate attribute The coordinate attribute `co` assigned to the vertices is of type `numpy.ndarray` and contains the default coordinates of the dodecahedron """ obj = ifs.IndexedFaceSet(geometric_objects.dodecahedron_faces()) if generate_coordinates: obj.set_attribute("co", "verts", geometric_objects.dodecahedron_coordinates()) return obj
[docs]def icosahedron(generate_coordinates=True): """ Create an icosahedron as an ifs object. By default, standard coordinates of a unit icosahedron, centered at (0,0,0), will be assigned to the vertices and can be accessed via the attribute coordinate `co`. Parameters ---------- generate_coordinates : bool (default=True) Decides on whether a container like coordinate attribute with default standard coordinates shall be assigned to the vertices. Returns ------- obj : ifs The icosahedron that has been created. Notes ----- * Coordinate attribute The coordinate attribute `co` assigned to the vertices is of type `numpy.ndarray` and contains the default coordinates of the icosahedron """ obj = ifs.IndexedFaceSet(geometric_objects.icosahedron_faces()) if generate_coordinates: obj.set_attribute("co", "verts", geometric_objects.icosahedron_coordinates()) return obj
[docs]def disc(resolution=20, generate_coordinates=True, center=(0,0,0), normal=(0,0,1), radius=1): """ Create a disc as an ifs object. By default, the disc is centered at (0,0,0), the norm pointing at [0,0,1] and the radius 1. The coordinates of the vertices can be accessed via the attribute coordinate `co`. Parameters ---------- resolution : int (default=20) The amount of vertices of the disc generate_coordinates : bool (default=True) Decides on whether a container like coordinate attribute with default standard coordinates shall be assigned to the vertices. center : iterable (default=(0,0,0)) The center of the disc as a list in 3D space. normal : iterable (default=(0,0,1)) The normal vector of the disc. radius : float (default=1) The radius of the disc. Returns ------- obj : ifs The disc that has been created. """ obj = ifs.IndexedFaceSet(geometric_objects.disc_face(resolution)) if generate_coordinates: obj.set_attribute("co", "verts", geometric_objects.disc_coordinates( resolution, center, normal, radius)) return obj
[docs]def cylinder(resolution=20, generate_coordinates=True, top_radius=1, bot_radius=1, length=1, center=(0,0,0), normal=(0,0,1)): """ Create a cylinder as an ifs object. By default, the cylinder's bottom will be at (0,0,0) and it's top at (0,0,1). The coordinates of the vertices can be accessed via the attribute coordinate `co`. Parameters ---------- resolution : int (default=20) The amount of faces of the cylinder. generate_coordinates : bool (default=True) Decides on whether a container like coordinate attribute with default standard coordinates shall be assigned to the vertices. top_radius : float (default=1) The radius of the top of the cylinder. bot_radius : float (default=1) The radius of the bottom of the cylinder length : float (default=1) The length of the cylinder. center : iterable (default=(0,0,0)) The center of the bottom of the cylinder. normal : iterable (default=(0,0,1)) The normal of the cylinder's top and bottom faces. Returns ------- obj : ifs The cylinder that has been created. """ obj = ifs.IndexedFaceSet(geometric_objects.cylinder_faces(resolution)) if generate_coordinates: obj.set_attribute("co", "verts", geometric_objects.cylinder_coordinates( resolution, top_radius, bot_radius, length, center, normal)) return obj
[docs]def arrow(resolution=20, generate_coordinates=True, heights=(0,0.7,0.7,1), radii=(0.05,0.05,0.125)): """ Create an arrow as an ifs object which can be used to visualize vectors. By default, the arrow will point up. The bottom will be at (0,0,0) and the head at [0,0,1]. The coordinates of the vertices can be accessed via the attribute coordinate `co`. Parameters ---------- resolution : int (default=20) The amount of vertices at the base of the tip generate_coordinates : bool (default=True) Decides on whether a container like coordinate attribute with default standard coordinates shall be assigned to the vertices. heights : iterable (default=(0,0.7,0.7,1)) First element defines height of the bottom of the stick, the second the height of the top of the stick, the third the height of the base of the tip and the forth the height of the tip of the head. radii : iterable (default=(0.05,0.05,0.125)) First element defines the radius of the bottom of the stick, second the radius of the top of the stick and the third the radius of the base of the tip. Returns ------- obj : ifs The arrow that has been created. """ obj = ifs.IndexedFaceSet(geometric_objects.arrow_faces(resolution)) if generate_coordinates: obj.set_attribute("co", "verts", geometric_objects.arrow_coordinates( resolution, heights, radii)) return obj