Wires#

Module containing wires & contours.

class volmdlr.wires.ClosedPolygon2D(points: List[Point2D], name: str = '')[source]#

Bases: ClosedPolygonMixin, Contour2D

A collection of points, connected by line segments, following each other.

area()[source]#

Returns the area of the polygon.

axial_symmetry(line)[source]#

Finds out the symmetric closed_polygon2d according to a line.

barycenter()[source]#

Calculates the geometric center of the polygon, which is the average position of all the points in it.

Return type:

volmdlr.Point2D

center_of_mass()[source]#

Returns polygon’s center of mass.

classmethod concave_hull(points, concavity, scale_factor, name: str = '')[source]#

Calculates the concave hull from a cloud of points.

i.e., it Unites all points under the smallest possible area.

Parameters:
  • points (class: 'volmdlr.Point2D') – list of points corresponding to the cloud of points

  • concavity (float) – Sets how sharp the concave angles can be. It goes from -1 (not concave at all. in fact, the hull will be left convex) up to +1 (very sharp angles can occur. Setting concavity to +1 might result in 0º angles!) concavity is defined as the cosine of the concave angles.

  • scale_factor (float.) – Sets how big is the area where concavities are going to be searched. The bigger, the more sharp the angles can be. Setting it to a very high value might affect the performance of the program. This value should be relative to how close to each other the points to be connected are.

  • name – object’s name.

classmethod convex_hull_points(points, name: str = '')[source]#

Uses the scipy method ConvexHull to calculate the convex hull from a cloud of points.

copy(*args, **kwargs)[source]#

Returns a copy of the object.

delaunay_triangulation()[source]#

Triangulate a closed polygon 2d using delaunay algorithm.

Returns:

delaunay triangles.

frame_mapping(frame: Frame2D, side: str)[source]#

Apply transformation to the object.

get_closing_point(polygon2_2d, primitive, ax=None)[source]#

Gets sewing closing points for given primitive points.

get_line_segments()[source]#

Get polygon lines.

get_possible_sewing_closing_points(polygon2, polygon_primitive, line_segment1: None, line_segment2: None)[source]#

Searches all possibles closing points available for the given primitive.

get_valid_sewing_polygon_primitive(polygon2_2d)[source]#

Get valid primitive to start sewing two polygons.

grid_triangulation_points(number_points_x: int = 25, number_points_y: int = 25, include_edge_points: bool = True)[source]#

Use an n by m grid to triangulate the contour.

Parameters:
  • number_points_x (int) – Number of discretization points in x direction.

  • number_points_y (int) – Number of discretization points in y direction.

  • include_edge_points (bool, optional) – Flag to include edge points as inside the polygon

Returns:

Discretization data.

Return type:

list

is_convex()[source]#

Verifies if a polygon is convex or Not.

property is_trigo#

Verifies if Closed Polygon 2D is in trigo direction.

Returns:

line_intersecting_closing_point(crossing_point)[source]#

Finds closing point for the sewing method using intersection of lines drawn from the barycenter.

returns the closing point.

offset(offset)[source]#

Offsets a polygon 2d edges from a distance.

Parameters:

offset – offset distance.

Returns:

plot(ax=None, edge_style: EdgeStyle = EdgeStyle(color='k', alpha=1, edge_ends=False, edge_direction=False, width=None, arrow=False, plot_points=False, dashed=True, linestyle='-', linewidth=1, equal_aspect=True), point_numbering=False, fill=False, fill_color='w')[source]#

Matplotlib plot for a closed polygon 2D.

point_border_distance(point, return_other_point=False)[source]#

Compute the distance to the border distance of polygon.

Output is always positive, even if the point belongs to the polygon.

point_in_polygon()[source]#

In case the barycenter of the polygon is outside, this method finds another point inside the polygon.

point_inside(point, include_edge_points: bool = False, tol: float = 1e-06)[source]#

Ray casting algorithm copied from internet.

classmethod points_convex_hull(points, name: str = '')[source]#

Creates a convex hull from a collection of 2D points.

points_in_polygon(points, include_edge_points: bool = False, tol: float = 1e-06)[source]#

Check if a list of points is inside the polygon using parallel computing.

Parameters:
  • points (list or numpy.ndarray) – List of points in the form [(x1, y1), (x2, y2), …]

  • include_edge_points (bool, optional) – Flag to include edge points as inside the polygon

  • tol (float, optional) – Tolerance for numerical comparisons, defaults to 1e-6

Returns:

List of boolean values indicating whether each point is inside the polygon

Return type:

numpy.ndarray

polygon_distance(polygon: ClosedPolygon2D) float[source]#

Returns the minimum distance to other given polygon.

rotation(center: Point2D, angle: float)[source]#

ClosedPolygon2D rotation.

Parameters:
  • center – rotation center

  • angle – angle rotation

Returns:

a new rotated ClosedPolygon2D

search_ear(remaining_points, initial_point_to_index)[source]#

Helper method to search for ears for ear clipping triangulation method.

Parameters:
  • remaining_points – list of remaining points.

  • initial_point_to_index – initial point to index.

Returns:

search_farthest(interseting_point, possible_closing_points)[source]#

Chooses the closest of the farthest available.

While Sewing two Polygons, and searching a face’s closing point, this method verifies it :return: True if to search the farthest of False if not

second_moment_area(point)[source]#

Returns the second moment of area of the polygon.

select_closest_sewing_closing_point(line_segment: LineSegment2D, polygon_primitive, possible_closing_points)[source]#

Searches the closest sewing closing point available.

select_farthest_sewing_closing_point(line_segment: LineSegment2D, polygon_primitive, possible_closing_points)[source]#

Searches the closest sewing closing point available.

self_intersects()[source]#

Determines if a polygon self intersects using the Bentley-Ottmann algorithm.

Returns:

True if the polygon self intersects, False otherwise. If True, returns two intersecting line segments as LineSegment2D objects. If False, returns two None values;

Return type:

Tuple[bool, Union[volmdlr.edges.LineSegment2D, None], Union[volmdlr.edges.LineSegment2D, None]]

simplify(min_distance: float = 0.01, max_distance: float = 0.05)[source]#

Simplify polygon.

to_3d(plane_origin, x, y)[source]#

Transforms a ClosedPolygon2D into an ClosedPolygon3D, given a plane origin and an u and v plane vector.

Parameters:
  • plane_origin – plane origin.

  • x – plane u vector.

  • y – plane v vector.

Returns:

ClosedPolygon3D.

translation(offset: Vector2D)[source]#

ClosedPolygon2D translation.

Parameters:

offset – translation vector

Returns:

A new translated ClosedPolygon2D

triangulation(tri_opt: str = 'p')[source]#

Perform triangulation on the polygon.

To detail documentation, please refer to https://rufat.be/triangle/API.html

Parameters:

tri_opt (str) – (Optional) Triangulation preferences.

Returns:

A 2D mesh.

Return type:

vmd.Mesh2D

class volmdlr.wires.ClosedPolygon3D(points: List[Point3D], name: str = '')[source]#

Bases: Contour3D, ClosedPolygonMixin

A collection of points, connected by line segments, following each other.

check_sewing(polygon2, sewing_faces)[source]#

Checks if sewing is valid or not.

static clean_sewing_closing_pairs_dictionary(dict_closing_pairs, closing_point_index, passed_by_zero_index)[source]#

Cleans the dictionary containing the sewing closing pairs information.

In case it needs to be recalculated due to changing closing points.

close_sewing(dict_closing_pairs)[source]#

Closes sewing resulting triangles.

concave_sewing(polygon2: ClosedPolygon3D, x: float, y: float)[source]#

Sews the current polygon with another specified polygon when one of them is concave.

This method performs sewing between the current polygon and the specified polygon when one of the polygons is concave, using the provided x and y directions of the plane used to project the polygons in.

Parameters:
  • polygon2 (ClosedPolygon3D) – The polygon to sew with the current polygon.

  • x (float) – The x-direction of the projection plane.

  • y (float) – The y-direction of the projection plane.

Returns:

A list of triangles’ points representing the sewn polygons.

Return type:

list[list[Point3D]]

convex_sewing(polygon2, x, y)[source]#

Sew to Convex Polygon.

Parameters:
  • polygon2 – other polygon to sew with.

  • x – u vector for plane projection.

  • y – v vector for plane projection.

copy(*args, **kwargs)[source]#

Returns a copy of the object.

static fix_sewing_normals(triangles, reference_linesegment)[source]#

Fixes sewing triangle normal so it faces always outwards.

get_line_segments()[source]#

Get polygon lines.

get_valid_concave_sewing_polygon(polygon1_2d, polygon2_2d)[source]#

Gets valid concave sewing polygon.

static is_sewing_forward(closing_point_index, list_closing_point_indexes) bool[source]#

Verifies if it is sewing forward.

plot(ax=None, edge_style: EdgeStyle = EdgeStyle(color='k', alpha=1, edge_ends=False, edge_direction=False, width=None, arrow=False, plot_points=False, dashed=True, linestyle='-', linewidth=1, equal_aspect=True))[source]#

Plot closed polygon 3d using matplotlib.

redefine_sewing_triangles_points(triangles_points, passed_by_zero_index, closing_point_index, previous_closing_point_index)[source]#

Fixes sewing triangle points.

rotation(center: Point3D, axis: Vector3D, angle: float)[source]#

ClosedPolygon3D rotation.

Parameters:
  • center – rotation center.

  • axis – rotation axis.

  • angle – angle rotation.

Returns:

a new rotated ClosedPolygon3D.

sewing(polygon2, x, y)[source]#

Sew two polygon3D together.

Parameters:
  • x – The vector representing first direction to project polygons in

  • y – The vector representing second direction to project polygons in

static sewing_closing_point_past_point0(closing_point_index, list_closing_point_indexes, passed_by_zero_index, ratio_denominator)[source]#

Chooses sewing closing point when point index passes through zero index again.

static sewing_closing_points_to_remove(closing_point_index, list_closing_point_indexes, passed_by_zero_index)[source]#

Identifies which points to be removed.

simplify(min_distance: float = 0.01, max_distance: float = 0.05)[source]#

Simplifies polygon 3d.

Parameters:
  • min_distance – minimal allowed distance.

  • max_distance – maximal allowed distance.

Returns:

Simplified closed polygon 3d.

to_2d(plane_origin, x, y)[source]#

Transforms a ClosedPolygon3D into an ClosedPolygon2D, given a plane origin and an u and v plane vector.

Parameters:
  • plane_origin – plane origin.

  • x – plane u vector.

  • y – plane v vector.

Returns:

ClosedPolygon2D.

translation(offset: Vector3D)[source]#

ClosedPolygon3D translation.

Parameters:

offset – translation vector.

Returns:

A new translated ClosedPolygon3D.

static validate_concave_closing_point(closing_point_index, list_closing_point_indexes, passed_by_zero_index, ratio_denominator, polygons_points_ratio)[source]#

Validates concave closing point.

class volmdlr.wires.ClosedPolygonMixin[source]#

Bases: object

Abstract class for ClosedPolygon, storing methods used by ClosedPolygon2D and ClosedPolygon3D.

edge_statistics()[source]#

Returns polygon statistics.

get_lengths()[source]#

Gets line segment lengths.

get_line_segments()[source]#

Abstract method.

invert()[source]#

Invert the polygon.

length()[source]#

Polygon length.

Returns:

polygon length.

property line_segments#

Polygon line segments.

max_length()[source]#

Gets the minimal length for a line segment in the polygon.

min_length()[source]#

Gets the minimal length for a line segment in the polygon.

simplify_polygon(min_distance: float = 0.01, max_distance: float = 0.05, angle: float = 15)[source]#

Simplify polygon.

class volmdlr.wires.Contour2D(primitives: List[Edge], reference_path: str = '#', name: str = '')[source]#

Bases: ContourMixin, Wire2D

A collection of 2D primitives forming a closed wire2D.

TODO : center_of_mass and second_moment_area should be changed accordingly to area considering the triangle drawn by the arcs

area()[source]#

Returns the area of the contour.

bounding_points()[source]#

Bounding points (x_min, y_min) (x_max, y_max).

center_of_mass()[source]#

Calculates the center of mass of the Contour2D.

Returns:

Contour’s center of mass.

clean_primitives()[source]#

Delete primitives with start=end, and return a new contour.

closest_point_to_point2(point2)[source]#

Search the closest point from self to point2. It only considers the start or end or primitives.

Parameters:

point2 – other point.

Returns:

the closest point to point2.

copy(deep=True, memo=None)[source]#

A specified copy of a Contour2D.

cut_by_bspline_curve(bspline_curve2d: BSplineCurve2D)[source]#

Cut a contour 2d with bspline_curve 2d to define two different contours.

cut_by_line(line: Line2D) List[Contour2D][source]#
Parameters:

line – The line used to cut the contour.

Returns:

A list of resulting contours

cut_by_wire(wire: Wire2D)[source]#

Cut a contour 2d with a wire 2d and return a list of contours 2d.

Parameters:
  • wire – volmdlr.wires.Wire2D

  • wire – volmdlr.wires.Wire2D.

Return type:

list[volmdlr.wires.Contour2D]

Returns:

contours2d : list[volmdlr.wires.Contour2D].

discretized_contour(n: float)[source]#

Discretize each contour’s primitive and return a new contour with these discretized primitives.

divide(contours, abs_tol: float = 1e-06)[source]#

Divide contour with other contours.

property edge_polygon#

Returns the edge polygon of a contour.

An edge polygon is the polygon generated by start and end points of each primitive of the contour.

classmethod from_bounding_rectangle(x_min, x_max, y_min, y_max, name: str = '')[source]#

Create a contour 2d with bounding_box parameters, using line segments 2d.

get_divided_contours(cutting_point1: Point2D, cutting_point2: Point2D, closing_contour, abs_tol: float = 1e-06)[source]#

Get divided contours.

get_furthest_point_to_point2(point2)[source]#

Search the furthest point from self to point2. It only considers the start or end or primitives.

Parameters:

point2 – other point.

Returns:

the furthest point.

grid_triangulation(x_density: float | None = None, y_density: float | None = None, min_points_x: int = 20, min_points_y: int = 20, number_points_x: int | None = None, number_points_y: int | None = None)[source]#

Compute a triangulation using an n-by-m grid to triangulate the contour.

intersection_contour_with(other_contour, abs_tol=1e-06)[source]#

Gets the contour(s) resulting from the intersections of two other contours.

Parameters:
  • other_contour – other contour.

  • abs_tol – tolerance.

Returns:

list of resulting intersection contours.

intersection_points(contour2d)[source]#

Returns the intersections points with other specified contour.

is_edge_inside(edge, abs_tol: float = 1e-06)[source]#

Verifies if given edge is inside self contour perimeter, including its edges.

Parameters:
  • edge – other edge to verify if inside contour.

  • abs_tol – tolerance used.

Returns:

True or False.

is_inside(other_contour)[source]#

Verifies if given contour is inside self contour perimeter, including its edges.

Parameters:

other_contour – other contour.

Returns:

True or False

merge_not_adjacent_contour(other_contour)[source]#

Merge two connected but not adjacent contours.

Parameters:

other_contour – other contour to be merged.

Returns:

merged contour.

merge_with(contour2d, abs_tol: float = 1e-06)[source]#

Merge two adjacent contours, and returns one outer contour and inner contours (if there are any).

Parameters:
  • contour2d – contour to merge with.

  • abs_tol – tolerance.

Returns:

merged contours.

plot_data(edge_style: EdgeStyle | None = None, surface_style: SurfaceStyle | None = None)[source]#

Plot 2D representation of the contour.

point_inside(point, include_edge_points: bool = False, tol: float = 1e-06)[source]#

Verifies if point belongs is within the contour.

Parameters:
  • point – point to be verified.

  • include_edge_points – consider bounds of contour or not.

  • tol – tolerance to be considered.

Returns:

True if point belongs, false otherwise.

random_point_inside(include_edge_points: bool = False)[source]#

Finds a random point inside the polygon.

Parameters:

include_edge_points (bool) – Choose True if you want to consider a point on the polygon inside.

Returns:

A random point inside the polygon

Return type:

volmdlr.Point2D

classmethod rectangle(xmin: float, xmax: float, ymin: float, ymax: float, is_trigo: bool = True)[source]#

Creates a rectangular contour.

Parameters:
  • xmin (float) – minimal x coordinate

  • xmax (float) – maximal x coordinate

  • ymin (float) – minimal y coordinate

  • ymax (float) – maximal y coordinate

  • is_trigo (bool) – (Optional) If True, triangle is drawn in counterclockwise direction.

Returns:

Contour2D

classmethod rectangle_from_center_and_sides(center, x_length, y_length, is_trigo: bool = True)[source]#

Creates a rectangular contour given a center and a side.

repair_cut_contour(n, intersections, line)[source]#

Repair contour.

Choose: n=0 for Side 1: opposite side of beginning of contour n=1 for Side 2: start of contour to first intersect (i=0) and

i odd to i+1 even

second_moment_area(point)[source]#

Returns the second moment of are of the contour.

split_by_line(line: Line2D) List[Contour2D][source]#

Split the contour with the given line.

split_regularly(n)[source]#

Split in n slices.

to_3d(plane_origin, x, y)[source]#

Transforms a Contour2D into an Contour3D, given a plane origin and an u and v plane vector.

Parameters:
  • plane_origin – plane origin.

  • x – plane u vector.

  • y – plane v vector.

Returns:

Contour3D.

triangulation()[source]#

Returns the triangulation of the contour 2d.

union(contour2: Contour2D)[source]#

Union two contours, if they are adjacent, or overlap somehow.

class volmdlr.wires.Contour3D(primitives: List[Primitive3D], reference_path: str = '#', name: str = '')[source]#

Bases: ContourMixin, Wire3D

A collection of 3D primitives forming a closed wire3D.

average_center_point()[source]#

Returns the average center point.

property bounding_box#

Gets bounding box value.

Returns:

Bounding Box.

clean_primitives()[source]#

Delete primitives with start=end, and return a new contour.

contour_intersection(contour3d)[source]#

Calculates intersections between two Contour3D.

Parameters:

contour3d – second contour

Returns:

list of points

copy(deep=True, memo=None)[source]#

Copies the Contour3D.

property edge_polygon#

Get the edge polygon of the contour.

The edge polygon is formed by connecting the vertices of the contour’s edges.

Returns:

The edge polygon of the contour.

Return type:

ClosedPolygon3D

frame_mapping(frame: Frame3D, side: str)[source]#

Changes frame_mapping and return a new Contour3D.

side = ‘old’ or ‘new’.

classmethod from_step(arguments, object_dict, **kwargs)[source]#

Converts a step primitive to a Contour3D.

Parameters:
  • arguments (list) – The arguments of the step primitive.

  • object_dict (dict) – The dictionary containing all the step primitives that have already been instantiated.

Returns:

The corresponding Contour3D object.

Return type:

volmdlr.wires.Contour3D

line_intersections(line: Line3D)[source]#

Calculates intersections between a contour 3d and Line 3d.

Parameters:

line – Line 3D to verify intersections.

Returns:

list with the contour intersections with line

linesegment_intersections(linesegment: LineSegment3D)[source]#

Calculates intersections between a contour 3d and line segment 3D.

Parameters:

linesegment – line segment 3D to verify intersections.

Returns:

list with the contour intersections with line

merge_with(contour3d, abs_tol: float = 1e-06)[source]#

Merge two adjacent contours, and returns one outer contour and inner contours (if there are any).

plot(ax=None, edge_style: EdgeStyle = EdgeStyle(color='k', alpha=1, edge_ends=False, edge_direction=False, width=None, arrow=False, plot_points=False, dashed=True, linestyle='-', linewidth=1, equal_aspect=True))[source]#

Contour 3D plot using Matplotlib.

rotation(center: Point3D, axis: Vector3D, angle: float)[source]#

Contour3D rotation.

Parameters:
  • center – rotation center.

  • axis – rotation axis.

  • angle – angle rotation.

Returns:

a new rotated Contour3D.

to_2d(plane_origin: Point3D, x: Vector3D, y: Vector3D) Contour2D[source]#

Converts 3D contour into a 2D contour.

Parameters:
  • plane_origin – 3D point representing the origin of the coordinates’ system.

  • x – 3D vector representing the x direction of the coordinates’ system.

  • y – 3D vector representing the y direction of the coordinates’ system.

Returns:

Equivalent 2D contour.

to_step(current_id, surface_id=None, surface3d=None)[source]#

Converts the object to a STEP representation.

Parameters:

current_id (int) – The ID of the last written primitive.

Returns:

The STEP representation of the object and the last ID.

Return type:

tuple[str, list[int]]

translation(offset: Vector3D)[source]#

Contour3D translation.

Parameters:

offset – translation vector.

Returns:

A new translated Contour3D.

class volmdlr.wires.ContourMixin[source]#

Bases: WireMixin

Abstract class for Contour, storing methods and attributes used by Contour2D and Contour3D.

are_extremity_points_touching(wire)[source]#

Verifies if the extremities points of wire are touching contour.

Parameters:

wire – other wire.

Returns:

True if other contour is touching

classmethod contours_from_edges(list_edges, tol=1e-06, name: str = 'r')[source]#

Creates an ordered contour given a list of unordered edges.

delete_shared_contour_section(contour, abs_tol: float = 1e-06)[source]#

Delete shared primitives between two adjacent contours.

Parameters:
  • contour – other contour.

  • abs_tol – tolerance.

Returns:

list of new primitives, without those shared by both contours.

discretized_primitives(number_points: float)[source]#

Discretize each contour’s primitive and return a list of discretized primitives.

edges_order_with_adjacent_contour(contour)[source]#

Check if the shared edges between two adjacent contours are traversed with two different directions along each contour.

extremities_points(list_p)[source]#

Return extremities points of a list of points on a contour.

classmethod from_points(points, name: str = '')[source]#

Create a contour from points with line_segments.

get_geo_lines(tag: int, primitives_tags: List[int])[source]#

Gets the lines that define a Contour in a .geo file.

Parameters:
  • tag (int) – The contour index

  • primitives_tags (List[int]) – The contour’s primitives index

Returns:

A line

Return type:

str

get_geo_points()[source]#

Get points in geo file format.

invert()[source]#

Invert the Contour.

is_adjacent(contour)[source]#

Check if two contour are adjacent.

So: are sharing primitives but not superposing or none is inside the other.

is_contour_closed()[source]#

Verifies if contour is closed or not.

Returns:

True is closed, False if Open.

is_ordered(tol=1e-06)[source]#

Verifies if a contour is ordered (primitives following each other).

Parameters:

tol – tolerance to be considered.

Returns:

True if ordered, False if not.

is_overlapping(contour2, intersecting_points=None)[source]#

Check if the contours are overlapping (a part of one is on the other).

merge_primitives_with(contour)[source]#

Extract not shared primitives between two adjacent contours, to be merged.

Parameters:

contour

Returns:

order_contour(tol: float = 1e-06)[source]#

Verifies if the contours’ primitives are ordered (one after the other). If not, it will order it.

primitive_over_contour(primitive, tol: float = 1e-06)[source]#

Verifies if the entire primitive is over a contour.

primitive_section_over_contour(primitive, abs_tol: float = 1e-06)[source]#

Verifies if at least a small section of a primitive is over a contour, not necessarily the entire primitive.

reorder_contour_at_point(point)[source]#

Create a new contour from self, but starting at given point.

Parameters:

point – other point.

Returns:

new contour

shared_primitives_extremities(contour)[source]#

#todo: is this description correct?.

Extract shared primitives extremities between two adjacent contours.

shared_primitives_with(contour)[source]#

Extract shared primitives between two adjacent contours.

shares_primitives(contour)[source]#

Checks if two contour share primitives.

to_polygon(angle_resolution, discretize_line: bool = False, discretize_line_direction: str = 'xy')[source]#

Transform the contour_mixin to a polygon, COPY/PASTE from Contour2D.

Parameters:
  • angle_resolution (float) – Number of points per radians.

  • discretize_line (bool) – Boolean indicating whether the line segments should be discretized or not.

Returns:

The discretized version of the contour.

Return type:

ClosedPolygon2D

class volmdlr.wires.EdgeCollection3D(primitives: List[Edge], color=None, alpha=1, name: str = '')[source]#

Bases: WireMixin, PhysicalObject

A collection of simple edges 3D.

babylon_meshes(**kwargs)[source]#

Set the mesh for babylonjs.

babylon_param()[source]#

Get dict for babylonjs object settings.

babylon_points()[source]#

Get list of points coordinates.

property bounding_box#

Get big bounding box of all edges.

plot(ax=None, edge_style: EdgeStyle = EdgeStyle(color='k', alpha=1, edge_ends=False, edge_direction=False, width=None, arrow=False, plot_points=False, dashed=True, linestyle='-', linewidth=1, equal_aspect=True))[source]#

Plot edges with Matplotlib, not tested.

points()[source]#

Get list of all points.

to_babylon()[source]#

Generate a mesh from all edges for performance when drawing.

class volmdlr.wires.Triangle(point1, point2, point3, name: str = '')[source]#

Bases: ClosedPolygonMixin

Defines a triangle from 3 points.

It is a Super Class for Triangle2D and Triangle3D, storing their main attribute and methods.

class volmdlr.wires.Triangle2D(point1: Point2D, point2: Point2D, point3: Point2D, name: str = '')[source]#

Bases: Triangle, ClosedPolygon2D

Defines a triangle 2D.

Parameters:
  • point1 – triangle point 1.

  • point2 – triangle point 2.

  • point3 – triangle point 3.

area()[source]#

Calculate the area of the triangle.

Returns:

Area of the triangle.

Return type:

float

aspect_ratio()[source]#

Calculate the aspect ratio of the triangle.

Returns:

Aspect ratio of the triangle.

Return type:

float

axial_symmetry(line)[source]#

Finds out the symmetric triangle 2d according to a line.

circumcircle_radius()[source]#

Calculate the radius of the circumscribed circle (circumcircle) of the triangle.

Returns:

Radius of the circumscribed circle.

Return type:

float

incircle_radius()[source]#

Calculate the radius of the inscribed circle (incircle) of the triangle.

Returns:

Radius of the inscribed circle.

Return type:

float

ratio_circumr_length()[source]#

Calculate the ratio of the circumscribed circle radius to the perimeter (length) of the triangle.

Returns:

Ratio of incircle radius to perimeter.

Return type:

float

ratio_incircler_length()[source]#

Calculate the ratio of the incircle radius to the perimeter (length) of the triangle.

Returns:

Ratio of incircle radius to perimeter.

Return type:

float

class volmdlr.wires.Triangle3D(point1: Point3D, point2: Point3D, point3: Point3D, name: str = '')[source]#

Bases: Triangle

Defines a triangle 3D.

Parameters:
  • point1 – triangle point 1.

  • point2 – triangle point 2.

  • point3 – triangle point3.

class volmdlr.wires.Wire2D(primitives, reference_path: str = '#', name: str = '')[source]#

Bases: WireMixin, PhysicalObject

A collection of simple primitives, following each other making a wire.

area()[source]#

Gets the area for a Wire2D.

axial_symmetry(line)[source]#

Finds out the symmetric wire 2d according to a line.

property bounding_rectangle#

Returns the bounding rectangle of the wire.

This property returns the bounding rectangle of the wire. If the bounding rectangle has not been calculated yet, it is computed using the get_bouding_rectangle method and stored in the _bounding_rectangle attribute. Subsequent calls to this property will return the pre-calculated bounding rectangle.

Returns:

The bounding rectangle of the wire.

Return type:

volmdlr.core.BoundingRectangle.

bsplinecurve_crossings(bsplinecurve: BSplineCurve2D)[source]#

Gets the wire primitives crossings with the bsplinecurve.

Returns a list of crossings in the form of a tuple (point, primitive).

bsplinecurve_intersections(bsplinecurve: BSplineCurve2D)[source]#

Gets the wire primitives intersections with the bsplinecurve.

Returns a list of intersections in the form of a tuple (point, primitive).

edge_crossings(edge)[source]#

Gets the crossings between an edge and a Wire.

Parameters:

edge – edge to search for crossings.

Returns:

list of points containing all crossing points.

extend(point)[source]#

Extend a wire by adding a line segment connecting the given point to the nearest wire’s extremities.

frame_mapping(frame: Frame2D, side: str)[source]#

Changes frame_mapping and return a new Wire 2D.

side = ‘old’ or ‘new’

get_bouding_rectangle()[source]#

Calculates the bounding rectangle of the wire.

This method calculates the bounding rectangle of the wire. It initializes the minimum and maximum values for the x and y coordinates using the bounds of the first primitive. Then, it iterates over the remaining primitives and updates the minimum and maximum values based on their bounds. The resulting bounding rectangle is returned as a volmdlr.core.BoundingRectangle object.

Returns:

The bounding rectangle of the wire.

Return type:

volmdlr.core.BoundingRectangle.

infinite_intersections(infinite_primitives)[source]#

Returns a list that contains the intersections between a succession of infinite primitives.

There must be a method implemented to intersect the two infinite primitives.

static is_crossing_start_end_point(intersections, primitive)[source]#

Returns True if the crossings provided are start or end of the Wire 2D.

Parameters:
  • intersections – intersection results for primitive line intersections

  • primitive – intersecting primitive

Returns:

False if intersection not a start or

end point of a contours primitives, or True if it is.

is_inside(other_contour)[source]#

Verifies if given contour is inside self contour perimeter, including its edges.

Parameters:

other_contour – other contour.

Returns:

True or False

is_start_end_crossings_valid(crossing_primitive, intersection, primitive)[source]#

Returns if the crossings are valid.

Parameters:
  • crossing_primitive – crossing primitive.

  • intersection – intersection result. for primitive line intersections

  • primitive – intersecting primitive

Returns:

None if intersection not a start or

end point of a contours primitives, or a volmdlr.Point2D if it is.

is_symmetric(wire2d, line)[source]#

Checks if the two wires 2d are symmetric or not according to line.

line_crossings(line: Line2D)[source]#

Calculates valid crossing intersections of a wire and an infinite line.

Parameters:

line (curves.Line2D) – line crossing the wire

returns a list of Tuples (point, primitive) of the wire primitives intersecting with the line

line_intersections(line: Line2D)[source]#

Returns a list of intersection of the wire primitives intersecting with the line.

Returns:

a tuple (point, primitive)

linesegment_crossings(linesegment: LineSegment2D)[source]#

Gets the wire primitives intersecting with the line.

Returns a list of crossings in the form of a tuple (point, primitive).

linesegment_intersections(linesegment: LineSegment2D)[source]#

Returns a list of intersection of the wire primitives intersecting with the line segment.

Returns:

a tuple (point, primitive)

nearest_primitive_to(point)[source]#

Search for the nearest primitive for a point.

offset(offset)[source]#

Generates an offset of a Wire2D.

plot(ax=None, edge_style=EdgeStyle(color='k', alpha=1, edge_ends=False, edge_direction=False, width=None, arrow=False, plot_points=False, dashed=True, linestyle='-', linewidth=1, equal_aspect=True))[source]#

Wire 2D plot using Matplotlib.

plot_data(*args, **kwargs)[source]#

Plot data for Wire2D.

point_distance(point)[source]#

Copied from Contour2D.

rotation(center: Point2D, angle: float)[source]#

Rotates the wire 2D.

Parameters:
  • center – rotation center.

  • angle – angle rotation.

Returns:

a new rotated Wire 2D.

symmetry(line)[source]#

TODO: code this.

to_3d(plane_origin, x, y)[source]#

Transforms a Wire2D into an Wire3D, given a plane origin and an u and v plane vector.

Parameters:
  • plane_origin – plane origin.

  • x – plane u vector.

  • y – plane v vector.

Returns:

Wire3D.

translation(offset: Vector2D)[source]#

Translates the Wire 2D.

Parameters:

offset – translation vector

Returns:

A new translated Wire 2D.

validate_edge_crossings(crossings)[source]#

Validates the crossings points from an edge and a wire.

Parameters:

crossings – list of crossing points found.

Returns:

list of valid crossing points.

validate_wire_crossing(crossing, current_wire_primitive, next_wire_primitive)[source]#

Validate the crossing point for the operation wire crossings.

Parameters:
  • crossing – crossing point.

  • current_wire_primitive – current wire primitive intersecting wire.

  • next_wire_primitive – next wire primitive intersecting wire.

Returns:

wire_crossings(wire)[source]#

Compute crossings between two wire 2d.

Parameters:

wire – volmdlr.wires.Wire2D

Returns:

crossing points: List[(volmdlr.Point2D)]

class volmdlr.wires.Wire3D(primitives: List[Primitive3D], color=None, alpha: float = 1.0, reference_path: str = '#', name: str = '')[source]#

Bases: WireMixin, PhysicalObject

A collection of simple primitives, following each other making a wire.

babylon_curves()[source]#

Gets babylonjs curves.

babylon_lines(points=None)[source]#

Returns the wire data in babylon format.

babylon_points()[source]#

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

property bounding_box#

Gets the wire 3D bounding box.

extrusion(extrusion_vector)[source]#

Extrudes a Wire 3D in a given direction.

Parameters:

extrusion_vector – extrusion vector used.

Returns:

A list of extruded faces.

frame_mapping(frame: Frame3D, side: str)[source]#

Changes frame_mapping and return a new Wire3D.

Parameters:
  • frame – frame used.

  • side – ‘old’ or ‘new’

get_primitives_2d(plane_origin, x, y)[source]#

Pass primitives to 2d.

Parameters:
  • plane_origin – plane origin.

  • x – vector u.

  • y – vector v.

Returns:

list of 2d primitives.

minimum_distance(wire2)[source]#

Gets minimum distance between two wires.

Parameters:

wire2 – other wire.

Returns:

point_distance(point)[source]#

Gets the distance from a point a Wire 3D object.

Parameters:

point – other point.

Returns:

the distance to wire and corresponding point.

rotation(center: Point3D, axis: Vector3D, angle: float)[source]#

Wire3D rotation.

Parameters:
  • center – rotation center.

  • axis – rotation axis.

  • angle – angle rotation.

Returns:

a new rotated Wire3D.

to_2d(plane_origin, x, y)[source]#

Transforms a Wire 3D into a Wire 2D, given a plane origin and an x and y vector.

to_bspline(discretization_parameter, degree)[source]#

Convert a wire 3d to a bspline curve 3d.

to_step(current_id, *args, **kwargs)[source]#

Converts the object to a STEP representation.

Parameters:

current_id (int) – The ID of the last written primitive.

Returns:

The STEP representation of the object and the last ID.

Return type:

tuple[str, list[int]]

triangulation()[source]#

Triangulation method for a Wire3D.

class volmdlr.wires.WireMixin[source]#

Bases: object

Abstract class for Wire, storing methods and attributes used by many classes in this module.

abscissa(point, tol: float = 1e-06)[source]#

Compute the curvilinear abscissa of a point on a wire.

discretization_points(*, number_points: int | None = None, angle_resolution: int = 20)[source]#
Parameters:

angle_resolution – distance between two discretized points.

edge_intersections(edge, abs_tol: float = 1e-06)[source]#

Compute intersections between a wire (2D or 3D) and an edge (2D or 3D).

Parameters:

edge – edge to compute intersections.

classmethod extract(contour, point1, point2, inside=False, name: str = '')[source]#

Extracts a wire from another contour/wire, given two points.

extract_with_points(point1: Point2D, point2: Point2D, inside: bool = True)[source]#

Extract primitives between two given points.

Parameters:

point1 – extraction point 1.

:param point2:extraction point2. :param inside: If True it’ll Extract primitives from smaller point abscissa value to greater point abscissa value. If False, it’ll return the contour primitives going from the greater point abscissa value to the smaller one.

classmethod from_circle(circle, name: str = '')[source]#

Creates a Contour from a circle.

Parameters:
  • circle – Circle.

  • name – object’s name.

Returns:

classmethod from_edge(edge, number_segments: int, name: str = '')[source]#

Creates a Wire object from an edge.

Parameters:
  • edge – edge used to create Wire.

  • number_segments – number of segment for the wire to have.

  • name – object’s name.

Returns:

Wire object.

classmethod from_points(points, name: str = '')[source]#

Create a contour from points with line_segments.

classmethod from_wires(wires, name: str = '')[source]#

Define a wire from successive wires.

get_connected_wire(list_wires)[source]#

Searches a wire in list_contour connected to self.

Parameters:

list_wires – list of wires.

Returns:

invert()[source]#

Gets the wire in the inverted direction.

inverted_primitives()[source]#

Invert wire’s primitives.

is_followed_by(wire_2, tol=1e-06)[source]#

Check if the wire is followed by wire_2.

is_ordered(tol=1e-06)[source]#

Check if the wire’s primitives are ordered or not.

is_primitive_section_over_wire(primitive, tol: float = 1e-06)[source]#

Verifies if primitive’s section is over wire.

Parameters:
  • primitive – primitive to be verified.

  • tol – tolerance to be considered.

Returns:

True or False

is_sharing_primitives_with(contour, abs_tol: float = 1e-06)[source]#

Check if two contour are sharing primitives.

is_superposing(contour2, abs_tol: float = 1e-06)[source]#

Check if the contours are superposing (one on the other without necessarily having an absolute equality).

length()[source]#

Returns the wire’s length.

middle_point()[source]#

Gets the middle point of a contour.

Returns:

middle point.

order_wire(tol=1e-06)[source]#

Order wire’s primitives.

ordering_primitives(tol: float = 1e-06)[source]#

Ordering wire / contour primitives.

Parameters:

tol – tolerance.

Returns:

plot(ax=None, edge_style=EdgeStyle(color='k', alpha=1, edge_ends=False, edge_direction=False, width=None, arrow=False, plot_points=False, dashed=True, linestyle='-', linewidth=1, equal_aspect=True))[source]#

Wire plot using Matplotlib.

point_at_abscissa(curvilinear_abscissa: float)[source]#

Gets the point corresponding to given abscissa.

point_belongs(point, abs_tol=1e-06)[source]#

Verifies if point is on a wire.

Parameters:
  • point – point to be verified.

  • abs_tol – tolerance to be considered.

Returns:

True or False

primitive_over_wire(primitive, tol: float = 1e-06)[source]#

Verifies if primitive is over wire.

Parameters:
  • primitive – primitive to be verified.

  • tol – tolerance to be considered.

Returns:

True or False

sort_points_along_wire(points)[source]#

Sort given points along the wire with respect to the abscissa.

split_with_sorted_points(sorted_points)[source]#

Split contour in various sections using a list of sorted points along the contour.

Parameters:

sorted_points – sorted list of points.

Returns:

list of Contour sections.

split_with_two_points(point1, point2, abs_tol: float = 1e-06)[source]#

Split a wire or contour in two points.

Parameters:
  • point1 – splitting point1.

  • point2 – splitting point2.

  • abs_tol – tolerance used.

Returns:

List of primitives in between these two points, and another list with the remaining primitives.

to_dict(*args, **kwargs)[source]#

Avoids storing points in memo that makes serialization slow.

to_wire_with_linesegments(number_segments: int)[source]#

Convert a wire with different primitives to a wire with just line segments by discretizing primitives.

Parameters:

number_segments (int) – number of segment for each primitive to be converted.

wire_intersections(wire, abs_tol: float = 1e-06)[source]#

Compute intersections between two wire 2d.

Parameters:

wire – volmdlr.wires.Wire2D

classmethod wires_from_edges(list_edges, tol=1e-06, name: str = '')[source]#

Defines a list of wires from edges, by ordering successive edges.

Parameters:
  • list_edges (List[edges.Edge]) – A list of edges

  • tol (float, optional) – A tolerance, defaults to 1e-6

  • name – object’s name.

Returns:

A list of wires

Return type:

List[wires.WireMixin]

volmdlr.wires.argmax(list_of_numbers)[source]#

Returns the max value and the argmax.

volmdlr.wires.argmin(list_of_numbers)[source]#

Returns the minimum value from a list of numbers and its index.

volmdlr.wires.bounding_rectangle_adjacent_contours(contours: List)[source]#

Compute the bounding box of a list of adjacent contours 2d.

Parameters:

contours (List[volmdlr.wires.Contour2D]) – A list of adjacent contours

Returns:

The bounding box

Return type:

volmdlr.core.BoundingRectangle

volmdlr.wires.reorder_contour3d_edges_from_step(raw_edges, step_data)[source]#

Helper function to order edges from a 3D contour coming from a step file.