mpacts.geometrygenerators. trianglegeometries

In order to be able to use this module import it like this:

import mpacts.geometrygenerators.trianglegeometries
#or assign it to a shorter name
import mpacts.geometrygenerators.trianglegeometries as tri

UnitCube

class mpacts.geometrygenerators.trianglegeometries.UnitCube

Bases: mpacts.geometrygenerators.polyhedron.Polyhedron

UnitCube(name, parent, **kwargs)

UnitHexagon

class mpacts.geometrygenerators.trianglegeometries.UnitHexagon

Bases: mpacts.geometrygenerators.polyhedron.Polyhedron

calculates the hexagon with area 1 around (0,0,0) in the xy-plane.

UnitHexagon(name, parent, **kwargs)
subdivide(n=1)

UnitIcoSphere

class mpacts.geometrygenerators.trianglegeometries.UnitIcoSphere(n, ico=<mpacts.geometrygenerators.trianglegeometries.UnitIcosahedron object>, decrement=False)

Bases: mpacts.geometrygenerators.polyhedron.Polyhedron

Calculates vertices, edges and faces by subdividing another IcoSphere or icosahedron (default) “n” times, thereby approximately quadrupling vertices, ... for each subdivision.

UnitIcoSphere(name, parent, **kwargs)
scaleVertices(scale)
setData(scale=1.0)

UnitIcosahedron

class mpacts.geometrygenerators.trianglegeometries.UnitIcosahedron

Bases: mpacts.geometrygenerators.polyhedron.Polyhedron

Creates an icosahedron centered around (0,0,0).

UnitIcosahedron(name, parent, **kwargs)
scaleVertices(scale)
setData(scale=1.0)

UnitTetrahedron

class mpacts.geometrygenerators.trianglegeometries.UnitTetrahedron(subdivide=0.0)

Bases: mpacts.geometrygenerators.polyhedron.Polyhedron

Creates a tetrahedron centered around (0,0,0).

UnitTetrahedron(name, parent, **kwargs)

UnitTriangle

class mpacts.geometrygenerators.trianglegeometries.UnitTriangle

Bases: mpacts.geometrygenerators.polyhedron.Polyhedron

calculates the regular triangle with side length 1 centered around (0,0,0) in the xy-plane

UnitTriangle(name, parent, **kwargs)
mpacts.geometrygenerators.trianglegeometries.check_edge_in_triangle(edge, test_t)

Given an edge containing two indices, it checks whether this edge is present in a given triangle (given by three indices)

mpacts.geometrygenerators.trianglegeometries.combine_triangle_meshes(meshlist)

For a list of meshes (each with vertices and triangles) this returns a combined vertices and triangle list (with triangles properly incremented)

mpacts.geometrygenerators.trianglegeometries.correct_triangle_normals(vertices, triangles, opt_bw=True)

For a given SOLID object, this corrects the triangle normals so they are all consistent and would result in a positive volume. WARNING: using this function for non-solids (or multiple solids), will only resolve the ‘sub’-solid containing triangle index zero!

mpacts.geometrygenerators.trianglegeometries.create_hex_mesh_from_vertices(v, distance_between_points, perpendicular_to, center=(0, 0, 0), invert=True, edge_vertices=None, corner_vertices=None)

Returns positions, triangles and edges for points with an assumed connectivity of 6.

Parameters:

-v vertices
-distance_between_points
 spacing of the points...
-perpendicular_to
 to fix triangle oriantation, we need to know - can be ‘x’, ‘y’ (default) or ‘z’
-center vertices will be translated by this much...
-invert switch between e.g. y and -y as the orientation.
-edge_vertices list of vertices which have 4-5 connections
-corner_vertices
 list of vertices which have <4 connections
mpacts.geometrygenerators.trianglegeometries.create_hex_mesh_from_vertices_convex_around_center(v, distance_between_points, center=(0, 0, 0), invert=False, edge_vertices=None, corner_vertices=None)

Returns positions, triangles and edges for points with an assumed connectivity of 6.

Parameters:

-v vertices
-distance_between_points
 spacing of the points...
-perpendicular_to
 to fix triangle oriantation, we need to know - can be ‘x’, ‘y’ (default) or ‘z’
-center vertices will be translated by this much...
-invert switch between e.g. y and -y as the orientation.
-edge_vertices list of vertices which have 4-5 connections
-corner_vertices
 list of vertices which have <4 connections
mpacts.geometrygenerators.trianglegeometries.create_plane(width, height, perpendicular_to='y', invert=False)

creates a plane perpendicular to x, y or z with given dimensions. Use transformations to move/rotate this plane

mpacts.geometrygenerators.trianglegeometries.create_regular_mesh_from_vertices(v, distance_between_points, perpendicular_to, center=(0, 0, 0), invert=True, edge_vertices=None, corner_vertices=None)

Returns positions, triangles and edges for points with an assumed connectivity of 8.

Parameters:

-v vertices
-distance_between_points
 spacing of the points...
-perpendicular_to
 to fix triangle oriantation, we need to know - can be ‘x’, ‘y’ (default) or ‘z’
-center vertices will be translated by this much...
-invert switch between e.g. y and -y as the orientation.
-edge_vertices list of vertices which have 4-7 connections
-corner_vertices
 list of vertices which have <4 connections
mpacts.geometrygenerators.trianglegeometries.create_triangulated_box(x_size, y_size=None, z_size=None, N=2, invert=False, **kwargs)

Make an (axis-aligned) box with given dimensions.

Parameters:

-x_size length of side along x-axis -y_size length of side along y-axis (default: x_size) -z_size length of side along z-axis (default: x_size) -N number of vertices along smallest dimension -invert if False (default), normals point inwards

returns vertices and triangles.

mpacts.geometrygenerators.trianglegeometries.create_triangulated_hex_plane(distance_between_points, N=10, perpendicular_to='y', center=(0, 0, 0), invert=True, edge_vertices=None, corner_vertices=None)

Creates vertices, triangles and edges of a triangulated hexagon.

Parameters:

-distance_between_points
 the edge length of the triangles
-N number of edges in the hexagon center-line
-perpendicular_to
 which coordinate axis, default: ‘y’
-center center of plane
-invert direction of triangles w.r.t. perp. axis
-edge_vertices vertices with less than 6 neighbors will be appended to this, if given.

returns vertices, triangles, edges

mpacts.geometrygenerators.trianglegeometries.create_triangulated_hex_rectangle(distance_between_points, N, center=(0, 0, 0), invert=True, edge_vertices=None, corner_vertices=None, crop_jagged_edges=True)
mpacts.geometrygenerators.trianglegeometries.create_triangulated_plane(width, height, N=10, perpendicular_to='y', center=(0, 0, 0), invert=True, edge_up=None)

Creates vertices, triangles and edges of a triangulated hexagon.

Parameters:

-width length of plane in first dimension
-height length of plane in second dimension
-N number of vertices in the smallest dimension
-perpendicular_to
 which coordinate axis, default: ‘y’
-center center of plane
-invert direction of triangles w.r.t. perp. axis
-edge_up will generate “folded-up” vertices in this...

returns vertices, triangles, edges

mpacts.geometrygenerators.trianglegeometries.create_truncatedcone(baseradius, topradius, height, N)

Create a truncated cone with given base radius, top radius and height with center of the base = 0, 0, 0. N is the number of corners or edges of the regular polygon which approximates the circular shape. The number of triangles in the truncated cone is thus 2*N Use transformations to put this cone elsewhere

mpacts.geometrygenerators.trianglegeometries.find_edge_triangles(edge, triangles)
mpacts.geometrygenerators.trianglegeometries.look_common_edge(good_t, test_t)

Given a reference ‘good’ triangle and a ‘test’ triangle, this returns the common edge, in the order as occuring in the reference triangle

mpacts.geometrygenerators.trianglegeometries.resolve_surrounding_normals(triangle_id, id_list, c, triangles, rec=True)
Given a triangle with known ‘correct’ normal, this recurvively flips all surrounding normals which are not conforming to this one,
growing until a whole solid object is consistent. WARNING: if the given mesh is not one solid object, it will likely throw a max recursion error and fail! second WARNING: stack overflow WILL occur for too large meshes because of high recursion levels. Use the function ‘resolve_surrounding_normals_front’ below for more safety.

Parameters

  • triangle id: Index of the known reference triangle with ‘correct’ normal
  • id_list: A list of all triangles which have already been ‘checked’ for normals. The first time, only the reference triangle should contain value ‘1’
  • c: a connectivity object
  • triangles: a list of triangles (will be modified), defined as a list of tuples containg node indices
  • rec: If false, we will only resolve the given triangle, and ignore the recursion For large meshes, using ‘resolve_surrounding_normals_front’ (which sets rec to false here) instead is more safe and will prevent stack-overflow errors due to high recursion levels!

Please note that the function ‘correct_triangle_normals’ uses this and is probably more practical for actual usage!

mpacts.geometrygenerators.trianglegeometries.resolve_surrounding_normals_front(front_list, id_list, c, triangles, rec=True)

Given a list of triangles (front) which is deemed ‘ok’, it will flip all the surrounding triangles normals in such a way that all normals are consistent. This is done recursively until the complete mesh is resolved.

mpacts.geometrygenerators.trianglegeometries.test_inertia()
mpacts.geometrygenerators.trianglegeometries.test_tim()