Shapes#

volmdlr shapes module.

class volmdlr.shapes.CompSolid(obj: TopoDS_Shape, reference_path: str = '#', name: str = '')#

Bases: Shape

A single compsolid.

class volmdlr.shapes.Compound(obj: TopoDS_Shape, reference_path: str = '#', name: str = '')#

Bases: Shape

A collection of disconnected solids.

babylon_data(merge_meshes: bool = True, show_curves: bool = False, ocaf=None)#

Get babylonjs data.

Returns:

Dictionary with babylon data.

static get_babylon_data(shape, merge_meshes=True, show_curves: bool = False, ocaf=None)#

Get babylonjs data.

Returns:

Dictionary with babylon data.

classmethod make_compound(list_of_shapes: Iterable[Shape], name: str = '') Compound#

Create a compound out of a list of shapes.

remove(shape: Shape)#

Remove the specified shape.

class volmdlr.shapes.Edge(obj: TopoDS_Shape, reference_path: str = '#', name: str = '')#

Bases: Shape

OCP Edge wrapped.

babylon_curves()#

Gets babylonjs curves.

babylon_lines(points=None)#

Returns the wire data in babylon format.

babylon_points()#

Returns a list of discretization points from the 3D primitive.

class volmdlr.shapes.Face(obj: TopoDS_Shape, reference_path: str = '#', name: str = '')#

Bases: Shape

OCP face wrapped.

center() tuple#

Returns tuple representing the face’s center.

Deprecated since version Use: center_of_mass() instead. This method will be removed in a future version.

center_of_mass() Point3D#

Returns tuple representing the face’s center.

class volmdlr.shapes.Location(translation: Vector3D | tuple[float, float, float] | ndarray[Any, dtype[_ScalarType_co]] = (0.0, 0.0, 0.0), quaternion: tuple[float, float, float, float] = (0.0, 0.0, 0.0, 1.0), name: str = '', wrapped: TopLoc_Location | None = None)#

Bases: DessiaObject

Represents a 3D location expressed as a rigid transformation (translation + rotation).

copy(deep: bool = True, memo: dict | None = None) Location#

Create a copy of this Location.

Parameters:
  • deep – If True, perform a deep copy of the underlying Location.

  • memo – A dict mapping already copied objects to their clones.

Returns:

New Location instance.

classmethod from_frame(frame: Frame3D) Location#

Create a Location instance given a frame.

classmethod identity() Location#

Create an identity Location (no transformation).

Returns:

Location with identity transformation.

property matrix: list[list[float]]#

The 4x4 homogeneous transformation matrix of this Location.

Returns:

A 4x4 list of floats in row-major order.

property matrix_column_major: list[float]#

The 4x4 homogeneous transformation matrix in column-major order.

This format is used by WebGL and Babylon.js for GPU transformations.

Returns:

Flat list of 16 floats in column-major order.

multiplied(other: Location | gp_Trsf) Location#

Return a new Location by combining with another transformation.

Computes self * other (applies self first, then other).

Parameters:

other – Location or gp_Trsf to combine with this Location.

Returns:

New Location representing self * other.

property quaternion: tuple[float, float, float, float]#

The rotational component (as quaternion) of this Location.

Returns:

A tuple (x, y, z, w) of floats representing the quaternion.

rotation(center: Point3D, axis: Vector3D, angle: float) Location#

Apply a rotation to this location.

Parameters:
  • center – Point3D defining the rotation center.

  • axis – Vector3D defining the axis direction.

  • angle – Rotation angle in radians.

Returns:

A new Location instance.

to_dict(use_pointers: bool = True, memo: dict[Any, Any] | None = None, path: str = '#', id_method: bool = True, id_memo: dict[Any, Any] | None = None, **kwargs: Any) Dict[str, Any]#

Serialize this Location to a JSON-compatible dictionary.

Includes translation and quaternion.

Parameters:
  • use_pointers – Whether to include pointer references.

  • memo – Memoization dict for serialization.

  • path – Path identifier in the serialization tree.

  • id_method – Whether to include method-based IDs.

  • id_memo – Memo dict for IDs.

  • kwargs – Additional keyword arguments.

Returns:

A JSON-serializable dict.

to_frame() Frame3D#

Return the local frame equivalent to applying the transformation of this location to the global system.

translation(offset: Vector3D) Location#

Apply a translation to this location.

Parameters:

offset – Vector3D defining the direction and translation distance.

Returns:

A new Location instance.

property translation_part: tuple[float, float, float]#

The translational component of this Location.

Returns:

A tuple (x, y, z) of floats.

class volmdlr.shapes.Shape(obj: TopoDS_Shape, reference_path: str = '#', name: str = '')#

Bases: Primitive3D

Represents a shape in the system. Wraps TopoDS_Shape.

apply_transformation(location: Location) Shape#

Apply the given transformation to the shape.

area() float#

Calculates the area of a shape.

Returns:

The surface area of all faces in this Shape

babylon_meshes(merge_meshes: bool = True, ocaf=None, *args, **kwargs)#

Returns the babylonjs mesh.

property bounding_box: BoundingBox#

Gets bounding box for this shape.

classmethod cast(obj: TopoDS_Shape, name: str = '') Shape#

Returns the right type of wrapper, given a OCCT object.

center_of_mass() Point3D#

Return the center of mass of the shape.

copy(deep=True, memo=None)#

Copy of Shape.

Returns:

return a copy the Shape.

classmethod dict_to_object(dict_: Dict[str, Any], force_generic: bool = False, global_dict=None, pointers_memo: dict[str, Any] | None = None, path: str = '#') Shape#

Creates a Shape from a dictionary.

difference(*to_subtract: Shape, tol: float | None = None) Shape#

Perform boolean difference (cut) operation on this Shape.

Subtracts one or more shapes from this shape using OpenCASCADE’s BRepAlgoAPI_Cut algorithm.

Parameters:
  • to_subtract – Shape(s) to subtract from this shape.

  • tol – Fuzzy mode tolerance. Enables fuzzy operations for shapes with small gaps/overlaps.

Returns:

Resulting Shape object after difference operation.

distance(other: Shape) float#

Minimal distance between two shapes.

Parameters:

other – other shape to calculate distance with.

distance_points(other: Shape)#

Minimal distance points between two shapes.

Parameters:

other – other shape to calculate distance with.

edge_intersections(edge, tol: float | None = None)#

Gets intersections between edge and shape.

faces_line_intersections(line, tol: float = 0.0001)#

Computes the intersections between the provided line and the faces of this Shape.

Parameters:
  • line – line to verify intersections with.

  • tol – Intersection tolerance.

Returns:

A list of tuples (face, intersection point).

classmethod from_brep(file: str | BytesIO, name: str = '') Shape#

Import shape from a BREP file.

classmethod from_brep_stream(stream: BinaryFile, name: str = '') Shape#

Import shape from a BREP file stream.

intersection(*to_intersect: Shape, tol: float | None = None) Shape#

Perform boolean intersection (common) operation on this Shape.

Computes the intersection between this shape and one or more shapes using OpenCASCADE’s BRepAlgoAPI_Common algorithm.

Parameters:
  • to_intersect – Shape(s) to intersect with this shape.

  • tol – Fuzzy mode tolerance. Enables fuzzy operations for shapes with small gaps/overlaps.

Returns:

Resulting Shape object representing the common volume.

length()#

Gets the shape’s length.

loc()#

Returns shape’s TopLoc_Location.

location()#

Returns shape’s Location.

matrix_of_inertia() list[list[float]]#

Computes the matrix of inertia of the volume.

Returns:

A 3x3 matrix representing the inertia tensor of the volume.

Return type:

numpy.ndarray

mesh(relative_linear_deflection: float = 0.005, angular_deflection: float = 0.5, linear_deflection: float | None = None, **kwargs) None#

Mesh the wrapped OCP object with BRepMesh_IncrementalMesh method, if not already done with same parameters.

The meshing parameters are saved as attributes of the instance, so they can be serialized and deserialized.

Parameters:
  • relative_linear_deflection – Relative linear deflection for mesh generation, used to compute linear deflection based on bounding box size. Smaller values produce finer meshes.

  • angular_deflection – Angular deflection in radians. Smaller values, finer meshes.

  • linear_deflection – Linear deflection for mesh generation. If provided, it overrides the automatic calculation based on bounding box size.

property metadata#

Gets Shape metadata.

mirror(frame)#

Makes the transformation into a symmetrical transformation.

Frame is the center of the planar symmetry and defines the plane of symmetry by its origin, “X Direction” and “Y Direction”.

Parameters:

frame

Returns:

moment_of_inertia(axis_point: Point3D, axis: Vector3D) float#

Computes the moment of inertia around a specified axis.

Parameters:
  • axis_point – A point on the axis of rotation.

  • axis – The direction of the axis of rotation.

Returns:

The moment of inertia around the specified axis.

obb(use_triangulation: bool = True, optimal: bool = True)#

Gets oriented bounding box for this shape.

plot(ax=None, edge_style=None)#

Plots a shape using matplolib.

property primitives: list[Shape]#

Gets children shapes of a shape-like object.

Returns:

A list of Shape object that are the children of the current Shape object.

property root_shape: Shape#

Get the root shape.

rotation(center: Point3D, axis: Vector3D, angle: float, keep_reference: bool = True)#

Shape rotation.

Parameters:
  • center – rotation center

  • axis – rotation axis

  • angle – rotation angle in radians

  • keep_reference – If True (default), retains a reference to the original object. In an assembly, this means that changes to the base object (e.g., color or geometry) will be propagated to all instances of the shape (This is highly recommended for optimal memory efficiency) . If False, creates a new, independent shape with no links to the original object.

Returns:

a new rotated Shape

scale(factor: float, center: Point3D | None = None) Shape#

Scales shape through a transformation.

shape_type() str#

Returns shape type name.

split(*splitters: Shape, tol: float | None = None) Shape#

Split this shape with one or more splitter shapes.

Divides this shape using OpenCASCADE’s BRepAlgoAPI_Splitter algorithm.

Parameters:
  • splitters – Shape(s) to use for splitting this shape.

  • tol – Fuzzy mode tolerance. Enables fuzzy operations for shapes with small gaps/overlaps.

Returns:

Resulting Shape object after splitting.

subtraction(*to_subtract: Shape, tol: float | None = None) Shape#

Deprecated: Use difference() instead.

Deprecated since version 0.20.5: Use difference() instead. This method will be removed in v1.0.0.

tessellate(relative_linear_deflection: float = 0.005, angular_deflection: float = 0.5, merge_meshes=True, linear_deflection: float | None = None, include_metadata: bool = True, **kwargs) Mesh3D | list[Mesh3D]#

Tessellates the geometry into vertices and triangles.

Parameters:
  • relative_linear_deflection – Relative linear deflection for mesh generation, used to compute linear deflection based on bounding box size. Smaller values produce finer meshes.

  • angular_deflection – Angular deflection in radians. Smaller values, finer meshes.

  • merge_meshes – If true, all faces are merged into a single mesh; otherwise, each face has an associated mesh.

  • linear_deflection – Linear deflection for mesh generation. If provided, it overrides the automatic calculation based on bounding box size.

  • include_metadata – If True, include topology metadata (faces, edges) in the resulting Mesh3D. Default is True.

Returns:

A single Mesh3D object if merge_meshes is True, otherwise a list of Mesh3D objects for each face.

to_brep(file: str | BytesIO, write_mesh: bool = True) bool#

Export this shape to a BREP file.

to_brep_stream(write_mesh: bool = True) BytesIO#

Export shape from a BREP file stream.

to_dict(use_pointers: bool = True, memo=None, path: str = '#', id_method=True, id_memo=None, **kwargs) Dict[str, Any]#

Serializes a 3-dimensional Shape into a dictionary.

transformation(to_frame: Frame3D, from_frame: Frame3D = Frame3D(origin=Point3D(0.0, 0.0, 0.0), u=Vector3D(1.0, 0.0, 0.0), v=Vector3D(0.0, 1.0, 0.0), w=Vector3D(0.0, 0.0, 1.0)))#

Frame maps a shape from a frame1 to a frame 2.

Parameters:
  • from_frame – the origin frame to frame map from. defaults to OXYZ.

  • to_frame – the destiny frame to frame map to.

translation(offset: Vector3D, keep_reference: bool = True)#

Translate the shape by a given vector.

Parameters:
  • offset – The vector by which to translate the shape.

  • keep_reference – If True (default), retains a reference to the original object. In an assembly, this means that changes to the base object (e.g., color or geometry) will be propagated to all instances of the shape (This is highly recommended for optimal memory efficiency) . If False, creates a new, independent shape with no links to the original object.

Returns:

A new shape translated by the given vector.

triangulation(relative_linear_deflection: float = 0.005, angular_deflection: float = 0.5, merge_meshes=True, linear_deflection: float | None = None, include_metadata: bool = True, **kwargs) Mesh3D#

Tessellates the geometry into vertices and triangles.

Parameters:
  • relative_linear_deflection – Relative linear deflection for mesh generation, used to compute linear deflection based on bounding box size. Smaller values produce finer meshes.

  • angular_deflection – Angular deflection in radians. Smaller values, finer meshes.

  • merge_meshes – If true, all faces are merged into a single mesh; otherwise, each face has an associated mesh.

  • linear_deflection – Linear deflection for mesh generation. If provided, it overrides the automatic calculation based on bounding box size.

  • include_metadata – If True, include topology metadata (faces, edges) in the resulting Mesh3D. Default is True.

Returns:

A single Mesh3D object if merge_meshes is True, otherwise a list of Mesh3D objects for each face.

union(*to_union: Shape, glue: bool = False, tol: float | None = None) Shape#

Perform boolean union (fuse) operation on this Shape.

Fuses one or more shapes with this shape using OpenCASCADE’s BRepAlgoAPI_Fuse algorithm.

Parameters:
  • to_union – Shape(s) to fuse with this shape.

  • glue – Enables glue optimization for better performance when shapes intersect.

  • tol – Fuzzy mode tolerance. Enables fuzzy operations for shapes with small gaps/overlaps.

Returns:

Resulting Shape object after union.

volmdlr_primitives()#

Gets shape’s volmdlr primitives.

volume()#

Gets the Volume of a shape.

Returns:

class volmdlr.shapes.Shell(obj: TopoDS_Shape, reference_path: str = '#', name: str = '')#

Bases: Shape, ShellSolidMixin

OCP shell wrapped.

adjacent_faces(face: Face3D)#

Finds all the first neighbors (adjacent faces) of a given face.

Parameters:

face (vm_faces.Face3D) – Target face.

Returns:

List of adjacent faces.

Return type:

list[vm_faces.Face3D]

adjacent_faces_indexes(face_index: int)#

Finds all the first neighbors (adjacent faces) of a given face.

Parameters:

face_index (int) – The index of the target face.

Returns:

List of indices representing adjacent faces.

Return type:

list[int]

faces_graph()#

Returns the graph of adjacent faces of the shell.

Returns:

A NetworkX graph representing adjacent faces.

Return type:

nx.Graph

classmethod from_faces(faces, tol: float = 1e-06, name: str = '')#

Create a Shell from a list of faces.

Parameters:
  • faces – List of faces to create a shell.

  • tol – Tolerance to be used.

  • name – Name to be given to new shell.

Returns:

A new Shell object.

property is_closed#

Returns True if shell is a closed shell and False otherwise.

classmethod make_extrusion(shape: Contour3D, extrusion_direction: Vector3D, extrusion_length: float, name: str = '') Shell#

Returns a Shell generated by the extrusion of a wire.

classmethod make_loft(sections: list[Contour3D | Point3D], ruled: bool = False, name: str = '') Shell#

Builds a lofted shell by connecting a sequence of section profiles.

Parameters:
  • sections – A list of section profiles to be connected. The first and the last sections can be vertices, representing punctual sections.

  • ruled – A boolean value indicating the type of surface to generate between each pair of sections. If False (default), the loft will generate smooth curves between each of the sections. If True, the loft will generate a ruled surface (straight lines) between each pair of sections.

  • name – An optional string to name the solid.

Returns:

A Shell object representing the lofted shape.

Raises

ValueError: If less than two sections are provided.

classmethod make_revolve(shape: Wire3D, axis_point: Point3D, axis: Vector3D, angle: float = 6.283185307179586, name: str = '') Shell#

Revolves a 3D wire around a specified axis through a given angle to create a Shell object.

Parameters:
  • shape – A Wire3D to be revolved.

  • axis_point – A Point3D object representing the point through which the axis of revolution passes.

  • axis – A Vector3D object representing the direction of the axis of revolution.

  • angle – A float representing the angle of revolution in radians. Default is 2*pi, which corresponds to a full revolution.

  • name – An optional string to name the Solid object.

Returns:

A TopoDS_Solid or TopoDS_Shell object resulting from the revolution operation.

classmethod make_sweep(section: Contour2D, path: Wire3D | Edge, starting_frame: Frame3D | None = None, is_frenet: bool = False, mode: Vector3D | Wire3D | Edge | None = None, transition_mode: Literal['transformed', 'round', 'right'] = 'transformed', name: str = '') Shell#

Class method to create a Shell object by sweeping a contour along a provided path.

Parameters:
  • section – A Contour2D object representing the section to be swept.

  • path – A Wire3D or Edge object representing the path along which the section is to be swept.

  • starting_frame – An optional Frame3D object representing the starting frame of the sweep. If None, the starting frame is computed based on the path.

  • is_frenet – A boolean value indicating whether to use Frenet mode. If True, the orientation of the profile is computed with respect to the Frenet trihedron. Default is False.

  • mode – An optional parameter that can be a Vector3D, Wire3D, Edge, or None. This parameter provides additional sweep mode parameters. If it’s a Vector3D, the direction of the vector is used as the sweep direction. If it’s a Wire3D or Edge, the sweep follows the path of the wire or edge.

  • transition_mode – A string indicating how to handle profile orientation at C1 path discontinuities. Possible values are ‘transformed’, ‘round’, and ‘right’. ‘transformed’ means the profile is automatically transformed to make the sweeping path tangent continuous. ‘round’ means a round corner is built between the two successive sections. ‘right’ means a right corner (intersection) is built between the two successive sections. Default is ‘transformed’.

  • name – An optional string to name the Shell object.

Returns:

A Shell object resulting from the sweep operation.

classmethod make_wedge(dx: float, dy: float, dz: float, xmin: float, zmin: float, xmax: float, zmax: float, local_frame_origin: Point3D = Point3D(0.0, 0.0, 0.0), local_frame_direction: Vector3D = Vector3D(0.0, 0.0, 1.0), local_frame_x_direction: Vector3D | None = None, name: str = '') Shell#

Creates a wedge, which can represent a pyramid or a truncated pyramid.

The origin of the local coordinate system is the corner of the base rectangle of the wedge. The y-axis represents the “height” of the pyramid or truncated pyramid.

To create a pyramid, specify xmin=xmax=dx/2 and zmin=zmax=dz/2.

Parameters:
  • dx (float) – The length of the base rectangle along the x-axis.

  • dy (float) – The height of the pyramid or truncated pyramid along the y-axis.

  • dz (float) – The width of the base rectangle along the z-axis.

  • xmin (float) – The x-coordinate of one corner of the top rectangle.

  • zmin (float) – The z-coordinate of one corner of the top rectangle.

  • xmax (float) – The x-coordinate of the opposite corner of the top rectangle.

  • zmax (float) – The z-coordinate of the opposite corner of the top rectangle.

  • local_frame_origin (volmdlr.Point3D) – The origin of the local coordinate system for the wedge. Defaults to the origin (0, 0, 0).

  • local_frame_direction (volmdlr.Vector3D) – The main direction for the local coordinate system of the wedge. Defaults to the z-axis (0, 0, 1).

  • local_frame_x_direction (volmdlr.Vector3D) – The x direction for the local coordinate system of the wedge. Defaults to the x-axis (1, 0, 0).

  • name (str) – (Optional) Shape name.

Returns:

The created wedge.

Return type:

Shell

Example: To create a pyramid with a square base of size 1 and where its apex is located at volmdlr.Point3D(0.0, 0.0, 2.0): >>> dx, dy, dz = 1, 2, 1 >>> wedge = Shell.make_wedge(dx=dx, dy=dy, dz=dz, xmin=dx / 2, xmax=dx / 2, zmin=dz / 2, zmax=dz / 2, >>> local_frame_origin=volmdlr.Point3D(-0.5, 0.5, 0.0), >>> local_frame_direction=-volmdlr.Y3D, >>> local_frame_x_direction=volmdlr.X3D)

property parent_shape: Shape#

Get the root shape.

property primitives: list[Shape]#

Gets children shapes of a shape-like object.

Returns:

A list of Shape object that are the children of the current Shape object.

shortest_path_between_faces(source_face, target_face)#

Computes the shortest path (fewest number of faces) between two faces.

Parameters:
  • source_face (vm_faces.Face3D) – The starting face.

  • target_face (vm_faces.Face3D) – Target face.

Returns:

List of faces representing the shortest path.

Return type:

list[vm_faces.Face3D]

shortest_path_between_faces_indexes(start_index, end_index)#

Computes the shortest path (fewest number of faces) between two faces.

Parameters:
  • start_index (int) – Index of the starting face.

  • end_index (int) – Index of the target face.

Returns:

List of indices representing the shortest path.

Return type:

list[int]

class volmdlr.shapes.ShellSolidMixin#

Bases: object

A mixin class to provide face manipulation methods.

property edges: list[Edge]#

Get shape edges in the same order as mesh metadata.

Ensures correspondence: edges[i] matches metadata[“edges”][i][“id”] == i when mesh is created with _extract_face_metadata.

Returns:

List of Edge objects, deduplicated and ordered by ID.

property faces: list[Face3D]#

Get shape faces.

get_face(index: int) Face#

Gets the face at a given position in the shape’s list of faces.

Parameters:

index (int) – The 0-based index of the desired face.

Returns:

The specified face.

Return type:

Face

get_face_index(face: Face) int#

Finds the index of the given face within the shape’s list of faces.

Parameters:

face – The face for which to retrieve the index.

Returns:

The 0-based index of the specified face.

Return type:

int

class volmdlr.shapes.Solid(obj: TopoDS_Shape, reference_path: str = '#', name: str = '')#

Bases: Shape, ShellSolidMixin

A single solid.

classmethod from_faces(faces: list[Face3D], tol: float = 1e-06, name: str = '') Solid#

Make a solid from a list of faces.

Parameters:
  • faces – A list containing the faces that form a closed volume.

  • tol – tolerance used.

  • name – name for new instance.

Returns:

The solid after assembling of faces.

classmethod from_shells(outer_shell: Shell, inner_shells: list[Shell]) Solid#

Makes a solid from a list of shell.

is_inside(point: Point3D, tolerance: float = 1e-06) bool#

Returns whether the point is inside a solid or compound object within the specified tolerance.

Parameters:
  • point – tuple or Vector representing 3D point to be tested

  • tolerance – tolerance for inside determination, default=1.0e-6

Returns:

bool indicating whether point is within solid

classmethod make_box(length: float, width: float, height: float, frame: Frame3D | None = None, frame_centered: bool = False, name: str = '') Solid#

Create a box with the specified dimensions and position it according to the given frame.

The resulting box will have dimensions (length, width, height) with one of its corners at the origin of the frame, if frame_centered is False. The box will be centered at the frame origin if it is True. By default, the function creates a box with a corner at (0, 0, 0) and the opposite corner at (length, width, height) in the global coordinate system.

Parameters:
  • length – The length of the box along the x-axis.

  • width – The width of the box along the y-axis.

  • height – The height of the box along the z-axis.

  • frame – The coordinate frame for the box.

  • frame_centered – Whether to center the box at the origin of the frame or not.

  • name – The name of the solid. Defaults to an empty string.

Returns:

Solid: A new box solid instance.

classmethod make_cone(radius1: float, radius2: float, height: float, frame: Frame3D | None = None, angle: float = 6.283185307179586, name: str = '') Solid#

Create a cone with the specified radii and height.

By default, the function creates a full cone using the global coordinate system.

Parameters:
  • radius1 – The radius at the base of the cone.

  • radius2 – The radius at the top of the cone.

  • height – The height of the cone.

  • frame – The coordinate frame for the cone.

  • angle – The angle in radians for the conical segment.

  • name – The name of the solid.

Returns:

Solid: A new cone solid instance.

classmethod make_cylinder(radius: float, height: float, frame: Frame3D | None = None, angle: float = 6.283185307179586, name: str = '') Solid#

Create a cylinder with the specified radius and height.

By default, the function creates a full cylinder using the global coordinate system. The base of the cylinder starts at the origin point of the given frame, and it will be created following the w-dirction of the same frame.

Parameters:
  • radius – The radius of the cylinder.

  • height – The height of the cylinder.

  • frame – The coordinate frame for the cylinder.

  • angle – The angle in radians the cylindrical segment.

  • name – The name of the solid.

Returns:

Solid: A new cylinder solid instance.

classmethod make_extrusion(face: PlaneFace3D, extrusion_vector: Vector3D, name: str = '') Solid#

Create a solid generated by the extrusion of a plane face.

This method extrudes the given plane face along the specified vector to generate a solid.

Parameters:
  • face – The plane face to be extruded.

  • extrusion_vector – The vector defining the direction and length of the extrusion.

  • name – The name of the solid. Defaults to an empty string.

Returns:

A new solid instance created by extruding the specified plane face.

classmethod make_extrusion_from_frame_and_wires(frame: Frame3D, outer_contour2d: Contour2D, inner_contours2d: list[Contour2D], extrusion_length: float, name: str = '') Solid#

Create a solid generated by the extrusion of a plane face defined by the given contours and frame.

This method creates a solid by extruding a plane face defined by the specified outer and inner contours along the w-axis of the provided frame.

Parameters:
  • frame – The coordinate frame for the extrusion.

  • outer_contour2d – The outer contour of the 2D shape to be extruded.

  • inner_contours2d – A list of inner contours for the 2D shape to be extruded.

  • extrusion_length – The length of the extrusion along the frame’s w-axis.

  • name – The name of the solid. Defaults to an empty string.

Returns:

Solid: A new solid instance created by extruding the defined plane face.

classmethod make_hallow_cylinder(frame: Frame3D, inner_radius: float, outer_radius: float, height: float, name: str = '')#

Deprecated typo version of make_hollow_cylinder. This method will be removed soon.

Please use make_hollow_cylinder instead.

Parameters:
  • frame (volmdlr.Frame3D) – The reference frame defining the position and orientation of the hollow cylinder.

  • inner_radius (float) – The inner radius of the hollow cylinder.

  • outer_radius (float) – The outer radius of the hollow cylinder.

  • height (float) – The height of the hollow cylinder.

  • name (str, optional) – The name of the hollow cylinder. Default is an empty string.

classmethod make_hollow_cylinder(frame: Frame3D, inner_radius: float, outer_radius: float, height: float, name: str = '')#

Create a solid hollow cylinder with the specified radius and height, positioned using the given frame.

The axis of revolution of the hollow cylinder corresponds to the local z-axis (w-axis) of the provided frame.

Parameters:
  • frame (volmdlr.Frame3D) – The reference frame defining the position and orientation of the hollow cylinder. The w-axis of the frame corresponds to the axis of revolution of the hollow cylinder.

  • inner_radius (float) – The inner radius of the hollow cylinder.

  • outer_radius (float) – The outer radius of the hollow cylinder.

  • height (float) – The height of the hollow cylinder.

  • name (str, optional) – The name of the hollow cylinder. Default is an empty string.

classmethod make_loft(sections: list[Contour3D | Point3D], ruled: bool = False, name: str = '') Solid#

Builds a lofted solid by connecting a sequence of section profiles.

Parameters:
  • sections – A list of section profiles to be connected. The first and the last sections can be vertices, representing punctual sections.

  • ruled – A boolean value indicating the type of surface to generate between each pair of sections. If False (default), the loft will generate smooth curves between each of the sections. If True, the loft will generate a ruled surface (straight lines) between each pair of sections.

  • name – An optional string to name the solid.

Returns:

A Solid object representing the lofted shape.

Raises

ValueError: If less than two sections are provided.

classmethod make_revolve(shape: PlaneFace3D, axis_point: Point3D, axis: Vector3D, angle: float = 6.283185307179586, name: str = '') Solid#

Class method to create a Solid object by revolving a plane face around a specified axis through a given angle.

Parameters:
  • shape – A plane face to be revolved.

  • axis_point – A Point3D object representing the point through which the axis of revolution passes.

  • axis – A Vector3D object representing the direction of the axis of revolution.

  • angle – A float representing the angle of revolution in radians. Default is 2*pi, which corresponds to a full revolution.

  • name – An optional string to name the Solid object.

Returns:

A TopoDS_Solid or TopoDS_Shell object resulting from the revolution operation.

classmethod make_revolve_from_contour(frame: Frame3D, contour2d: Contour2D, axis_point: Point3D, axis: Vector3D, inner_contours: list[Contour2D] | None = None, angle: float = 6.283185307179586, name: str = '') Solid#

Class method to create a Solid object by revolving a contour around a specified axis through a given angle.

Parameters:
  • frame – A Frame3D object representing the frame of the contour.

  • contour2d – A Contour2D object representing the contour to be revolved.

  • axis_point – A Point3D object representing the point through which the axis of revolution passes.

  • axis – A Vector3D object representing the direction of the axis of revolution.

  • inner_contours – An optional list of Contour2D objects representing the inner contours of the contour.

  • angle – A float representing the angle of revolution in radians. Default is 2*pi, which corresponds to a full revolution.

  • name – An optional string to name the Solid object.

Returns:

A Solid object resulting from the revolution operation.

classmethod make_solid(shell: Shell, name: str = '') Solid#

Makes a solid from a single shell.

classmethod make_sphere(radius: float, frame: Frame3D | None = None, angle1: float = -1.5707963267948966, angle2: float = 1.5707963267948966, angle3: float = 6.283185307179586, name: str = '') Solid#

Create a sphere with the specified radius.

By default, the function creates a full sphere using the global coordinate system.

Parameters:
  • radius – The radius of the sphere.

  • frame – The coordinate frame for the sphere.

  • angle1 – The starting angle in radians for the latitude.

  • angle2 – The ending angle in radians for the latitude.

  • angle3 – The angle in radians for the longitude.

  • name – solid name.

Returns:

A new sphere solid instance.

classmethod make_sweep(face: PlaneFace3D, path: Wire3D | Edge, is_frenet: bool = False, mode: Vector3D | Wire3D | Edge | None = None, transition_mode: Literal['transformed', 'round', 'right'] = 'transformed', name: str = '') Solid#

Class method to create a Solid object by sweeping a plane face along a provided path.

Parameters:
  • face – A PlaneFace3D object representing the face to be swept.

  • path – A Wire3D or Edge object representing the path along which the face is to be swept.

  • is_frenet – A boolean value indicating whether to use Frenet mode. If True, the orientation of the profile is computed with respect to the Frenet trihedron. Default is False.

  • mode – An optional parameter that can be a Vector3D, Wire3D, Edge, or None. This parameter provides additional sweep mode parameters. If it’s a Vector3D, the direction of the vector is used as the sweep direction. If it’s a Wire3D or Edge, the sweep follows the path of the wire or edge.

  • transition_mode – A string indicating how to handle profile orientation at C1 path discontinuities. Possible values are ‘transformed’, ‘round’, and ‘right’. ‘transformed’ means the profile is automatically transformed to make the sweeping path tangent continuous. ‘round’ means a round corner is built between the two successive sections. ‘right’ means a right corner (intersection) is built between the two successive sections. Default is ‘transformed’.

  • name – An optional string to name the Solid object.

Returns:

A Solid object resulting from the sweep operation.

classmethod make_sweep_from_contour(section: Contour2D, path: Wire3D | Edge, inner_contours: list[Contour2D] | None = None, starting_frame: Frame3D | None = None, is_frenet: bool = False, mode: Vector3D | Wire3D | Edge | None = None, transition_mode: Literal['transformed', 'round', 'right'] = 'transformed', name: str = '') Solid#

Class method to create a Solid object by sweeping a contour along a provided path.

Parameters:
  • section – A Contour2D object representing the section to be swept.

  • path – A Wire3D or Edge object representing the path along which the section is to be swept.

  • inner_contours – A list of Contour2D objects representing the inner contours of the section.

  • starting_frame – An optional Frame3D object representing the starting frame of the sweep. If None, the starting frame is computed based on the path.

  • is_frenet – A boolean value indicating whether to use Frenet mode. If True, the orientation of the profile is computed with respect to the Frenet trihedron. Default is False.

  • mode – An optional parameter that can be a Vector3D, Wire3D, Edge, or None. This parameter provides additional sweep mode parameters. If it’s a Vector3D, the direction of the vector is used as the sweep direction. If it’s a Wire3D or Edge, the sweep follows the path of the wire or edge.

  • transition_mode – A string indicating how to handle profile orientation at C1 path discontinuities. Possible values are ‘transformed’, ‘round’, and ‘right’. ‘transformed’ means the profile is automatically transformed to make the sweeping path tangent continuous. ‘round’ means a round corner is built between the two successive sections. ‘right’ means a right corner (intersection) is built between the two successive sections. Default is ‘transformed’.

  • name – An optional string to name the Solid object.

Returns:

A Solid object resulting from the sweep operation.

classmethod make_torus(radius1: float, radius2: float, frame: Frame3D | None = None, angle1: float = 0, angle2: float = 6.283185307179586, name: str = '') Solid#

Create a torus with the specified radii and angles.

By default, the function creates a full torus using the global coordinate system.

Parameters:
  • radius1 – The major radius of the torus.

  • radius2 – The minor radius of the torus.

  • frame – The coordinate frame for the torus.

  • angle1 – The starting angle in radians for the torus segment.

  • angle2 – The ending angle in radians for the torus segment.

  • name – The name of the solid.

Returns:

Solid: A new torus solid instance.

classmethod make_wedge(dx: float, dy: float, dz: float, xmin: float, zmin: float, xmax: float, zmax: float, local_frame_origin: Point3D = Point3D(0.0, 0.0, 0.0), local_frame_direction: Vector3D = Vector3D(0.0, 0.0, 1.0), local_frame_x_direction: Vector3D | None = None, name: str = '') Solid#

Creates a wedge, which can represent a pyramid or a truncated pyramid.

The origin of the local coordinate system is the corner of the base rectangle of the wedge. The y-axis represents the “height” of the pyramid or truncated pyramid.

To create a pyramid, specify xmin=xmax=dx/2 and zmin=zmax=dz/2.

Parameters:
  • dx (float) – The length of the base rectangle along the x-axis.

  • dy (float) – The height of the pyramid or truncated pyramid along the y-axis.

  • dz (float) – The width of the base rectangle along the z-axis.

  • xmin (float) – The x-coordinate of one corner of the top rectangle.

  • zmin (float) – The z-coordinate of one corner of the top rectangle.

  • xmax (float) – The x-coordinate of the opposite corner of the top rectangle.

  • zmax (float) – The z-coordinate of the opposite corner of the top rectangle.

  • local_frame_origin (volmdlr.Point3D) – The origin of the local coordinate system for the wedge. Defaults to the origin (0, 0, 0).

  • local_frame_direction (volmdlr.Vector3D) – The main direction for the local coordinate system of the wedge. Defaults to the z-axis (0, 0, 1).

  • local_frame_x_direction (volmdlr.Vector3D) – The x direction for the local coordinate system of the wedge. Defaults to the x-axis (1, 0, 0).

  • name (str) – (Optional) Shape name.

Returns:

The created wedge.

Return type:

Solid

Example: To create a pyramid with a square base of size 1 and where its apex is located at volmdlr.Point3D(0.0, 0.0, 2.0): >>> dx, dy, dz = 1, 2, 1 >>> wedge = Solid.make_wedge(dx=dx, dy=dy, dz=dz, xmin=dx / 2, xmax=dx / 2, zmin=dz / 2, zmax=dz / 2, >>> local_frame_origin=volmdlr.Point3D(-0.5, 0.5, 0.0), >>> local_frame_direction=-volmdlr.Y3D, >>> local_frame_x_direction=volmdlr.X3D)

class volmdlr.shapes.TopoMesh3D(shape: Shell | Solid, mesh_linear_deflection: float = 0.005, mesh_angular_deflection: float = 0.5, color: tuple[float, float, float] = (0.8, 0.8, 0.8), alpha: float = 1.0, name: str = '', **kwargs)#

Bases: Mesh3D

A class that represents a Mesh3D of a BRep model but also keeps its topological data structure.

get_interfering_faces(other: TopoMesh3D) Shell#

Detect interfering faces between this mesh and another TopoMesh3D.

These are faces that do not intersect with any other’s face but that are interfering other’s shape, which means it is totally inside of it.

Parameters:

other – Another TopoMesh3D instance.

Returns:

Two shells containing intersecting faces in self and other, respectively.

get_intersecting_faces(other: TopoMesh3D) tuple[Shell, Shell]#

Detect intersecting faces between this mesh and another TopoMesh3D.

Parameters:

other – Another TopoMesh3D instance.

Returns:

Two shells containing intersecting faces in self and other, respectively.

get_visible_faces(origin: Point3D, environment: list[TopoMesh3D] | None = None) Shell#

Identify visible faces from a given origin, accounting for occlusion by other TopoMesh3D objects.

Parameters:
  • origin – The origin point in space for visibility determination.

  • environment – A list of other TopoMesh3D objects to consider for occlusion.

Returns:

A Shell with the visible faces.

get_visible_triangles(origin: Point3D, environment: list[TopoMesh3D] | None = None, return_triangles: bool = False) set | list[Triangle3D]#

Identify visible triangles from a given origin, accounting for occlusion by other TopoMesh3D objects.

Parameters:
  • origin – The origin point in space for visibility determination.

  • environment – A list of other TopoMesh3D objects to consider for occlusion.

  • return_triangles – (Optional) If set to True also returns a list of Triangle3D

Returns:

A set of indices of visible triangles in self.

initializer() tuple[ndarray[Any, dtype[_ScalarType_co]], ndarray[Any, dtype[_ScalarType_co]]]#

Tessellates the geometry into vertices and triangles and assigns triangles to faces.

Returns:

A tuple with the vertices and triangles.

mesh(relative_linear_deflection: float = 0.005, angular_deflection: float = 0.5, linear_deflection: float | None = None, **kwargs) None#

Re-mesh the wrapped shape, if not already done with same parameters.

The meshing parameters are saved as attributes of the instance, so they can be serialized and deserialized.

Parameters:
  • relative_linear_deflection – Relative linear deflection for mesh generation, used to compute linear deflection based on bounding box size. Smaller values produce finer meshes.

  • angular_deflection – Angular deflection in radians. Smaller values, finer meshes.

  • linear_deflection – Linear deflection for mesh generation. If provided, it overrides the automatic calculation based on bounding box size.

property mesh_angular_deflection: float#

Get set mesh angular tolerance.

mesh_difference(other: TopoMesh3D) Mesh3D#

Perform a difference operation (this mesh - other mesh).

mesh_intersection(other: TopoMesh3D) Mesh3D#

Perform an intersection operation between this mesh and another mesh.

property mesh_linear_deflection: float#

Get set mesh linear tolerance.

mesh_union(other: TopoMesh3D) Mesh3D#

Perform a union operation between this mesh and another mesh.

minimum_distance(other: TopoMesh3D) float#

Return the minimum distance between self and other.

Parameters:

other – Another TopoMesh3D instance.

Returns:

A float representing the minimum distance between self and other.

round_vertices(decimals: int = 9) TopoMesh3D#

Round the vertices of the Mesh instance to a given number of decimals.

Parameters:

decimals (int, optional) – The number of decimal places to round the vertices to (default is 9).

Returns:

A new Mesh instance with rounded vertices.

Return type:

MeshType

slice() list[Face3D]#

Slice prototype.

class volmdlr.shapes.Vertex(obj: TopoDS_Shape, reference_path: str = '#', name: str = '')#

Bases: Shape

OCP Edge wrapped.

babylon_points()#

Returns a list of discretization points from the 3D primitive.

property point: Point3D#

Returns the point associated with the vertex.

class volmdlr.shapes.Wire(obj: TopoDS_Shape, reference_path: str = '#', name: str = '')#

Bases: Shape

OCP Wire wrapped.

babylon_curves()#

Gets babylonjs curves.

babylon_lines(points=None)#

Returns the wire data in babylon format.

babylon_points()#

Returns a list of discretization points from the 3D primitive.

classmethod from_edges(wire_edges: list[Edge] | list[Edge] | list[TopoDS_Edge], name: str = '')#

Create a Wire from a list of edges.

Parameters:
  • wire_edges – List of edges to create a Wire.

  • name – Name to be given to new Wire.

Returns:

A new Wire object.

volmdlr.shapes.downcast(obj: TopoDS_Shape) TopoDS_Shape#

Downcasts a TopoDS object to suitable specialized type.

volmdlr.shapes.shapetype(obj: TopoDS_Shape) TopAbs_ShapeEnum#

Gets the shape type for a TopoDS_Shape object.