Wires¶
Module containing wires & contours.
- class design3d.wires.ClosedPolygon2D(points: List[Point2D], name: str = '')[source]¶
Bases:
ClosedPolygonMixin
,Contour2D
A collection of points, connected by line segments, following each other.
- barycenter()[source]¶
Calculates the geometric center of the polygon, which is the average position of all the points in it.
- Return type:
design3d.Point2D
- 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: 'design3d.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.
- delaunay_triangulation()[source]¶
Triangulate a closed polygon 2d using delaunay algorithm.
- Returns:
delaunay triangles.
- get_closing_point(polygon2_2d, primitive, ax=None)[source]¶
Gets sewing closing points for given primitive points.
- 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
- 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
- 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[design3d.edges.LineSegment2D, None], Union[design3d.edges.LineSegment2D, None]]
- 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:
d3dd.Mesh2D
- class design3d.wires.ClosedPolygon3D(points: List[Point3D], name: str = '')[source]¶
Bases:
Contour3D
,ClosedPolygonMixin
A collection of points, connected by line segments, following each other.
- 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.
- 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.
- static fix_sewing_normals(triangles, reference_linesegment)[source]¶
Fixes sewing triangle normal so it faces always outwards.
- 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.
- class design3d.wires.ClosedPolygonMixin[source]¶
Bases:
object
Abstract class for ClosedPolygon, storing methods used by ClosedPolygon2D and ClosedPolygon3D.
- property line_segments¶
Polygon line segments.
- class design3d.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
- center_of_mass()[source]¶
Calculates the center of mass of the Contour2D.
- Returns:
Contour’s center of mass.
- 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.
- 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 – design3d.wires.Wire2D
wire – design3d.wires.Wire2D.
- Return type:
list[design3d.wires.Contour2D]
- Returns:
contours2d : list[design3d.wires.Contour2D].
- discretized_contour(n: float)[source]¶
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, 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, y_density: float = None, min_points_x: int = 20, min_points_y: int = 20, number_points_x: int = None, number_points_y: int = 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.
- 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:
design3d.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
- class design3d.wires.Contour3D(primitives: List[Primitive3D], reference_path: str = '#', name: str = '')[source]¶
Bases:
ContourMixin
,Wire3D
A collection of 3D primitives forming a closed wire3D.
- property bounding_box¶
Gets bounding box value.
- Returns:
Bounding Box.
- contour_intersection(contour3d)[source]¶
Calculates 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)[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:
- 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.
- class design3d.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 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.
- 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
- 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
#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, 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:
- class design3d.wires.EdgeCollection3D(primitives: List[Edge], color=None, alpha=1, name: str = '')[source]¶
Bases:
WireMixin
A collection of simple edges 3D.
- property bounding_box¶
Get big bounding box of all edges.
- class design3d.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 design3d.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
- 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
- class design3d.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 design3d.wires.Wire2D(primitives, reference_path: str = '#', name: str = '')[source]¶
Bases:
WireMixin
A collection of simple primitives, following each other making a wire.
- 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:
design3d.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 design3d.core.BoundingRectangle object.
- Returns:
The bounding rectangle of the wire.
- Return type:
design3d.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 design3d.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)
- 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.
- rotation(center: Point2D, angle: float)[source]¶
Rotates the wire 2D.
- Parameters:
center – rotation center.
angle – angle rotation.
- Returns:
a new rotated Wire 2D.
- 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:
- class design3d.wires.Wire3D(primitives: List[Primitive3D], color=None, alpha: float = 1.0, reference_path: str = '#', name: str = '')[source]¶
Bases:
WireMixin
A collection of simple primitives, following each other making a wire.
- 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.
- class design3d.wires.WireMixin[source]¶
Bases:
DataEqualityObject
Abstract class for Wire, storing methods and attributes used by many classes in this module.
- discretization_points(*, number_points: int = 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.
- get_connected_wire(list_wires)[source]¶
Searches a wire in list_contour connected to self.
- Parameters:
list_wires – list of wires.
- Returns:
- 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).
- 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_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 – design3d.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]
- design3d.wires.argmin(list_of_numbers)[source]¶
Returns the minimum value from a list of numbers and its index.
- design3d.wires.bounding_rectangle_adjacent_contours(contours: List)[source]¶
Compute the bounding box of a list of adjacent contours 2d.
- Parameters:
contours (List[
design3d.wires.Contour2D
]) – A list of adjacent contours- Returns:
The bounding box
- Return type: