Procedural Generation
Procedural shapes
PointCloud(data=None)
Bases: Mesh
A data structure for representing point clouds
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
__str__ |
str
|
Representation of the object and its elements as a string. |
id_vertices
property
Shortcut for range(len(self.vertices))
append(x)
Shortcut for self.vertices.append(x)
, since we can only append elements in the 'vertices' container
PolyLine(data=None)
Bases: Mesh
A data structure for representing polylines.
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
edges |
DataContainer
|
the container for all edges |
__str__ |
Representation of the object and its elements as a string. |
id_edges
property
Shortcut for range(len(self.edges))
id_vertices
property
Shortcut for range(len(self.vertices))
SurfaceMesh(data=None)
Bases: Mesh
A data structure for representing polygonal surfaces.
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
edges |
DataContainer
|
the container for all edges |
faces |
DataContainer
|
the container for all faces |
face_corners |
DataContainer
|
the container for all corner of faces |
boundary_edges |
list
|
list of all edge indices on the boundary |
interior_edges |
list
|
list of all interior edge indices (all edges \ boundary_edges) |
boundary_vertices |
list
|
list of all vertex indices on the boundary |
interior_vertices |
list
|
list of all interior verticex indices (all vertices \ boundary_vertices) |
connectivity |
_SurfaceConnectivity
|
the connectivity utility class |
id_corners
property
Shortcut for range(len(self.face_corners))
id_edges
property
Shortcut for range(len(self.edges))
id_faces
property
Shortcut for range(len(self.faces))
id_vertices
property
Shortcut for range(len(self.vertices))
clear_boundary_data()
Clear all boundary data. Next call to a boundary/interior container or method will recompute everything
is_edge_on_border(u, v)
whether edge (u,v) is a boundary edge or not
Parameters:
Name | Type | Description | Default |
---|---|---|---|
u |
int
|
vertex id |
required |
v |
int
|
vertex id |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether edge (u,v) is a boundary edge or not. Returns False if (u,v) is not a valid edge. |
is_quad()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is quadrangular (all faces are quad) |
is_triangular()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is triangular (all faces are triangles) |
is_vertex_on_border(u)
whether vertex u
is a boundary vertex or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
u |
int
|
vertex id |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether vertex |
ith_vertex_of_face(fid, i)
helper function to get the i-th vertex of a face, i.e. self.faces[fid][i]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fid |
int
|
face id |
required |
i |
int
|
vertex id in face. Should be 0 <= vid < len(face) |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
the id of the i-th vertex in face |
pt_of_face(fid)
point coordinates of vertices of face fid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fid |
int
|
face id |
required |
Returns:
Name | Type | Description |
---|---|---|
Iterable |
iterator of Vec objects representing point coordinates of vertices |
VolumeMesh(data=None)
Bases: Mesh
id_cells
property
Shortcut for range(len(self.cells))
id_corners
property
Shortcut for range(len(self.face_corners))
id_edges
property
Shortcut for range(len(self.edges))
id_faces
property
Shortcut for range(len(self.faces))
id_vertices
property
Shortcut for range(len(self.vertices))
is_edge_on_border(*args)
Simple test to determine if a given edge is on the boundary of the mesh.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if the given edge is on the boundary of the mesh. |
is_face_on_border(*args)
Simple test to determine if a given face is on the boundary of the mesh.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True is the given face exists and is on the boundary of the mesh |
is_tetrahedral()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is tetrahedral (all cells are tetrahedra) |
quad(P0, P1, P2, triangulate=False)
Generates a quad from three vertices
P1------- / / / / P0-------P2
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P0,P1,P2 |
Vec
|
coordinates of corners. The fourth point is deduced as P2 + P1 - 2*P0 |
required |
triangulate |
bool
|
whether to output two triangles instead of a quad. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
a quad |
triangle(P0, P1, P2)
Generates a triangle from three vertices
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P0,P1,P2 |
Vec
|
three points |
required |
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
a triangle |
ring(N, defect, open=False, n_cover=1)
Computes a ring of triangles with prescribed number of triangles and angle defect at the center.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N |
int
|
number of triangles in the ring |
required |
defect |
float
|
target angle defect to achieve. Position of the central point is adjusted via dichotomy to match this value. |
required |
open |
bool)
|
whether to connect the last vertex to the first. |
False
|
n_cover |
int
|
Number of covering of the ring. Defaults to 1. |
1
|
Raises:
Type | Description |
---|---|
Exception
|
Fails if N<3 |
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
the ring |
AABB(p_min, p_max)
Axis Aligned Bounding Box in n dimensions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p_min |
Iterable
|
minimal values for each dimension |
required |
p_max |
Iterable
|
maximal values for each dimension |
required |
Raises:
Type | Description |
---|---|
Exception
|
fails if p_min and p_max have different sizes (inconsistent dimension) |
center: Vec
property
dim: int
property
Dimension of the axis-aligned bounding box
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
dimension |
maxi: Vec
property
Maximum coordinates of any point inside the box. The box is an axis-aligned hexahedron which opposite corners are mini and maxi
Returns:
Name | Type | Description |
---|---|---|
Vec |
Vec
|
maximum coordinates |
mini: Vec
property
Minimum coordinates of any point inside the box The box is an axis-aligned hexahedron which opposite corners are mini and maxi
Returns:
Name | Type | Description |
---|---|---|
Vec |
Vec
|
minimum coordinates |
span: Vec
property
contains_point(pt)
Point - bounding box intersection predicate. If the point is on the boundary of the box, the convention is as follows: inclusive if the point touches the min coordinates, exclusive for the max coordinates
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pt |
Vec
|
a query position |
required |
Raises:
Type | Description |
---|---|
IncompatibleDimensionError
|
fails if the point has a different dimension than the bounding box. |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether the point 'pt' is inside the bounding box. |
distance(pt, which='l2')
Computes the distance from a point to the bounding box.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pt |
Vec
|
coordinates of the point |
required |
which |
str
|
which distance to consider. Choices are 'l2', 'l1' or 'linf'. Defaults to "l2". |
'l2'
|
Raises:
Type | Description |
---|---|
IncompatibleDimensionError
|
fails if the point has a different dimension than the bounding box. |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the distance from the point to the bounding box |
do_intersect(b1, b2)
staticmethod
Intersection test between two bounding boxes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b1 |
AABB
|
first bounding box |
required |
b2 |
AABB
|
second bounding box |
required |
Raises:
Type | Description |
---|---|
IncompatibleDimensionError
|
fails if b1 and b2 have different dimensions |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether the two BB intersect |
infinite(dim)
classmethod
Computes a bounding box with bounds at infinity, containing the whole space R^n
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dim |
int
|
dimension of the BB to build |
required |
Returns:
Name | Type | Description |
---|---|---|
AABB |
AABB
|
A bounding box containing all of R^n |
intersection(b1, b2)
staticmethod
Computes the intersection bounding box of two bounding boxes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b1 |
AABB
|
first bounding box |
required |
b2 |
AABB
|
second bounding box |
required |
Raises:
Type | Description |
---|---|
IncompatibleDimensionError
|
fails if b1 and b2 have different dimensions |
Returns:
Name | Type | Description |
---|---|---|
AABB |
AABB
|
a bounding box representing the intersection (may be empty). |
is_empty()
Tests if the bounding box encloses an empty domain
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether the bounding box is empty |
of_mesh(mesh, padding=0.0)
classmethod
Computes the 3D bounding box of all vertices of a mesh
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mesh |
Mesh
|
input mesh. Can be of any type (only the 'vertices' container is accessed) |
required |
padding |
float
|
slack to be added between the mesh and the box. Defaults to 0 for a tight bounding box. |
0.0
|
Returns:
Name | Type | Description |
---|---|---|
AABB |
AABB
|
3D bounding box of the vertices of the mesh |
of_points(points, padding=0.0)
classmethod
Computes the bounding box of a set of nD points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points |
ndarray
|
input points |
required |
padding |
float
|
slack to be added between the mesh and the box. Defaults to 0 for a tight bounding box. |
0.0
|
Returns:
Name | Type | Description |
---|---|---|
AABB |
AABB
|
nD bounding box of the points |
pad(pad)
Enlarges the bounding box by adding pad
on each dimension on each side. Does nothing if the padding values are negative.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pad |
float | iterable
|
Additional dimensions to be added. If a float is provided, will assume that padding is the same for each dimensions. If an array is provided, its size should match the dimension of the box. Values are clamped to be >=0. |
required |
project(pt)
Computes the closest point from point 'pt' in the bounding box in Euclidean distance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pt |
Vec
|
the point to project |
required |
Raises:
Type | Description |
---|---|
IncompatibleDimensionError
|
fails if the point has a different dimension than the bounding box. |
Returns:
Name | Type | Description |
---|---|---|
Vec |
Vec
|
the projected point |
union(b1, b2)
staticmethod
Computes the union bounding box of two bounding boxes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b1 |
AABB
|
first bounding box |
required |
b2 |
AABB
|
second bounding box |
required |
Raises:
Type | Description |
---|---|
IncompatibleDimensionError
|
fails if b1 and b2 have different dimensions |
Returns:
Name | Type | Description |
---|---|---|
AABB |
AABB
|
a bounding box representing the union |
unit_cube(dim, centered=False)
classmethod
Computes the unit bounding box [0,1]^n or [-0.5, 0.5]^n
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dim |
int
|
dimension of the BB to build |
required |
centered |
bool
|
whether to generate [0,1]^n (False) or [-0.5;0.5]^n (True). Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
AABB |
AABB
|
a hypercube of side length 1 |
PointCloud(data=None)
Bases: Mesh
A data structure for representing point clouds
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
__str__ |
str
|
Representation of the object and its elements as a string. |
id_vertices
property
Shortcut for range(len(self.vertices))
append(x)
Shortcut for self.vertices.append(x)
, since we can only append elements in the 'vertices' container
PolyLine(data=None)
Bases: Mesh
A data structure for representing polylines.
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
edges |
DataContainer
|
the container for all edges |
__str__ |
Representation of the object and its elements as a string. |
id_edges
property
Shortcut for range(len(self.edges))
id_vertices
property
Shortcut for range(len(self.vertices))
SurfaceMesh(data=None)
Bases: Mesh
A data structure for representing polygonal surfaces.
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
edges |
DataContainer
|
the container for all edges |
faces |
DataContainer
|
the container for all faces |
face_corners |
DataContainer
|
the container for all corner of faces |
boundary_edges |
list
|
list of all edge indices on the boundary |
interior_edges |
list
|
list of all interior edge indices (all edges \ boundary_edges) |
boundary_vertices |
list
|
list of all vertex indices on the boundary |
interior_vertices |
list
|
list of all interior verticex indices (all vertices \ boundary_vertices) |
connectivity |
_SurfaceConnectivity
|
the connectivity utility class |
id_corners
property
Shortcut for range(len(self.face_corners))
id_edges
property
Shortcut for range(len(self.edges))
id_faces
property
Shortcut for range(len(self.faces))
id_vertices
property
Shortcut for range(len(self.vertices))
clear_boundary_data()
Clear all boundary data. Next call to a boundary/interior container or method will recompute everything
is_edge_on_border(u, v)
whether edge (u,v) is a boundary edge or not
Parameters:
Name | Type | Description | Default |
---|---|---|---|
u |
int
|
vertex id |
required |
v |
int
|
vertex id |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether edge (u,v) is a boundary edge or not. Returns False if (u,v) is not a valid edge. |
is_quad()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is quadrangular (all faces are quad) |
is_triangular()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is triangular (all faces are triangles) |
is_vertex_on_border(u)
whether vertex u
is a boundary vertex or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
u |
int
|
vertex id |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether vertex |
ith_vertex_of_face(fid, i)
helper function to get the i-th vertex of a face, i.e. self.faces[fid][i]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fid |
int
|
face id |
required |
i |
int
|
vertex id in face. Should be 0 <= vid < len(face) |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
the id of the i-th vertex in face |
pt_of_face(fid)
point coordinates of vertices of face fid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fid |
int
|
face id |
required |
Returns:
Name | Type | Description |
---|---|---|
Iterable |
iterator of Vec objects representing point coordinates of vertices |
Vec
Bases: ndarray
A simple class to manipulate vectors in mouette. Basically, it inherits from a numpy array and implements some quality of life features for 2D and 3D vectors especially.
x: float
property
writable
First coordinate of the vector
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
|
xy
property
First two coordinates of the vector
Returns:
Name | Type | Description |
---|---|---|
float |
|
y
property
writable
Second coordinate of the vector
Returns:
Name | Type | Description |
---|---|---|
float |
|
z
property
writable
Third coordinate of the vector
Returns:
Name | Type | Description |
---|---|---|
float |
|
X()
classmethod
The [1,0,0] vector
Returns:
Name | Type | Description |
---|---|---|
Vec |
[1,0,0] |
Y()
classmethod
The [0,1,0] vector
Returns:
Name | Type | Description |
---|---|---|
Vec |
[0,1,0] |
Z()
classmethod
The [0,0,1] vector
Returns:
Name | Type | Description |
---|---|---|
Vec |
[0,0,1] |
dot(other)
Dot product between two vectors:
$ a \cdot b = \sum_i a[i]b[i]$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Vec
|
other vector to dot with |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the dot product |
from_complex(c)
classmethod
2D vector from complex number
Parameters:
Name | Type | Description | Default |
---|---|---|---|
c |
complex
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
Vec |
|
norm(which='l2')
Vector norm. Three norms are implemented: the Euclidean l2 norm, the l1 norm or the l-infinite norm:
l2 : $ \sqrt{ \sum_i v[i]^2 } $
l1 : $ \sum_i |v[i]| $
linf : $ \max_i |v[i]| $
Parameters:
Name | Type | Description | Default |
---|---|---|---|
which |
str
|
which norm to compute. Choices are "l2", "l1" and "linf". Defaults to "l2". |
'l2'
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the vector's norm |
normalize(which='l2')
Normalizes the vector to have unit norm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
which |
str
|
which norm to compute. Choices are "l2", "l1" and "linf". Defaults to "l2". |
'l2'
|
normalized(vec, which='l2')
staticmethod
Computes and returns a normalized vector of the input vector vec
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vec |
Vec
|
the input vector |
required |
which |
str
|
which norm to compute. Choices are "l2", "l1" and "linf". Defaults to "l2". |
'l2'
|
Returns:
Name | Type | Description |
---|---|---|
Vec |
the normalized vector |
outer(other)
Outer product between two vectors:
\(a \otimes b = c \in \mathbb{R}^{n \times n}\) such that \(c[i,j] = a[i]b[j]\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Vec
|
the second vector |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.array: an array of shape (n,n) |
random(n)
classmethod
Generates a random vector of size n
with coefficients sampled uniformly and independently in [0;1)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
size |
required |
Returns:
Name | Type | Description |
---|---|---|
Vec |
|
zeros(n)
classmethod
Generates a vector of size n
full of zeros.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
size |
required |
Returns:
Name | Type | Description |
---|---|---|
Vec |
|
VolumeMesh(data=None)
Bases: Mesh
id_cells
property
Shortcut for range(len(self.cells))
id_corners
property
Shortcut for range(len(self.face_corners))
id_edges
property
Shortcut for range(len(self.edges))
id_faces
property
Shortcut for range(len(self.faces))
id_vertices
property
Shortcut for range(len(self.vertices))
is_edge_on_border(*args)
Simple test to determine if a given edge is on the boundary of the mesh.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if the given edge is on the boundary of the mesh. |
is_face_on_border(*args)
Simple test to determine if a given face is on the boundary of the mesh.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True is the given face exists and is on the boundary of the mesh |
is_tetrahedral()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is tetrahedral (all cells are tetrahedra) |
angle_2vec2D(V1, V2)
angle_2vec3D(V1, V2)
angle_3pts(A, B, C)
aspect_ratio(A, B, C)
Computes the aspect ratio of triangle ABC, defined as the ratio between the circumradius to twice the inradius. This ratio equals 1 for equilateral triangle and goes to zero as the triangle gets close to degenerate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A |
Vec
|
first point of the triangle |
required |
B |
Vec
|
second point of the triangle |
required |
C |
Vec
|
third point of the triangle |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the aspect ratio of triangle ABC |
axis_aligned_cube(colored=False, triangulate=False)
generated an axis aligned cube as 6 quad faces.
7--------6 /| /| / | / | 4--------5 | | | | | | 3-----|--2 | / | / |/ |/ 0--------1
Parameters:
Name | Type | Description | Default |
---|---|---|---|
colored |
bool
|
if set to true, will add a colo rattribute on faces to determine. Defaults to False. |
False
|
triangulate |
bool
|
if set to true, will triangulate the faces. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a cube |
axis_rot_from_z(v)
The (smallest) rotation to align the z axis (0,0,1) with the vector v
check_argument(argname, argvalue, expected_type, expected_values=None)
check input sanity on the argument of a function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
argname |
str
|
Name of the argument (for exhaustivity of error message) |
required |
argvalue |
any
|
value of the argument |
required |
expected_type |
type
|
expected type of the argument. If type(argvalue) does not match, will raise an InvalidArgumentTypeError |
required |
expected_values |
list
|
List of possible values the argument is allowed to take. If argvalue is not in the list, will raise an InvalidArgumentValueError. Defaults to None. |
None
|
circumcenter(v1, v2, v3)
Circumcenter of the triangle formed by three points in space
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v1 |
Vec
|
first point |
required |
v2 |
Vec
|
second point |
required |
v3 |
Vec
|
third point |
required |
Warning
Circumcenter of triangle (v1,v2,v3) may not lay inside the triangle
Returns:
Name | Type | Description |
---|---|---|
Vec |
Vec
|
coordinates of the circumcenter |
cotan(A, B, C)
cotangent of the angle \(\hat{ABC}\) Parameters: A (Vec): point A B (Vec): point B C (Vec): point C
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the cotangent |
cross(A, B)
cylinder(P1, P2, radius=1.0, N=50, fill_caps=True)
Generates a cylinder around the segment defined by P1 and P2
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P1 |
Vec
|
start of the cylinder (center of bottom face) |
required |
P2 |
Vec
|
end of the cylinder (center of top face) |
required |
radius |
float
|
radius. Defaults to 1.. |
1.0
|
N |
int
|
number of segments. Defaults to 50. |
50
|
fill_caps |
bool
|
whether to also generate faces at caps. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a cylinder |
det_2x2(A, B)
Computes a 2x2 determinant
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A |
Union[complex, ndarray]
|
first column vector. Can also be a complex number |
required |
B |
Union[complex, ndarray]
|
second column vector. Can also be a complex number |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the determinant |
det_3x3(*args)
Computes a 3x3 using the rule of Sarrus
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
Either a 3x3 numpy array representing a matrix, or 3 3x1 numpy array representing three column vectors |
()
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the determinant |
distance(A, B, which='l2')
Distance between A and B. Three distances are implemented, the Euclidean distance l2, the Manhattan l1 distance of the l-infinity distance:
l2: \(\sqrt{(B-A)^T(B-A)} = \sqrt{\sum_i (A_i - B_i)^2}\)
l1: \(\sum_i |A_i - B_i|\)
linf: \(\max_i |A_i - B_i|\)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A |
Vec
|
first point |
required |
B |
Vec
|
second point |
required |
which |
str
|
which norm to compute. Choices are "l2", "l1" and "linf". Defaults to "l2". |
'l2'
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
distance |
distance_to_segment2D(P, A, B)
Computes, in the plane, the distance of point P to the segment [A;B]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P |
Vec
|
Query point in 2D |
required |
A |
Vec
|
First segment extremity |
required |
B |
Vec
|
Second segment extremity |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the euclidean distance from P to [A;B] |
dodecahedron()
Generate a unit dodecahedron as the dual mesh of an icosahedron
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a dodecahedron |
dot(A, B)
dot product \(A^TB\) between two vectors
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A |
ndarray
|
first vector |
required |
B |
ndarray
|
second vector |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
dot product |
face_basis(*f)
Orthonormal basis of face Given three points A,B,C, returns a basis such that the first vector is along direction AB and third vector is normal to the plane ABC
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A,B,C |
three points (in a list or not) |
required |
Returns:
Type | Description |
---|---|
Vec,Vec,Vec: an orthonormal 3D basis of the face |
hexahedron(P1, P2, P3, P4, P5, P6, P7, P8, colored=False, triangulate=False, volume=False)
Generate an hexahedron in arbitrary configuration given 8 points. Order and connectivity of points is:
7--------6 /| /| / | / | 4--------5 | | | | | | 3-----|--2 | / | / |/ |/ 0--------1
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P1 |
to P8 (Vec
|
coordinates of eight vertices |
required |
colored |
bool
|
if set to true, will add a color attribute on faces. Defaults to False. |
False
|
triangulate |
bool
|
if set to true, will triangulate the faces. Defaults to False. |
False
|
volume |
bool
|
if set to true, will also generate three tetrahedra to fill the volume. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a cube |
hexahedron_4pts(P1, P2, P3, P4, colored=False, volume=False)
Generate an hexahedron given by an absolute position and three points building a basis.
4 | | 3 | / |/ 1--------2
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P1 |
to P4 (Vec
|
coordinates of vertices |
required |
colored |
bool
|
if set to true, will add a color attribute on faces to determine. Defaults to False. |
False
|
volume |
bool
|
if set to true, will also generate three tetrahedra to fill the volume. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
[description] |
icosahedron(center=Vec(0, 0, 0), radius=1.0, uv=False)
icosphere(n_refine=3, center=Vec(0.0, 0.0, 0.0), radius=1.0)
Generates an icosphere, that is a subdivision of the icosahedron
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_refine |
int
|
number of subdivisions. Defaults to 3. |
3
|
center |
Vec
|
center of the sphere. Defaults to Vec(0.,0.,0.). |
Vec(0.0, 0.0, 0.0)
|
radius |
float
|
radius of the sphere. Defaults to 1.. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
description |
intersect_2lines2D(p1, d1, p2, d2)
Computes the intersection of two lines in the plane
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p1 |
Vec
|
point on the first line |
required |
d1 |
Vec
|
direction vector of the first line |
required |
p2 |
Vec
|
point on the second line |
required |
d2 |
Vec
|
direction vector of the second line |
required |
Returns:
Name | Type | Description |
---|---|---|
Vec |
Vec
|
the intersection point. None if lines are parallel |
match_rotation(Ra, Rb, symgroup=Rotation.create_group('O'), threshold=math.pi / 4)
Given two rotation matrices, compute the matching between the two: the minimal rotation going from Ra to s(Rb) with s in some symmetry group (most often the octahedral group for cube symmetries)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symgroup |
Rotation)
|
a rotation group (given by the |
create_group('O')
|
Returns:
Name | Type | Description |
---|---|---|
Rotation |
the minimal rotation going from Ra to Rb |
norm(x, which='l2')
Vector norm. Three norms are implemented, the Euclidean l2 norm, the l1 norm or the l-infinite norm:
l2: $ \sqrt{ \sum_i v[i]^2 } $
l1: $ \sum_i |v[i]| $
linf: $ \max_i |v[i]| $
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray
|
vector from which we compute the norm. Will be flattened if it has more than one dimension. |
required |
which |
str
|
which norm to compute. Choices are "l2", "l1" and "linf". Defaults to "l2". |
'l2'
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the vector's norm |
octahedron()
Generate a unit octahedron as the dual mesh of the unit hexahedron
Reference
https://danielsieger.com/blog/2021/01/03/generating-platonic-solids.html
project_to_plane(P, N, orig)
quad_area(A, B, C, D)
rotate_2d(v, angle)
sign(x)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
float
|
input number |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
x/|x| and 0 for x=0 |
sign0(x)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
float
|
input number |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
the sign of x |
signed_angle_2vec3D(V1, V2, N)
signed_angle_3pts(A, B, C, N)
sphere_fibonacci(n_pts, radius=1.0, build_surface=True)
Generates a point cloud or a surface mesh using fibonacci sampling of a sphere.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_pts |
int
|
total number of vertices |
required |
radius |
float
|
Radius of the sphere. Defaults to 1. |
1.0
|
build_surface |
bool
|
If specified to True, the function will also compute a triangulation of the vertices. This is obtained through a convex hull algorithm (since points lay on a convex shape, the convex hull and the Delaunay triangulation are equivalent). Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
SurfaceMesh
|
[SurfaceMesh | PointCloud]: the generated mesh |
sphere_uv(n_lat, n_long, center=Vec(0.0, 0.0, 0.0), radius=1.0)
Generates a sphere using classical spherical uv-coordinates
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_lat |
int
|
number of different latitudes for points |
required |
n_long |
int
|
number of different longitudes for points |
required |
center |
Vec
|
Center position of the sphere. Defaults to Vec(0.,0.,0.). |
Vec(0.0, 0.0, 0.0)
|
radius |
float
|
Radius of the sphere. Defaults to 1. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
the sphere |
tetrahedron(P1, P2, P3, P4, volume=False)
Simple tetrahedron from four points
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P1 |
Vec
|
first point |
required |
P2 |
Vec
|
second point |
required |
P3 |
Vec
|
third point |
required |
P4 |
Vec
|
fourth point |
required |
volume |
bool
|
whether to generate a cell or just a surface. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
description |
torus(major_segments, minor_segments, major_radius, minor_radius, triangulate=False)
Generates a torus From https://danielsieger.com/blog/2021/05/03/generating-primitive-shapes.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
major_segments |
int
|
number of major segments |
required |
minor_segments |
int
|
number of minor segments |
required |
major_radius |
float
|
global radius of the torus |
required |
minor_radius |
float
|
thickness of the torus |
required |
triangulate |
bool
|
whether to output a triangular or quadmesh. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a torus |
triangle_area(A, B, C)
Transformations
PointCloud(data=None)
Bases: Mesh
A data structure for representing point clouds
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
__str__ |
str
|
Representation of the object and its elements as a string. |
id_vertices
property
Shortcut for range(len(self.vertices))
append(x)
Shortcut for self.vertices.append(x)
, since we can only append elements in the 'vertices' container
PolyLine(data=None)
Bases: Mesh
A data structure for representing polylines.
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
edges |
DataContainer
|
the container for all edges |
__str__ |
Representation of the object and its elements as a string. |
id_edges
property
Shortcut for range(len(self.edges))
id_vertices
property
Shortcut for range(len(self.vertices))
SurfaceMesh(data=None)
Bases: Mesh
A data structure for representing polygonal surfaces.
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
edges |
DataContainer
|
the container for all edges |
faces |
DataContainer
|
the container for all faces |
face_corners |
DataContainer
|
the container for all corner of faces |
boundary_edges |
list
|
list of all edge indices on the boundary |
interior_edges |
list
|
list of all interior edge indices (all edges \ boundary_edges) |
boundary_vertices |
list
|
list of all vertex indices on the boundary |
interior_vertices |
list
|
list of all interior verticex indices (all vertices \ boundary_vertices) |
connectivity |
_SurfaceConnectivity
|
the connectivity utility class |
id_corners
property
Shortcut for range(len(self.face_corners))
id_edges
property
Shortcut for range(len(self.edges))
id_faces
property
Shortcut for range(len(self.faces))
id_vertices
property
Shortcut for range(len(self.vertices))
clear_boundary_data()
Clear all boundary data. Next call to a boundary/interior container or method will recompute everything
is_edge_on_border(u, v)
whether edge (u,v) is a boundary edge or not
Parameters:
Name | Type | Description | Default |
---|---|---|---|
u |
int
|
vertex id |
required |
v |
int
|
vertex id |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether edge (u,v) is a boundary edge or not. Returns False if (u,v) is not a valid edge. |
is_quad()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is quadrangular (all faces are quad) |
is_triangular()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is triangular (all faces are triangles) |
is_vertex_on_border(u)
whether vertex u
is a boundary vertex or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
u |
int
|
vertex id |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether vertex |
ith_vertex_of_face(fid, i)
helper function to get the i-th vertex of a face, i.e. self.faces[fid][i]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fid |
int
|
face id |
required |
i |
int
|
vertex id in face. Should be 0 <= vid < len(face) |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
the id of the i-th vertex in face |
pt_of_face(fid)
point coordinates of vertices of face fid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fid |
int
|
face id |
required |
Returns:
Name | Type | Description |
---|---|---|
Iterable |
iterator of Vec objects representing point coordinates of vertices |
VolumeMesh(data=None)
Bases: Mesh
id_cells
property
Shortcut for range(len(self.cells))
id_corners
property
Shortcut for range(len(self.face_corners))
id_edges
property
Shortcut for range(len(self.edges))
id_faces
property
Shortcut for range(len(self.faces))
id_vertices
property
Shortcut for range(len(self.vertices))
is_edge_on_border(*args)
Simple test to determine if a given edge is on the boundary of the mesh.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if the given edge is on the boundary of the mesh. |
is_face_on_border(*args)
Simple test to determine if a given face is on the boundary of the mesh.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True is the given face exists and is on the boundary of the mesh |
is_tetrahedral()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is tetrahedral (all cells are tetrahedra) |
cylindrify_edges(mesh, radius=0.05, N=50)
Transforms edges of a polyline as cylinder surface
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mesh |
PolyLine
|
the input mesh |
required |
radius |
float
|
Radius of the output cylinders. Defaults to 5e-2. |
0.05
|
N |
int
|
Number of points inside each circle of the cylinders. Defaults to 50. |
50
|
Returns:
Type | Description |
---|---|
SurfaceMesh
|
SurfaceMesh |
spherify_vertices(points, radius=0.01, n_subdiv=1)
Transforms vertices of a point cloud as icospheres
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points |
PointCloud
|
the input point cloud |
required |
radius |
float
|
radius of each sphere. Defaults to 1e-2. |
0.01
|
n_subdiv |
int
|
number of subdivisions of the icospheres. Defaults to 1. |
1
|
Returns:
Type | Description |
---|---|
SurfaceMesh
|
SurfaceMesh |
PointCloud(data=None)
Bases: Mesh
A data structure for representing point clouds
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
__str__ |
str
|
Representation of the object and its elements as a string. |
id_vertices
property
Shortcut for range(len(self.vertices))
append(x)
Shortcut for self.vertices.append(x)
, since we can only append elements in the 'vertices' container
PolyLine(data=None)
Bases: Mesh
A data structure for representing polylines.
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
edges |
DataContainer
|
the container for all edges |
__str__ |
Representation of the object and its elements as a string. |
id_edges
property
Shortcut for range(len(self.edges))
id_vertices
property
Shortcut for range(len(self.vertices))
SurfaceMesh(data=None)
Bases: Mesh
A data structure for representing polygonal surfaces.
Attributes:
Name | Type | Description |
---|---|---|
vertices |
DataContainer
|
the container for all vertices |
edges |
DataContainer
|
the container for all edges |
faces |
DataContainer
|
the container for all faces |
face_corners |
DataContainer
|
the container for all corner of faces |
boundary_edges |
list
|
list of all edge indices on the boundary |
interior_edges |
list
|
list of all interior edge indices (all edges \ boundary_edges) |
boundary_vertices |
list
|
list of all vertex indices on the boundary |
interior_vertices |
list
|
list of all interior verticex indices (all vertices \ boundary_vertices) |
connectivity |
_SurfaceConnectivity
|
the connectivity utility class |
id_corners
property
Shortcut for range(len(self.face_corners))
id_edges
property
Shortcut for range(len(self.edges))
id_faces
property
Shortcut for range(len(self.faces))
id_vertices
property
Shortcut for range(len(self.vertices))
clear_boundary_data()
Clear all boundary data. Next call to a boundary/interior container or method will recompute everything
is_edge_on_border(u, v)
whether edge (u,v) is a boundary edge or not
Parameters:
Name | Type | Description | Default |
---|---|---|---|
u |
int
|
vertex id |
required |
v |
int
|
vertex id |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether edge (u,v) is a boundary edge or not. Returns False if (u,v) is not a valid edge. |
is_quad()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is quadrangular (all faces are quad) |
is_triangular()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is triangular (all faces are triangles) |
is_vertex_on_border(u)
whether vertex u
is a boundary vertex or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
u |
int
|
vertex id |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether vertex |
ith_vertex_of_face(fid, i)
helper function to get the i-th vertex of a face, i.e. self.faces[fid][i]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fid |
int
|
face id |
required |
i |
int
|
vertex id in face. Should be 0 <= vid < len(face) |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
the id of the i-th vertex in face |
pt_of_face(fid)
point coordinates of vertices of face fid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fid |
int
|
face id |
required |
Returns:
Name | Type | Description |
---|---|---|
Iterable |
iterator of Vec objects representing point coordinates of vertices |
VolumeMesh(data=None)
Bases: Mesh
id_cells
property
Shortcut for range(len(self.cells))
id_corners
property
Shortcut for range(len(self.face_corners))
id_edges
property
Shortcut for range(len(self.edges))
id_faces
property
Shortcut for range(len(self.faces))
id_vertices
property
Shortcut for range(len(self.vertices))
is_edge_on_border(*args)
Simple test to determine if a given edge is on the boundary of the mesh.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if the given edge is on the boundary of the mesh. |
is_face_on_border(*args)
Simple test to determine if a given face is on the boundary of the mesh.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True is the given face exists and is on the boundary of the mesh |
is_tetrahedral()
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the mesh is tetrahedral (all cells are tetrahedra) |
dual_mesh(mesh)
Computes the dual mesh of a mesh
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mesh |
SurfaceMesh
|
input surface |
required |
Returns:
Type | Description |
---|---|
SurfaceMesh
|
SurfaceMesh |