Wires#
Module containing wires & contours.
- class volmdlr.wires.ClosedPolygon2D(points: list[Point2D], name: str = '')#
Bases:
ClosedPolygonMixin,Contour2DA collection of points, connected by line segments, following each other.
- area()#
Return the area of the polygon.
- barycenter()#
Calculate the geometric center of the polygon, which is the average position of all the points in it.
- Return type:
volmdlr.Point2D
- classmethod concave_hull(points: list[Point2D], concavity: float, scale_factor: float, name: str = '')#
Calculate 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: list[Point2D], name: str = '')#
Use the scipy method ConvexHull to calculate the convex hull from a cloud of points.
- copy(*args, **kwargs)#
Return a copy of the object.
- delaunay_triangulation()#
Triangulate a closed polygon 2d using delaunay algorithm.
- Returns:
delaunay triangles.
- get_closing_point(polygon2_2d: ClosedPolygon2D, primitive: LineSegment2D, ax=None)#
Get sewing closing points for given primitive points.
- get_line_segments()#
Get polygon lines.
- get_possible_sewing_closing_points(polygon2: ClosedPolygon2D, polygon_primitive: LineSegment2D, line_segment1: LineSegment2D | None = None, line_segment2: LineSegment2D | None = None)#
Search all possibles closing points available for the given primitive.
- get_valid_sewing_polygon_primitive(polygon2_2d: ClosedPolygon2D)#
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)#
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()#
Verify 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: Point2D)#
Find closing point for the sewing method using intersection of lines drawn from the barycenter.
returns the closing point.
- offset(offset: float)#
Offsets a polygon 2d edges from a distance.
- Parameters:
offset – offset distance.
- Returns:
- plot(ax=None, edge_style: EdgeStyle | None = None, point_numbering: bool = False, fill: bool = False, fill_color: str = 'w')#
Matplotlib plot for a closed polygon 2D.
- point_border_distance(point: Point2D, return_other_point: bool = False)#
Compute the distance to the border distance of polygon.
Output is always positive, even if the point belongs to the polygon.
- point_in_polygon()#
In case the barycenter of the polygon is outside, this method finds another point inside the polygon.
- point_inside(point: Point2D, include_edge_points: bool = False, tol: float = 1e-06)#
Ray casting algorithm copied from internet.
- classmethod points_convex_hull(points, name: str = '')#
Create a convex hull from a collection of 2D points.
- points_in_polygon(points: list[Point2D], include_edge_points: bool = False, tol: float = 1e-06)#
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#
Return the minimum distance to other given polygon.
- rotation(center: Point2D, angle: float)#
ClosedPolygon2D rotation.
- Parameters:
center – rotation center
angle – angle rotation
- Returns:
a new rotated ClosedPolygon2D
- search_ear(remaining_points: list[Point2D], initial_point_to_index: Point2D)#
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(intersecting_point: Point2D, possible_closing_points: list[Point2D])#
Choose 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
- select_closest_sewing_closing_point(line_segment: LineSegment2D, polygon_primitive: LineSegment2D, possible_closing_points: list[Point2D])#
Search the closest sewing closing point available.
- select_farthest_sewing_closing_point(line_segment: LineSegment2D, polygon_primitive: LineSegment2D, possible_closing_points: list[Point2D])#
Search the closest sewing closing point available.
- self_intersects()#
Determine 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)#
Simplify polygon.
- to_3d(plane_origin: Point2D, x: Vector2D, y: Point2D)#
Transform 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)#
ClosedPolygon2D translation.
- Parameters:
offset – translation vector
- Returns:
A new translated ClosedPolygon2D
- triangulation(tri_opt: str = 'p')#
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 = '')#
Bases:
Contour3D,ClosedPolygonMixinA collection of points, connected by line segments, following each other.
- check_sewing(polygon2: ClosedPolygon3D, sewing_faces: list[list[Point3D]])#
Check the consistency of sewing between two polygons.
This method verifies the consistency of the sewing process between the current polygon and another specified polygon. It compares the total number of line segments from both polygons with the length of the list of sewing faces to ensure they match.
- Parameters:
polygon2 (ClosedPolygon3D) – The other polygon to check sewing consistency with.
sewing_faces (list[list[Point3D]]) – The list of sewing faces representing the sewn polygons.
- Returns:
True if the sewing is consistent, False otherwise.
- Return type:
bool
- static clean_sewing_closing_pairs_dictionary(dict_closing_pairs: dict, closing_point_index: int, passed_by_zero_index: bool)#
Clean 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: dict)#
Close sewing resulting triangles.
- concave_sewing(polygon2: ClosedPolygon3D, x: Vector3D, y: Vector3D)#
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 – The x-direction of the projection plane.
y – 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: ClosedPolygon3D, x: Vector3D, y: Vector3D)#
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)#
Return a copy of the object.
- static fix_sewing_normals(triangles: list[list[Point3D]], reference_linesegment: LineSegment3D)#
Fix sewing triangle normal so it faces always outwards.
- get_line_segments()#
Get polygon lines.
- get_valid_concave_sewing_polygon(polygon1_2d: ClosedPolygon2D, polygon2_2d: ClosedPolygon2D)#
Determine a valid concave sewing polygon based on the 2D projections of two polygons.
This method calculates a valid concave sewing polygon for further sewing operations, based on the provided 2D projections of two polygons. It identifies the valid primitive segment from the first polygon (polygon1_2d) with respect to the second polygon (polygon2_2d), and rearranges the segments of the current polygon accordingly.
- Parameters:
polygon1_2d (ClosedPolygon2D) – The 2D projection of the first polygon.
polygon2_2d (ClosedPolygon2D) – The 2D projection of the second polygon.
- Returns:
A valid concave sewing polygon for further operations.
- Return type:
- static is_sewing_forward(closing_point_index: int, list_closing_point_indexes: list[int]) bool#
Check if the sewing process is moving forward based on the closing point index.
This static method determines whether the sewing process is moving forward based on the closing point index and the list of closing point indexes. It compares the current closing point index with the last index in the list to ascertain the direction of sewing.
- Parameters:
closing_point_index (int) – The index of the current closing point.
list_closing_point_indexes (list[int]) – The list of closing point indexes.
- Returns:
True if the sewing process is moving forward, False otherwise.
- Return type:
bool
- redefine_sewing_triangles_points(triangles_points: list[Point3D], passed_by_zero_index: bool, closing_point_index: int, previous_closing_point_index: int)#
Redefines the points of triangles based on specific conditions during sewing.
This method adjusts the points of triangles based on certain conditions encountered during the sewing process. It iterates through the list of triangles and modifies their points if they meet the specified criteria related to the closing point index, previous closing point index, and the direction of traversal.
- Parameters:
triangles_points (list[list[Point3D]]) – The list of triangles’ points representing the sewn polygons.
passed_by_zero_index (bool) – A flag indicating whether the sewing has passed by the zero index.
closing_point_index (int) – The index of the closing point on the polygon.
previous_closing_point_index (int) – The index of the previous closing point on the polygon.
- Returns:
The adjusted list of triangles’ points after redefinition.
- Return type:
list[list[Point3D]]
- rotation(center: Point3D, axis: Vector3D, angle: float)#
ClosedPolygon3D rotation.
- Parameters:
center – rotation center.
axis – rotation axis.
angle – angle rotation.
- Returns:
a new rotated ClosedPolygon3D.
- sewing(polygon2: ClosedPolygon3D, x: Vector3D, y: Vector3D)#
Sew two polygon3D together.
- Parameters:
polygon2 – The other polygon to sew with.
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: int, list_closing_point_indexes: list[int], passed_by_zero_index: bool, ratio_denominator: float)#
Choose sewing closing point when point index passes through zero index again.
- static sewing_closing_points_to_remove(closing_point_index: int, list_closing_point_indexes: list[int], passed_by_zero_index: bool)#
Determine the closing points to remove during the sewing process.
This static method identifies the closing points that need to be removed during the sewing process based on the current closing point index, the list of closing point indexes, and the flag indicating whether the sewing process has passed by zero index.
- Parameters:
closing_point_index (int) – The index of the current closing point.
list_closing_point_indexes (list[int]) – The list of closing point indexes.
passed_by_zero_index (bool) – A flag indicating if the sewing has passed by the zero index.
- Returns:
The list of closing points to be removed.
- Return type:
list[int]
- simplify(min_distance: float = 0.01, max_distance: float = 0.05)#
Simplifies polygon 3d.
- Parameters:
min_distance – minimal allowed distance.
max_distance – maximal allowed distance.
- Returns:
Simplified closed polygon 3d.
- to_2d(plane_origin: Point3D, x: Vector3D, y: Vector3D)#
Transform 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)#
ClosedPolygon3D translation.
- Parameters:
offset – translation vector.
- Returns:
A new translated ClosedPolygon3D.
- static validate_concave_closing_point(closing_point_index: int, list_closing_point_indexes: list[int], passed_by_zero_index: bool, ratio_denominator: float, polygons_points_ratio: float)#
Validate concave closing point.
- class volmdlr.wires.ClosedPolygonMixin#
Bases:
objectAbstract class for ClosedPolygon, storing methods used by ClosedPolygon2D and ClosedPolygon3D.
- edge_statistics()#
Return polygon statistics.
- get_lengths()#
Get line segment lengths.
- get_line_segments()#
Abstract method.
- invert()#
Invert the polygon.
- length()#
Polygon length.
- Returns:
polygon length.
- property line_segments#
Polygon line segments.
- max_length()#
Get the minimal length for a line segment in the polygon.
- min_length()#
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)#
Simplify polygon.
- class volmdlr.wires.Contour2D(primitives: list[Edge], reference_path: str = '#', name: str = '')#
Bases:
ContourMixin,Wire2DA 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()#
Return the area of the contour.
- bounding_points()#
Bounding points (x_min, y_min) (x_max, y_max).
- center_of_mass()#
Calculate the center of mass of the Contour2D.
- Returns:
Contour’s center of mass.
- centroid()#
Get the centroid of a closed polygon 2d.
- clean_primitives()#
Delete primitives with start=end, and return a new contour.
- closest_point_to_point2(point2: Point2D)#
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)#
A specified copy of a Contour2D.
- cut_by_bspline_curve(bspline_curve2d: BSplineCurve2D)#
Cut a contour 2d with bspline_curve 2d to define two different contours.
- cut_by_line(line: Line2D) list[Contour2D]#
- Parameters:
line – The line used to cut the contour.
- Returns:
A list of resulting contours
- cut_by_wire(wire: Wire2D)#
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:
list[volmdlr.wires.Contour2D].
- discretized_contour(n: float)#
Discretize each contour’s primitive and return a new contour with these discretized primitives.
- 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: float, x_max: float, y_min: float, y_max: float, name: str = '')#
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)#
Get divided contours.
- get_furthest_point_to_point2(point2: Point2D)#
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)#
Compute a triangulation using an n-by-m grid to triangulate the contour.
- intersection_contour_with(other_contour: Contour2D, abs_tol: float = 1e-06)#
Get 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: Contour2D)#
Return the intersections points with other specified contour.
- is_edge_inside(edge: LineSegment2D, abs_tol: float = 1e-06)#
Verify 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: Contour2D)#
Verify 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: Contour2D)#
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)#
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.
- point_inside(point: Point2D, include_edge_points: bool = False, tol: float = 1e-06)#
Verify 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)#
Find 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, name: str = '')#
Create 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.
name (str) – (Optional) Allows to assign a name to the object.
- Returns:
Contour2D
- classmethod rectangle_from_center_and_sides(center, x_length, y_length, is_trigo: bool = True, name: str = '')#
Create a rectangular contour given a center and a side.
- repair_cut_contour(n, intersections, line)#
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)#
Return the second moment of are of the contour.
- split_regularly(n)#
Split in n slices.
- to_3d(plane_origin: Point3D, x: Vector3D, y: Vector3D)#
Transform 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()#
Return the triangulation of the contour 2d.
- class volmdlr.wires.Contour3D(primitives: list[Primitive3D], reference_path: str = '#', name: str = '')#
Bases:
ContourMixin,Wire3DA collection of 3D primitives forming a closed wire3D.
- average_center_point()#
Return the average center point.
- property bounding_box#
Gets bounding box value.
- Returns:
Bounding Box.
- clean_primitives()#
Delete primitives with start=end, and return a new contour.
- contour_intersection(contour3d: Contour3D)#
Calculate intersections between two Contour3D.
- Parameters:
contour3d – second contour
- Returns:
list of points
- 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:
- frame_mapping(frame: Frame3D, side: str)#
Change frame_mapping and return a new Contour3D.
side = ‘old’ or ‘new’.
- classmethod from_step(arguments, object_dict, **kwargs)#
Convert 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:
- line_intersections(line: Line3D)#
Calculate 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)#
Calculate 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: Contour3D, abs_tol: float = 1e-06)#
Merge two adjacent contours, and returns one outer contour and inner contours (if there are any).
- rotation(center: Point3D, axis: Vector3D, angle: float)#
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#
Convert 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)#
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]].
- class volmdlr.wires.ContourMixin#
Bases:
WireMixinAbstract class for Contour, storing methods and attributes used by Contour2D and Contour3D.
- are_extremity_points_touching(wire: WireMixin)#
Verify 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: float = 1e-06, name: str = 'r')#
Create an ordered contour given a list of unordered edges.
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.
Delete shared primitives between two adjacent contours.
- Parameters:
contour – other contour.
abs_tol – tolerance.
- Returns:
Two list of new primitives for both contours, without those shared by both contours.
- discretized_primitives(number_points: float)#
Discretize each contour’s primitive and return a list of discretized primitives.
- edges_order_with_adjacent_contour(contour: ContourMixin)#
Check two adjacent coutours edges order.
Check if the shared edges between two adjacent contours are traversed with two different directions along each contour.
- extremities_points(list_p)#
Return extremities points of a list of points on a contour.
- classmethod from_points(points, name: str = '')#
Create a contour from points with line_segments.
- get_geo_lines(tag: int, primitives_tags: list[int])#
Get 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()#
Get points in geo file format.
- invert()#
Invert the Contour.
- is_adjacent(contour: ContourMixin)#
Check if two contour are adjacent.
So: are sharing primitives but not superposing or none is inside the other.
- is_connected()#
Return True if all connected edges share the same vertex and False otherwise.
- is_contour_closed()#
Verify if contour is closed or not.
- Returns:
True if closed, False if Open.
- is_ordered(tol: float = 1e-06)#
Verify 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)#
Check if the contours are overlapping (a part of one is on the other).
- is_wire_connected()#
Return True if all connected edges share the same vertex and False otherwise.
This a special case for degenerated contours found in parametric space or in boolean operations.
- merge_primitives_with(contour)#
Extract not shared primitives between two adjacent contours, to be merged.
- Parameters:
contour
- Returns:
- order_contour(tol: float = 1e-06)#
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)#
Verify if the entire primitive is over a contour.
- primitive_section_over_contour(primitive, abs_tol: float = 1e-06)#
Verify if at least a small section of a primitive is over a contour, not necessarily the entire primitive.
- reorder_contour_at_point(point)#
Create a new contour from self, but starting at given point.
- Parameters:
point – other point.
- Returns:
new contour
#todo: is this description correct?.
Extract shared primitives extremities between two adjacent contours.
Extract shared primitives between two adjacent contours.
Checks if two contour share primitives.
- to_polygon(angle_resolution: int, discretize_line: bool = False, discretize_line_direction: str = 'xy')#
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:
- class volmdlr.wires.EdgeCollection3D(primitives: list[Edge], color=None, alpha: float = 1.0, reference_path: str = '#', name: str = '')#
Bases:
WireMixin,Primitive3DA collection of simple edges 3D.
- babylon_meshes(**kwargs)#
Set the mesh for babylonjs.
- babylon_param()#
Get dict for babylonjs object settings.
- babylon_points()#
Get list of points coordinates.
- property bounding_box#
Get big bounding box of all edges.
- points()#
Get list of all points.
- to_babylon()#
Generate a mesh from all edges for performance when drawing.
- class volmdlr.wires.Triangle(point1, point2, point3, name: str = '')#
Bases:
ClosedPolygonMixinDefines 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 = '')#
Bases:
Triangle,ClosedPolygon2DDefines a triangle 2D.
- Parameters:
point1 – triangle point 1.
point2 – triangle point 2.
point3 – triangle point 3.
- area()#
Calculate the area of the triangle.
- Returns:
Area of the triangle.
- Return type:
float
- aspect_ratio()#
Calculate the aspect ratio of the triangle.
- Returns:
Aspect ratio of the triangle.
- Return type:
float
- circumcircle_radius()#
Calculate the radius of the circumscribed circle (circumcircle) of the triangle.
- Returns:
Radius of the circumscribed circle.
- Return type:
float
- incircle_radius()#
Calculate the radius of the inscribed circle (incircle) of the triangle.
- Returns:
Radius of the inscribed circle.
- Return type:
float
- ratio_circumr_length()#
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()#
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 = '')#
Bases:
TriangleDefines a triangle 3D.
- class volmdlr.wires.Wire2D(primitives: list[Edge], reference_path: str = '#', name: str = '')#
Bases:
WireMixin,DessiaObjectA collection of simple primitives, following each other making a wire.
- area()#
Get the area for a Wire2D.
- axial_symmetry(line: LineSegment2D)#
Find 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)#
Get the wire primitives crossings with the bsplinecurve.
Returns a list of crossings in the form of a tuple (point, primitive).
- bsplinecurve_intersections(bsplinecurve: BSplineCurve2D)#
Find intersections between the wire primitives and the B-spline curve.
- Parameters:
bsplinecurve – the B-spline curve to find intersections with
- Returns:
list of intersections in the form of a tuple (point, primitive)
- edge_crossings(edge)#
Find valid crossing points between the edge and wire primitives.
- Parameters:
edge – the edge to find crossings with the wire
- Returns:
list of valid crossing points
- extend(point: Point2D)#
Extend a wire by adding a line segment connecting the given point to the nearest wire’s extremities.
- frame_mapping(frame: Frame2D, side: str)#
Change frame_mapping and return a new Wire 2D.
side = ‘old’ or ‘new’
- get_bouding_rectangle()#
Calculate 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)#
Return 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: list[Point2D], primitive)#
Return 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: Wire2D)#
Verify 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)#
Return 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)#
Check if the two wires 2d are symmetric or not according to line.
- line_crossings(line: Line2D)#
Calculate 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)#
Return a list of intersection of the wire primitives intersecting with the line.
- Returns:
a tuple (point, primitive)
- linesegment_crossings(linesegment: LineSegment2D)#
Get the wire primitives intersecting with the line.
Returns a list of crossings in the form of a tuple (point, primitive).
- linesegment_intersections(linesegment: LineSegment2D)#
Return a list of intersection of the wire primitives intersecting with the line segment.
- Returns:
a tuple (point, primitive)
- offset(offset: float)#
Generate an offset of a Wire2D.
- plot_data(edge_style: EdgeStyle | None = None, surface_style: SurfaceStyle | None = None)#
Plot 2D representation of the contour.
- point_distance(point: Point2D)#
Calculate the minimum distance between the wire and a given point.
- Parameters:
point – the point to calculate the distance from
- Returns:
the minimum distance between the wire and the point
- rotation(center: Point2D, angle: float)#
Rotatesthe wire 2D.
- Parameters:
center – rotation center.
angle – angle rotation.
- Returns:
a new rotated Wire 2D.
- symmetry(line)#
TODO: code this.
- to_3d(plane_origin, x, y)#
Transform 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)#
Translate the Wire 2D.
- Parameters:
offset – translation vector
- Returns:
A new translated Wire 2D.
- validate_edge_crossings(crossings: list[Point2D])#
Validate 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: Point2D, current_wire_primitive, next_wire_primitive)#
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:
- class volmdlr.wires.Wire3D(primitives: list[Primitive3D], color=None, alpha: float = 1.0, reference_path: str = '#', name: str = '')#
Bases:
WireMixin,DessiaObjectA collection of simple primitives, following each other making a wire.
- babylon_curves()#
Get babylonjs curves.
- babylon_lines(points=None)#
Return the wire data in babylon format.
- babylon_points()#
Returns a list of discretization points from the 3D primitive.
- property bounding_box#
Gets the wire 3D bounding box.
- property display_color: tuple[float, float, float]#
Get the color for display (custom color or default).
- extrusion(extrusion_vector: Vector3D)#
Extrude 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)#
Change frame_mapping and return a new Wire3D.
- Parameters:
frame – frame used.
side – ‘old’ or ‘new’
- get_primitives_2d(plane_origin: Point3D, x: Vector3D, y: Vector3D)#
Projects primitives onto a 2D plane.
- Parameters:
plane_origin – origin of the plane.
x – vector u.
y – vector v.
- Returns:
list of 2D primitives.
- property has_custom_color: bool#
Check if this object has a custom color set.
- property has_transparency: bool#
Check if this object has transparency (alpha < 1.0).
- minimum_distance(wire2: Wire3D)#
Get minimum distance between two wires.
- Parameters:
wire2 – other wire.
- Returns:
- point_distance(point: Point3D)#
Get 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)#
Wire3D rotation.
- Parameters:
center – rotation center.
axis – rotation axis.
angle – angle rotation.
- Returns:
a new rotated Wire3D.
- to_2d(plane_origin: Point3D, x: Vector3D, y: Vector3D)#
Transform a Wire 3D into a Wire 2D, given a plane origin and an x and y vector.
- to_bspline(discretization_parameter, degree)#
Convert a wire 3d to a bspline curve 3d.
- to_step(current_id, *args, **kwargs)#
Convert 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()#
Triangulation method for a Wire3D.
- class volmdlr.wires.WireMixin#
Bases:
Displayable3DAbstract class for Wire, storing methods and attributes used by many classes in this module.
- abscissa(point, tol: float = 1e-06) float#
Compute the curvilinear abscissa of a point on a wire.
- babylon_data(show_curves: bool = False, **kwargs) dict#
Return the babylonjs data for display.
- cad_view#
Implementation of a tag for displays.
- discretization_points(*, number_points: int | None = None, angle_resolution: int = 20)#
- Parameters:
angle_resolution – distance between two discretized points.
- edge_intersections(edge, abs_tol: float = 1e-06)#
Compute intersections between a wire (2D or 3D) and an edge (2D or 3D).
- Parameters:
edge – edge to compute intersections.
abs_tol – tolerance.
- classmethod extract(contour, point1, point2, inside=False, abs_tol: float = 1e-06, name: str = '')#
Extract a wire from another contour/wire, given two points.
- extract_with_points(point1: Point2D, point2: Point2D, inside: bool = True)#
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 = '')#
Create a Contour from a circle.
- Parameters:
circle – Circle.
name – object’s name.
- Returns:
- classmethod from_edge(edge, number_segments: int, name: str = '')#
Create 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_ocp(occt_wire: TopoDS_Shape)#
Instantiates a volmdlr wire, from occt object.
- classmethod from_points(points, name: str = '')#
Create a contour from points with line_segments.
- classmethod from_wires(wires, name: str = '')#
Define a wire from successive wires.
- get_connected_wire(list_wires)#
Search a wire in list_contour connected to self.
- Parameters:
list_wires – list of wires.
- Returns:
- invert()#
Get the wire in the inverted direction.
- inverted_primitives()#
Inverts each primitive of the wire.
- Returns:
list of inverted primitives
- is_followed_by(wire_2, tol=1e-06)#
Check if the wire is followed by wire_2.
- is_ordered(tol=1e-06) bool#
Check if the wire’s primitives are ordered or not.
- is_primitive_section_over_wire(primitive, tol: float = 1e-06) bool#
Verify 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) bool#
Check if two contour are sharing primitives.
- is_superposing(contour2, abs_tol: float = 1e-06)#
Check if the contours are superposing (one on the other without necessarily having an absolute equality).
- length() float#
Return the wire’s length.
- middle_point()#
Get the middle point of a contour.
- Returns:
middle point.
- static order_primitives(primitives, tol: float = 1e-06)#
Ordering wire / contour primitives.
- Parameters:
primitives – primitives.
tol – tolerance.
- Returns:
- order_wire(tol=1e-06)#
Order wire’s primitives.
- ordering_primitives(tol: float = 1e-06)#
Get contour/wires ordered primitives.
- plot_data_primitives(edge_style: EdgeStyle | None = None, surface_style: SurfaceStyle | None = None) list[PlotDataObject]#
Get list of plot_data primitives representing self.
- point_at_abscissa(curvilinear_abscissa: float)#
Get the point corresponding to given abscissa.
- point_belongs(point, abs_tol=1e-06) bool#
Verify 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) bool#
Verify if primitive is over wire.
- Parameters:
primitive – primitive to be verified.
tol – tolerance to be considered.
- Returns:
True or False
- scale(factor: float, origin: Point3D | Point2D | None = None) Any#
Perform a scale transformation on the shape.
- Parameters:
factor – The scaling value.
origin – The center of the scale.
- Returns:
A new transformed shape.
- sort_points_along_wire(points)#
Sort given points along the wire with respect to the abscissa.
- split_with_sorted_points(sorted_points)#
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.
- to_dict(*args, **kwargs)#
Avoid storing points in memo that makes serialization slow.
- to_ocp()#
Return an OCP shape equivalent to the volmdlr object.
- to_wire_with_linesegments(number_segments: int)#
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.
- trim(point1, point2, abs_tol: float = 1e-06)#
Trims a wire or contour between 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.
- wire_intersections(wire, abs_tol: float = 1e-06)#
Compute intersections between two wire 2d.
- Parameters:
wire – volmdlr.wires.Wire2D
abs_tol – tolerance.
- classmethod wires_from_edges(list_edges, tol=1e-06, name: str = '')#
Define 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]
- property wrapped#
Gets OCP wrapped object.
- volmdlr.wires.argmax(list_of_numbers)#
Returns the max value and the argmax.
- volmdlr.wires.argmin(list_of_numbers)#
Returns the minimum value from a list of numbers and its index.
- volmdlr.wires.bounding_rectangle_adjacent_contours(contours)#
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.wires.reorder_contour3d_edges_from_step(raw_edges, step_data)#
Helper function to order edges from a 3D contour coming from a step file.