Subpackage utils#

volmdlr.utils.common_operations module#

Concatenate common operation for two or more objects.

volmdlr.utils.common_operations.ellipse_abscissa_angle_integration(ellipse3d, point_abscissa, angle_start, initial_angle)[source]#

Calculates the angle for a given abscissa point by integrating the ellipse.

Parameters:
  • ellipse3d – the Ellipse3D.

  • point_abscissa – the given abscissa for given point.

  • angle_start – Ellipse3D / ArcEllipse3D start angle. (0 for Ellipse3D).

  • initial_angle – angle abscissa’s initial value.

Returns:

final angle abscissa’s value.

volmdlr.utils.common_operations.generic_minimum_distance(self, element, point1_edge1_, point2_edge1_, point1_edge2_, point2_edge2_, return_points=False)[source]#

Gets the minimum distance between two elements.

This is a generalized method in a case an analytical method has not yet been defined.

Parameters:
  • element – other element.

  • return_points – Weather to return the corresponding points or not.

Returns:

distance to edge.

volmdlr.utils.common_operations.get_abscissa_discretization(primitive, abscissa1, abscissa2, max_number_points: int = 10, return_abscissas: bool = True)[source]#

Gets n discretization points between two given points of the edge.

Parameters:
  • primitive – Primitive to discretize locally.

  • abscissa1 – Initial abscissa.

  • abscissa2 – Final abscissa.

  • max_number_points – Expected number of points to discretize locally.

  • return_abscissas – By default, returns also a list of abscissas corresponding to the discretization points

Returns:

list of locally discretized point and a list containing the abscissas’ values.

volmdlr.utils.common_operations.get_center_of_mass(list_points)[source]#

Gets the center of mass of a given list of points.

Parameters:

list_points – list of points to get the center of mass from.

Returns:

center of mass point.

volmdlr.utils.common_operations.get_plane_equation_coefficients(plane_frame)[source]#

Returns the a,b,c,d coefficient from equation ax+by+cz+d = 0.

volmdlr.utils.common_operations.get_plane_point_distance(plane_frame, point3d)[source]#

Gets distance between a point and plane, using its frame.

Parameters:
  • plane_frame – plane’s frame.

  • point3d – other point.

Returns:

point plane distance.

volmdlr.utils.common_operations.get_point_distance_to_edge(edge, point, start, end)[source]#

Calculates the distance from a given point to an edge.

Parameters:
  • edge – Edge to calculate distance to point.

  • point – Point to calculate the distance to edge.

  • start – Edge’s start point.

  • end – Edge’s end point.

Returns:

distance to edge.

volmdlr.utils.common_operations.minimum_distance_points_circle3d_linesegment3d(circle3d, linesegment3d)[source]#

Gets the points from the arc and the line that gives the minimal distance between them.

Parameters:
  • circle3d – Circle 3d or Arc 3d.

  • linesegment3d – Other line segment 3d.

Returns:

Minimum distance points.

volmdlr.utils.common_operations.order_points_list_for_nearest_neighbor(points)[source]#

Given a list of unordered points defining a path, it will order these points considering the nearest neighbor.

volmdlr.utils.common_operations.plot_circle(circle, 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]#

Create a Matplotlib plot for a circle 2d or fullarc 2d.

Parameters:
  • circle – circle to plot.

  • ax – Matplotlib plot axis.

  • edge_style – Edge Style to implement.

Returns:

Matplotlib plot axis.

volmdlr.utils.common_operations.plot_components_from_points(points, close_plot: bool = False)[source]#

Gets Matplotlib components from points.

Parameters:
  • points – given points.

  • close_plot – Weather to close the plot or not.

Returns:

volmdlr.utils.common_operations.plot_from_discretization_points(ax, edge_style, element, number_points: int | None = None, close_plot: bool = False)[source]#

General plot method using discretization_points method to generate points.

Parameters:
  • ax – Matplotlib plot.

  • edge_style – edge_style to be applied to plot.

  • element – volmdlr element to be plotted (either 2D or 3D).

  • number_points – number of points to be used in the plot.

  • close_plot – specifies if plot is to be closed or not.

Returns:

Matplotlib plot axis.

volmdlr.utils.common_operations.random_color()[source]#

Random color generator.

volmdlr.utils.common_operations.separate_points_by_closeness(points)[source]#

Separates a list of 3D Cartesian points into two groups based on their spatial closeness using DBSCAN.

This function applies the DBSCAN (Density-Based Spatial Clustering of Applications with Noise) algorithm to the given list of 3D Cartesian points. DBSCAN clusters the points based on their spatial proximity. The points are separated into two groups, ‘group1’ and ‘group2’, depending on their spatial closeness as determined by the DBSCAN clustering.

Please note that the ‘eps’ parameter inside the function can be adjusted to control the closeness threshold.

Parameters:

points – A list of 3D Cartesian points, where each point is represented as a list of three coordinates.

Returns:

  • group1 (list of lists): The first group of points based on their closeness.

  • group2 (list of lists): The second group of points based on their closeness.

volmdlr.utils.common_operations.split_wire_by_plane(wire, plane3d)[source]#

Splits a wire into two parts using a plane.

This method splits a wire into two parts based on the intersection points between the wire’s primitives (edges) and a given 3D plane. It first finds the intersection points between each primitive and the plane, excluding duplicate points. Then, it checks if the number of intersection points is greater than one. If so, it raises a NotImplementedError, as the split is ambiguous. Otherwise, it performs the split using the split_with_sorted_points method of the wire object. The resulting wire objects are returned as a tuple. Note: The method assumes that the wire and the plane are in the same coordinate system.

Parameters:
  • wire – The wire object to be split.

  • plane3d – The 3D plane object used for splitting the wire.

Returns:

A tuple containing two wire objects resulting from the split.

Raises:

NotImplementedError: If the wire intersects the plane at more than one point.

Example:

>>> from volmdlr import Point3D, Vector3D
>>> from volmdlr.surfaces import Plane3D
>>> from volmdlr.core import EdgeStyle
>>> from volmdlr.utils.common_operations import random_color
>>> from volmdlr.models.open_rounded_line_segments import open_rounded_line_segements
>>> plane = Plane3D.from_plane_vectors(Point3D(0.4, 0.4, 0.2), Vector3D(1, 0, 0), Vector3D(0, 1, 0))
>>> split_wire1,split_wire2 = split_wire_by_plane(open_rounded_line_segements, plane)
>>> ax = open_rounded_line_segements.plot()
>>> plane.plot(ax)
>>> split_wire1.plot(ax, EdgeStyle(random_color()))
>>> split_wire2.plot(ax, EdgeStyle(random_color()))

volmdlr.utils.intersections module#

volmdlr utils for calculating curves intersections.

volmdlr.utils.intersections.bspline_intersections_initial_conditions(primitive, bsplinecurve, resolution: float = 100, recursion_iteration=0)[source]#

Gets the initial conditions to calculate intersections between a bspline curve 2d and another edge 2d.

Parameters:
  • primitive – primitive to verify intersection with bspline

  • bsplinecurve – bsplinecurve to search for intersections.

  • resolution – bspline discretization resolution, to search for initial intersection conditions.

  • recursion_iteration – parameter to count recursions.

Returns:

a list with all initial sections where there may exist an intersection.

volmdlr.utils.intersections.circle_3d_line_intersections(circle_3d, line, abs_tol: float = 1e-06)[source]#

Calculates the intersections between a Circle3D and a Line3D.

Parameters:
  • circle_3d – Circle3D or Arc3D

  • line – Line3D to verify intersections

  • abs_tol – Tolerance.

Returns:

list of points intersecting Circle

volmdlr.utils.intersections.conic3d_line_intersections(conic3d, line3d, abs_tol: float = 1e-06)[source]#

Calculates the intersections between an Ellipse3D and a Line3D.

Parameters:
  • conic3d – The Hyperbola 3D.

  • line3d – The Line 3D.

  • abs_tol – Tolerance.

Returns:

list of points intersecting the Hyperbola 3D.

volmdlr.utils.intersections.conic_intersections(conic1, conic2, abs_tol: float = 1e-06)[source]#

Gets intersections between a two conic curves 3D.

Parameters:
  • conic1 – First conic curve 3D.

  • conic2 – Other conic curve 3D.

  • abs_tol – tolerance.

Returns:

A list of points, containing all intersections between the Line 3D and the Parabola3D.

volmdlr.utils.intersections.ellipse2d_line_intersections(ellipse2d, line2d, abs_tol: float = 1e-06)[source]#

Calculates the intersections between a line and an ellipse.

Parameters:
  • ellipse2d – Ellipse to calculate intersections

  • line2d – line to calculate intersections

  • abs_tol – tolerance.

Returns:

list of points intersections, if there are any

volmdlr.utils.intersections.get_bsplinecurve_intersections(primitive, bsplinecurve, abs_tol: float = 1e-06)[source]#

Calculates the intersections between a primitive and a BSpline Curve.

This method calculates the intersections between a given primitive and a BSpline Curve. The primitive can be any edge type or a plane3D. It first determines the initial intersection conditions using the bspline_intersections_initial_conditions function. Then, it iteratively checks for intersections by discretizing the BSpline Curve and checking for intersections with line segments. It maintains a list of intersections and validates each intersection against the specified tolerance. The method continues until there are no more intersection conditions to process. The resulting intersections are returned as a list.

Parameters:

primitive – The primitive object to verify intersection with the BSpline Curve.

It can be any edge type or a plane3D. :param bsplinecurve: The BSpline Curve object to search for intersections. :param abs_tol: The tolerance to be considered while validating an intersection.

Returns:

A list with all intersections between the edge and BSpline Curve.

Return type:

[volmdlr.Point3D].

volmdlr.utils.intersections.get_circle_intersections(circle1, circle2)[source]#

Calculates the intersections between two circle 2d.

Parameters:
  • circle1 – circle 1 verify intersection with bspline

  • circle2 – circle 2 to search for intersections.

Returns:

a list with all intersections between the two circles.

volmdlr.utils.intersections.get_planar_circle3d_line_intersections(circle_3d, line, abs_tol: float = 1e-07)[source]#

Calculates the intersections between a coplanar Circle3D and Line3D.

Parameters:
  • circle_3d – Circle3D or Arc3D

  • line – Line3D to verify intersections

  • abs_tol – Tolerance.

Returns:

list of points intersecting Circle

volmdlr.utils.intersections.get_plane_line_intersections(plane_frame, line, abs_tol: float = 1e-06)[source]#

Find the intersection with a line.

Parameters:
  • plane_frame – the plane’s frame.

  • line (edges.Line.) – Line to evaluate the intersection

  • abs_tol (float.) – tolerance.

Returns:

ADD DESCRIPTION

Return type:

List[volmdlr.Point3D]

volmdlr.utils.intersections.get_plane_linesegment_intersections(plane_frame, linesegment, abs_tol: float = 1e-06)[source]#

Gets the intersections of a plane a line segment 3d.

Parameters:
  • plane_frame – the plane’s frame.

  • linesegment – other line segment.

  • abs_tol – tolerance allowed.

Returns:

a list with the intersecting point.

volmdlr.utils.intersections.get_two_planes_intersections(plane1_frame, plane2_frame, abs_tol=1e-08)[source]#

Calculates the intersections between two planes, given their frames.

Parameters:
  • plane1_frame – Plane’s 1 frame.

  • plane2_frame – Plane’s 2 frame.

  • abs_tol – tolerance.

Returns:

A list containing two points that define an infinite line if there is any intersections,

or an empty list if the planes are parallel.

volmdlr.utils.parametric module#

volmdlr utils for calculating 3D to surface parametric domain operation.

volmdlr.utils.parametric.angle_discontinuity(angle_list)[source]#

Returns True if there is some angle discontinuity in the angle_list.

This discontinuity can occur when we transform some 3D primitive into the parametric domain of periodical surfaces.

Parameters:

angle_list (List[float]) – List with angle axis values of the primitive in parametric domain.

Returns:

Returns True if there is discontinuity, False otherwise.

Return type:

bool

volmdlr.utils.parametric.arc3d_to_cylindrical_coordinates_verification(start_end, start_end_theta_state, reference_points, discontinuity)[source]#

Verifies theta from start and end of an Arc3D after transformation from spatial to parametric coordinates.

volmdlr.utils.parametric.arc3d_to_spherical_coordinates_verification(start_end, reference_points, discontinuity)[source]#

Verifies theta and phi from start and end of an arc 3D after transformation from spatial to parametric coordinates.

volmdlr.utils.parametric.arc3d_to_toroidal_coordinates_verification(start_end, start_end_angles_state, reference_points, discontinuity)[source]#

Verifies theta and phi from start and end of an arc 3D after transformation from spatial to parametric coordinates.

Find the indices of the elements in the sorted list x that fall within the specified range.

This function use bisect python builtin module, which uses binary search and has a time complexity of O(log(n)). Where n is the array length.

Parameters:
  • x (list) – A sorted list of values.

  • xmin (float) – The minimum value in the range.

  • xmax (float) – The maximum value in the range.

Returns:

A python range from the first to the last elements in x.

Return type:

range

Example:

>>> array = [1, 2, 3, 4, 5]
>>> array_range_search(array, 2, 4)
range(1, 3)
volmdlr.utils.parametric.contour2d_healing(contour2d)[source]#

Heals topologies incoherencies on the boundary representation.

volmdlr.utils.parametric.contour2d_healing_close_gaps(contour2d, contour3d)[source]#

Heals topologies incoherencies on the boundary representation.

volmdlr.utils.parametric.contour2d_healing_self_intersection(contour2d)[source]#

Heals topologies incoherencies on the boundary representation.

volmdlr.utils.parametric.find_index_defined_brep_primitive_on_periodical_surface(primitives2d, periodicity)[source]#

Search for a primitive on the boundary representation that can be used as reference for repairing the contour.

volmdlr.utils.parametric.find_parametric_point_at_singularity(edge, abscissa, singularity_line, domain)[source]#

Uses tangent line to find real theta angle of the singularity point on parametric domain.

volmdlr.utils.parametric.find_sign_changes(list_of_values)[source]#

Finds the position of sign changes in a list.

Parameters:

list_of_values (list) – The list to search for sign changes.

Returns:

A list of indices where the sign changes occur.

Return type:

list

volmdlr.utils.parametric.fullarc_to_cylindrical_coordinates_verification(start, end, normal_dot_product)[source]#

Verifies theta from start and end of a full arc after transformation from spatial to parametric coordinates.

volmdlr.utils.parametric.is_isocurve(points, tol: float = 1e-06)[source]#

Test if the parametric points of the edge fits into a line segment.

volmdlr.utils.parametric.is_undefined_brep_primitive(primitive, periodicity)[source]#

2D primitives on parametric surface domain can be in wrong bound side due to periodic behavior of some surfaces.

A B-Rep primitive can be undefined when it’s not directly provided, but it’s found by some 3D to 2D operation. This can result in a primitive that is entirely contained on the periodical boundary, and we can only know its right position when it’s placed on the boundary representation, by analyzing the continuity of the 2D contour.

Parameters:
  • primitive (vme.Edge) – primitive to perform verification.

  • periodicity (list) – list with periodicity in x and y direction

volmdlr.utils.parametric.repair_arc3d_angle_continuity(angle_start, angle_end, periodicity)[source]#

Repairs Arc3D continuity after conversion of points to parametric 2D space.

volmdlr.utils.parametric.repair_singularity(primitive, last_primitive)[source]#

Repairs the Contour2D of SphericalSurface3D and ConicalSurface3D parametric face representations.

Used when transforming from spatial to parametric coordinates when the surface contains a singularity

volmdlr.utils.parametric.repair_start_end_angle_periodicity(angle, ref_angle)[source]#

Repairs start and end angles in parametric coordinates.

Uses ref_angle (angle just after start angle, if repairing start angle or angle just before end if repairing end

angle).

Parameters:
  • angle (float) – Angle to repair.

  • ref_angle – Angle of reference.

Returns:

Returns the repaired angle.

Return type:

float

volmdlr.utils.parametric.repair_undefined_brep(surface, primitives2d, primitives_mapping, i, previous_primitive)[source]#

Helper function to repair_primitives_periodicity.

volmdlr.utils.parametric.spherical_repair_start_end_angle_periodicity(start, end, point_after_start, point_before_end)[source]#

Verifies theta and phi from start and end of an arc 3D after transformation from spatial to parametric coordinates.

volmdlr.utils.parametric.toroidal_repair_start_end_angle_periodicity(start, end, start_end_angles_state, point_after_start, point_before_end)[source]#

Verifies theta and phi from start and end of an arc 3D after transformation from spatial to parametric coordinates.

volmdlr.utils.parametric.update_face_grid_points_with_inner_polygons(inner_polygons, grid_points_data)[source]#

Remove grid_points inside inner contours of the face.

volmdlr.utils.parametric.verify_repeated_parametric_points(points)[source]#

Verify repeated parametric points from point3d_to_2d method.

volmdlr.utils.step_writer module#

volmdlr utils for translating volmdlr primitives into step file entity.

volmdlr.utils.step_writer.assembly_definition_writer(current_id, assembly_data, component_data, assembly_frame_id, component_frame_id)[source]#

Returns component assembly data.

volmdlr.utils.step_writer.geometric_context_writer(current_id, uncertainty: float = 0.0001)[source]#

Helper function to write the step definitions of a product.

volmdlr.utils.step_writer.product_writer(current_id, product_name)[source]#

Helper function to write the step definitions of a product.

volmdlr.utils.step_writer.step_ids_to_str(ids)[source]#

Returns a string with a ‘#’ in front of each ID and a comma separating each-one.

Parameters:

ids (List[int]) – A list of step primitives IDs

Returns:

A string containing all the IDs

Return type:

str