Primitives¶
Primitives¶
Common abstract primitives.
- class design3d.primitives.RoundedLineSegments(points: List[Point3D], radius: Dict[str, float], closed: bool = False, adapt_radius: bool = False, reference_path: str = '#', name: str = '')[source]¶
Bases:
object
Rounded Line Segments class.
- frame_mapping(frame: Frame3D, side: str)[source]¶
Changes frame_mapping and return a new RoundedLineSegments.
side = ‘old’ or ‘new’
- line_class¶
alias of
LineSegment
Primitives2d¶
Extended primitives 2D classes.
- class design3d.primitives2d.ClosedRoundedLineSegments2D(points: List[Point2D], radius: Dict[int, float], adapt_radius: bool = False, reference_path: str = '#', name: str = '')[source]¶
Bases:
RoundedLineSegments2D
,Contour2D
Defines a polygon with some rounded corners.
- Parameters:
points (List of Point2D) – Points used to draw the wire
radius ({position1(n): float which is the radius linked the n-1 and n+1 points, position2(n+1):...}) – Radius used to connect different parts of the wire
- class design3d.primitives2d.Measure2D(point1, point2, label='', unit: str = 'mm', type_: str = 'distance')[source]¶
Bases:
LineSegment2D
Measure 2D class.
- Parameters:
unit – ‘mm’, ‘m’ or None. If None, the distance won’t be in the label.
- class design3d.primitives2d.OpenedRoundedLineSegments2D(points: List[Point2D], radius: Dict[int, float], adapt_radius: bool = False, reference_path: str = '#', name: str = '')[source]¶
Bases:
RoundedLineSegments2D
,Wire2D
Opened Rounded LineSegment2D class.
- Parameters:
points (List of Point2D.) – Points used to draw the wire.
radius ({position1(n): float which is the radius linked the n-1 and n+1 points, position2(n+1):...}.) – Radius used to connect different parts of the wire.
- class design3d.primitives2d.RoundedLineSegments2D(points: List[Point2D], radius: Dict[int, float], adapt_radius: bool = False, reference_path: str = '#', name: str = '')[source]¶
Bases:
RoundedLineSegments
A class representing a series of rounded line segments in 2D.
This class inherits from the RoundedLineSegments class, and provides methods to work with rounded line segments in 2D.
- Parameters:
points (List[design3d.Point2D]) – The list of points defining the line segments.
radius – The dictionary mapping segment indices to their respective radii.
:type radius:Dict[int, float] :param adapt_radius: Flag indicating whether to adapt the radius based on segment length. Defaults to False. :type adapt_radius: bool, optional :param name: The name of the rounded line segments. Defaults to ‘’. :type name: str, optional
- get_offset_new_points(line_indexes, offset, distance_dir1, distance_dir2, directive_vector1, directive_vector2, normal_vectors)[source]¶
Get Offset new points.
- get_offset_normal_vectors(line_indexes)[source]¶
Gets offset normal vectors.
- Parameters:
line_indexes
- Returns:
A list of consecutive line indexes.
- line_class¶
alias of
LineSegment2D
- offset(offset)[source]¶
Return a new rounded line segment with the specified offset.
This method creates a new rounded line segment by offsetting the current one by a given distance. The offset can be both positive and negative, moving the line segments outward or inward.
- Parameters:
offset (float) – The offset distance for the new rounded line segment.
- Returns:
A new RoundedLineSegments2D instance with the specified offset.
- Return type:
- offset_lines(line_indexes, offset)[source]¶
Line indexes is a list of consecutive line indexes.
These line should all be aligned line_indexes = 0 being the 1st line.
if self.close last line_index can be len(self.points)-1 if not, last line_index can be len(self.points)-2
Primitives3d¶
Common primitives 3D.
- class design3d.primitives3d.BSplineExtrusion(obj, vectorextru: Vector3D, reference_path: str = '#', name: str = '')[source]¶
Bases:
Primitive3D
Defines the extrusion of a BSpline.
- Parameters:
vectorextru – extrusion vector.
- classmethod from_step(arguments, object_dict, **kwargs)[source]¶
Converts a step primitive to a BSplineExtrusion.
- Parameters:
arguments (list) – The arguments of the step primitive. The last element represents the unit_conversion_factor.
object_dict (dict) – The dictionary containing all the step primitives that have already been instantiated.
- Returns:
The corresponding BSplineExtrusion object.
- Return type:
- class design3d.primitives3d.Block(frame: Frame3D, *, color: Tuple[float, float, float] = None, alpha: float = 1.0, reference_path: str = '#', name: str = '')[source]¶
Bases:
ClosedShell3D
Creates a block.
- Parameters:
frame – a frame 3D. The origin of the frame is the center of the block, the 3 vectors are defining the edges. The frame has not to be orthogonal
- cut_by_orthogonal_plane(plane_3d: Plane3D)[source]¶
Cuts Block by orthogonal plane, and return a plane face at this plane, bounded by the block volume.
- frame_mapping(frame: Frame3D, side: str)[source]¶
Changes frame_mapping and return a new Frame3D.
- Parameters:
side – ‘old’ or ‘new’
- classmethod from_bounding_box(bounding_box: BoundingBox, name: str = '')[source]¶
Create a block from a bounding box.
- Parameters:
bounding_box (BoundingBox) – the bounding box sued to create the block.
name (str) – the name of the block, optional.
- Returns:
the created block.
- Return type:
- get_bounding_box() BoundingBox [source]¶
Get the bounding box of the block.
- Returns:
the created bounding box.
- Return type:
- rotation(center: Point3D, axis: Vector3D, angle: float)[source]¶
Block rotation.
- Parameters:
center – rotation center
axis – rotation axis
angle – angle rotation
- Returns:
a new rotated Block
- subdivide_block(number_blocks_x, number_blocks_y, number_blocks_z)[source]¶
Divide block into sub blocks.
- class design3d.primitives3d.ClosedRoundedLineSegments3D(points: List[Point3D], radius: float, adapt_radius: bool = False, name: str = '')[source]¶
Bases:
RoundedLineSegments3D
,Contour3D
Defines a closed rounded line segment in 3D.
- Parameters:
points (List of Point3D) – Points used to draw the wire
radius ({position1(n): float which is the radius linked the n-1 and) – Radius used to connect different parts of the wire
n+1 points, position2(n+1):…}
- class design3d.primitives3d.Cone(frame: Frame3D, radius: float, length: float, color: Tuple[float, float, float] = None, alpha: float = 1.0, reference_path: str = '#', name: str = '')[source]¶
Bases:
ClosedShell3D
Represents a 3D cone defined by its frame, radius, and length.
- classmethod from_center_point_and_axis(center_point: Point3D, axis: Vector3D, radius: float, length: float, color: Tuple[float, float, float] = None, alpha: float = 1, reference_path: str = '#', name: str = '') Cone [source]¶
Create a cone from a center point, an axis, radius, and length.
- Parameters:
center_point (design3d.Point3D) – The center point of the cone (i.e. the middle point of the axis of the cone).
axis (design3d.Vector3D) – The axis of revolution for the cone.
radius (float) – The radius of the cone.
length (float) – The length of the cone.
color (Tuple[float, float, float], optional) – The color of the cone as an RGB tuple. Default is None.
alpha (float, optional) – The opacity of the cone (0.0 to 1.0). Default is 1.0.
reference_path (str) – A path corresponding to the “location” of the equivalent python object in the overall structure. “#/path/to/displayed_object”
name (str, optional) – The name of the cone. Default is an empty string.
- Returns:
A Cone instance created from the specified center point, axis, radius, and length.
- Return type:
- get_bounding_box() BoundingBox [source]¶
Compute the bounding box of the cone.
A is the point at the basis. B is the top.
- Returns:
The BoundingBox of the Cone.
- Return type:
- rotation(center: Point3D, axis: Vector3D, angle: float) Cone [source]¶
Cone rotation.
- Parameters:
center (design3d.Point3D) – The rotation center.
axis (design3d.Vector3D) – The rotation axis.
angle (float) – The angle of rotation.
- Returns:
A new rotated Cone.
- Return type:
- class design3d.primitives3d.Cylinder(frame: Frame3D, radius: float, length: float, color: Tuple[float, float, float] = None, alpha: float = 1.0, reference_path: str = '#', name: str = '')[source]¶
Bases:
ClosedShell3D
Represents a 3D cylinder defined by its frame, radius, and length.
- copy(deep=True, memo=None) Cylinder [source]¶
Creates a copy of Cylinder.
- Returns:
A copy of a current Cylinder.
- Return type:
- frame_mapping(frame: Frame3D, side: str) Cylinder [source]¶
Changes frame_mapping and return a new Frame3D.
side = ‘old’ or ‘new’
- classmethod from_center_point_and_axis(center_point: Point3D, axis: Vector3D, radius: float, length: float, color: Tuple[float, float, float] = None, alpha: float = 1, reference_path: str = '#', name: str = '') Cylinder [source]¶
Create a cylinder from a center point, an axis, radius, and length.
- Parameters:
center_point (design3d.Point3D) – The center point of the cylinder (i.e. the middle point of the axis of the cylinder).
axis (design3d.Vector3D) – The axis of revolution for the cylinder.
radius (float) – The radius of the cylinder.
length (float) – The length of the cylinder.
color (Tuple[float, float, float], optional) – The color of the cylinder as an RGB tuple. Default is None.
alpha (float, optional) – The opacity of the cylinder (0.0 to 1.0). Default is 1.0.
reference_path (str) – A path corresponding to the “location” of the equivalent python object in the overall structure. “#/path/to/displayed_object”
name (str, optional) – The name of the cylinder. Default is an empty string.
- Returns:
A Cylinder instance created from the specified center point, axis, radius, and length.
- Return type:
- classmethod from_end_points(point1: Point3D, point2: Point3D, radius: float, color: Tuple[float, float, float] = None, alpha: float = 1, reference_path: str = '#', name: str = '')[source]¶
Create a cylinder from two end points.
- Parameters:
point1 (design3d.Point3D) – The first end point defining the base of the cylinder.
point2 (design3d.Point3D) – The second end point defining the top of the cylinder.
radius (float) – The radius of the cylinder.
color (Tuple[float, float, float], optional) – The color of the cylinder as an RGB tuple. Default is None.
alpha (float, optional) – The opacity of the cylinder (0.0 to 1.0). Default is 1.0.
reference_path (str) – A path corresponding to the “location” of the equivalent python object in the overall structure. “#/path/to/displayed_object”
name (str, optional) – The name of the cylinder. Default is an empty string.
- Returns:
A Cylinder instance created from the specified end points.
- Return type:
- classmethod from_extremal_points(point1: Point3D, point2: Point3D, radius: float, color: Tuple[float, float, float] = None, alpha: float = 1, reference_path: str = '#', name: str = '')[source]¶
Deprecated class method. Use ‘from_end_points’ instead.
- get_bounding_box() BoundingBox [source]¶
Computes the bounding box of a cylinder.
- Returns:
The BoundingBox of the Cylinder.
- Return type:
- interference_volume_with_other_cylinder(other_cylinder: Cylinder, n_points: int = 1000) float [source]¶
Estimation of the interpenetration volume using LHS sampling (inspired by Monte-Carlo method).
- Parameters:
other_cylinder (Cylinder) – The other cylinder to compute the interference volume with.
n_points (int) – Optional parameter used for the number of random point used to discretize the cylinder
- Returns:
An estimation of the interference volume.
- Return type:
float
- is_intersecting_other_cylinder(other_cylinder: Cylinder) bool [source]¶
Verifies if two cylinders are intersecting or not.
- Parameters:
other_cylinder (Cylinder) – The other cylinder to compute if there is an intersection with.
- Returns:
True if cylinders are intersecting, False otherwise
- Return type:
bool
- lhs_points_inside(n_points: int) List[Point3D] [source]¶
Returns some points inside the cylinder from a LHS samplings.
- Parameters:
n_points (int) – The number of points to generate.
- Returns:
The Latin Hypercube Sampling points inside the cylinder.
- Return type:
list[design3d.Point3D]
- min_distance_to_other_cylinder(other_cylinder: Cylinder) float [source]¶
Compute the minimal distance between two design3d cylinders.
- Parameters:
other_cylinder (Cylinder) – The other cylinder to compute the distance with.
- Returns:
The minimal distance between the two 3D cylinders.
- Return type:
float
- point_belongs(point3d: Point3D, **kwargs) bool [source]¶
Check if the point belongs to the cylinder.
- Parameters:
point3d (design3d.Point3D) – The point to check if it’s the cylinder.
- Returns:
True if the given point is inside the cylinder, False otherwise.
- Return type:
bool
- random_point_inside() Point3D [source]¶
Return a random point inside a cylinder.
- Returns:
a random point inside the Cylinder
- Return type:
design3d.Point3D
- rotation(center: Point3D, axis: Vector3D, angle: float) Cylinder [source]¶
Cylinder rotation.
- Parameters:
center (design3d.Point3D) – The rotation center.
axis (design3d.Vector3D) – The rotation axis.
angle (float) – The angle of rotation.
- Returns:
A new rotated Cylinder.
- Return type:
- class design3d.primitives3d.ExtrudedProfile(frame: Frame3D, outer_contour2d: Contour2D, inner_contours2d: List[Contour2D], extrusion_length: float, color: Tuple[float, float, float] = None, alpha: float = 1.0, reference_path: str = '#', name: str = '')[source]¶
Bases:
ClosedShell3D
Extrude a profile given by outer and inner contours.
TODO: In the future change to a frame and a surface2D and an extrusion vector.
- frame_mapping(frame: Frame3D, side: str)[source]¶
Changes frame_mapping and return a new ExtrudeProfile.
- Parameters:
side – = ‘old’ or ‘new’.
- rotation(center: Point3D, axis: Vector3D, angle: float)[source]¶
Extruded Profile rotation.
- Parameters:
center – rotation center.
axis – rotation axis.
angle – angle rotation.
- Returns:
a new rotated ExtrudedProfile.
- class design3d.primitives3d.HollowCylinder(frame: Frame3D, inner_radius: float, outer_radius: float, length: float, color: Tuple[float, float, float] = None, alpha: float = 1, reference_path: str = '#', name: str = '')[source]¶
Bases:
ClosedShell3D
Represents a 3D hollow cylinder defined by its frame, radii, and length.
- copy(*args, **kwargs) HollowCylinder [source]¶
Creates a copy of HollowCylinder.
- Returns:
A copy of a current HollowCylinder.
- Return type:
- frame_mapping(frame: Frame3D, side: str) HollowCylinder [source]¶
Changes frame_mapping and return a new HollowCylinder.
side = ‘old’ or ‘new’.
- classmethod from_center_point_and_axis(center_point: Point3D, axis: Vector3D, inner_radius: float, outer_radius: float, length: float, color: Tuple[float, float, float] = None, alpha: float = 1, reference_path: str = '#', name: str = '') HollowCylinder [source]¶
Create a hollow cylinder from a center point, an axis, radius, and length.
- Parameters:
center_point (design3d.Point3D) – The center point of the hollow cylinder (i.e. the middle point of the axis of the hollow cylinder).
axis (design3d.Vector3D) – The axis of revolution for the hollow cylinder.
inner_radius (float) – The inner radius of the hollow cylinder.
outer_radius (float) – The outer radius of the hollow cylinder.
length (float) – The length of the hollow cylinder.
color (Tuple[float, float, float], optional) – The color of the hollow cylinder as an RGB tuple. Default is None.
alpha (float, optional) – The opacity of the hollow cylinder (0.0 to 1.0). Default is 1.0.
reference_path (str) – A path corresponding to the “location” of the equivalent python object in the overall structure. “#/path/to/displayed_object”
name (str, optional) – The name of the hollow cylinder. Default is an empty string.
- Returns:
A HollowCylinder instance created from the specified center point, axis, radii, and length.
- Return type:
- classmethod from_end_points(point1: Point3D, point2: Point3D, inner_radius: float, outer_radius: float, color: Tuple[float, float, float] = None, alpha: float = 1, reference_path: str = '#', name: str = '')[source]¶
Create a hollow cylinder from two end points.
- Parameters:
point1 (design3d.Point3D) – The first end point defining the base of the hollow cylinder.
point2 (design3d.Point3D) – The second end point defining the top of the hollow cylinder.
inner_radius (float) – The inner radius of the hollow cylinder.
outer_radius (float) – The outer radius of the hollow cylinder.
color (Tuple[float, float, float], optional) – The color of the hollow cylinder as an RGB tuple. Default is None.
alpha (float, optional) – The opacity of the hollow cylinder (0.0 to 1.0). Default is 1.0.
reference_path (str) – A path corresponding to the “location” of the equivalent python object in the overall structure. “#/path/to/displayed_object”
name (str, optional) – The name of the hollow cylinder. Default is an empty string.
- Returns:
A HollowCylinder instance created from the specified end points.
- Return type:
- classmethod from_extremal_points(point1: Point3D, point2: Point3D, inner_radius: float, outer_radius: float, color: Tuple[float, float, float] = None, alpha: float = 1, reference_path: str = '#', name: str = '')[source]¶
Deprecated class method. Use ‘from_end_points’ instead.
- get_bounding_box() BoundingBox [source]¶
Computes the bounding box of a hollow cylinder.
- Returns:
The BoundingBox of the HollowCylinder.
- Return type:
- rotation(center: Point3D, axis: Vector3D, angle: float) HollowCylinder [source]¶
Hollow cylinder rotation.
- Parameters:
center (design3d.Point3D) – The rotation center.
axis (design3d.Vector3D) – The rotation axis.
angle (float) – The angle of rotation.
- Returns:
A new rotated HollowCylinder.
- Return type:
- translation(offset: Vector3D) HollowCylinder [source]¶
Hollow cylinder translation.
- Parameters:
offset (design3d.Vector3D) – The translation vector.
- Returns:
A new translated HollowCylinder.
- Return type:
- class design3d.primitives3d.Measure3D(point1: Point3D, point2: Point3D, color: Tuple[float, float, float] = (1.0, 0, 0))[source]¶
Bases:
object
Used to create a measure between two points in 3D.
- class design3d.primitives3d.OpenRoundedLineSegments3D(points: List[Point3D], radius: Dict[str, float], adapt_radius: bool = False, name: str = '')[source]¶
Bases:
Wire3D
,RoundedLineSegments3D
Defines an open rounded line segments.
- Parameters:
points (List of Point3D.) – Points used to draw the wire.
radius ({position1(n): float which is the radius linked the n-1 and.) – Radius used to connect different parts of the wire.
n+1 points, position2(n+1):…}
- class design3d.primitives3d.RevolvedProfile(frame: Frame3D, contour2d: Contour2D, axis_point: Point3D, axis: Vector3D, angle: float = 6.283185307179586, *, color: Tuple[float, float, float] = None, alpha: float = 1, reference_path: str = '#', name: str = '')[source]¶
Bases:
ClosedShell3D
Revolve a 2D profile along an axis around a certain angle.
- property contour3d¶
Gets the positionned contour for revolution.
- frame_mapping(frame: Frame3D, side: str)[source]¶
Changes frame_mapping and return a new Revolved Profile.
side = ‘old’ or ‘new’
- frame_mapping_parameters(frame: Frame3D, side: str)[source]¶
Apply transformation to object’s parameters.
- rotation(center: Point3D, axis: Vector3D, angle: float)[source]¶
Revolved profile rotation.
- Parameters:
center (design3d.Point3D) – rotation center
axis (design3d.Vector3D) – rotation axis
angle (float) – angle rotation
- Returns:
a new rotated Revolved Profile
- Return type:
Revolved Profile
- class design3d.primitives3d.RoundedLineSegments3D(points: List[Point3D], radius: Dict[str, float], adapt_radius: bool = False, name: str = '')[source]¶
Bases:
RoundedLineSegments
A class representing a series of rounded line segments in 3D.
This class inherits from the RoundedLineSegments class, and provides methods to work with rounded line segments in 3D.
- Parameters:
points (List[design3d.Point3D]) – The list of points defining the line segments.
radius – The dictionary mapping segment indices to their respective radii.
:type radius:Dict[int, float] :param adapt_radius: Flag indicating whether to adapt the radius based on segment length. Defaults to False. :type adapt_radius: bool, optional :param name: The name of the rounded line segments. Defaults to ‘’. :type name: str, optional
- line_class¶
alias of
LineSegment3D
- class design3d.primitives3d.Sphere(center: Point3D, radius: float, color: Tuple[float, float, float] = None, alpha: float = 1.0, reference_path: str = '#', name: str = '')[source]¶
Bases:
ClosedShell3D
Defines a sphere at a given position & radius.
- frame_mapping(frame: Frame3D, side: str)[source]¶
Changes frame_mapping and return a new Sphere.
- Parameters:
side – ‘old’ or ‘new’
- inner_points(resolution: float = 0.001)[source]¶
Gives points inside the sphere with a sub-sphere strategy.
- point_belongs(point3d: Point3D, **kwargs) bool [source]¶
Returns if the point belongs to the sphere.
- Parameters:
point3d – design3d Point3D
- Returns:
True if the given point is inside the sphere, False otherwise
- class design3d.primitives3d.Sweep(contour2d: Contour2D, wire3d: Wire3D, starting_frame=None, *, color: Tuple[float, float, float] = None, alpha: float = 1, reference_path: str = '#', name: str = '')[source]¶
Bases:
ClosedShell3D
Sweep a profile along a path.
The resulting shape is defined by a contour in 2D and a path with C1 continuity provided by the 3D wire. The starting frame defines the position and orientation of the profile in the 3D space.
- Parameters:
contour2d (design3d.wires.Contour2D) – The 2D contour, defining the profile to be swept along the wire.
wire3d (design3d.wires.Wire3D) – The 3D wire path along which the contour is swept. The path must be C1 continuous.
starting_frame (design3d.Frame3D) – (optional) The starting frame for the sweep. This parameter is used to control the orientation of the profile in 3D space. The frame’s origin should be coincident with the start of the path. If not provided, it is determined from the orientation of the wire and may provide unexpected sweep orientation, if the aspect ratio of the profile is different of 1.
color (Tuple[float, float, float]) – (optional) The RGB color of the resulting shell.
alpha (float) – (optional) The transparency of the resulting shell.
name (str) – The name of the sweep.
- frame_mapping(frame: Frame3D, side: str)[source]¶
Changes frame_mapping and return a new Sweep.
- Parameters:
frame – Frame to map.
side – ‘old’ or ‘new’