2828_N_SAMPLE_CURVE_SHAPELY = 40
2929
3030# for shapely circular shapes discretization in visualization
31- _N_SHAPELY_QUAD_SEGS = 200
31+ _N_SHAPELY_QUAD_SEGS_VISUALIZATION = 200
3232
3333# Default number of points to discretize polyslab in `Cylinder.to_polyslab()`
3434_N_PTS_CYLINDER_POLYSLAB = 51
@@ -71,7 +71,12 @@ def inside(
7171 return (dist_x ** 2 + dist_y ** 2 + dist_z ** 2 ) <= (self .radius ** 2 )
7272
7373 def intersections_tilted_plane (
74- self , normal : Coordinate , origin : Coordinate , to_2D : MatrixReal4x4
74+ self ,
75+ normal : Coordinate ,
76+ origin : Coordinate ,
77+ to_2D : MatrixReal4x4 ,
78+ cleanup : bool = True ,
79+ quad_segs : Optional [int ] = None ,
7580 ) -> list [Shapely ]:
7681 """Return a list of shapely geometries at the plane specified by normal and origin.
7782
@@ -83,6 +88,11 @@ def intersections_tilted_plane(
8388 Vector defining the plane origin.
8489 to_2D : MatrixReal4x4
8590 Transformation matrix to apply to resulting shapes.
91+ cleanup : bool = True
92+ If True, removes extremely small features from each polygon's boundary.
93+ quad_segs : Optional[int] = None
94+ Number of segments used to discretize circular shapes. If ``None``, uses
95+ ``_N_SHAPELY_QUAD_SEGS_VISUALIZATION`` for high-quality visualization.
8696
8797 Returns
8898 -------
@@ -91,6 +101,9 @@ def intersections_tilted_plane(
91101 For more details refer to
92102 `Shapely's Documentation <https://shapely.readthedocs.io/en/stable/project.html>`_.
93103 """
104+ if quad_segs is None :
105+ quad_segs = _N_SHAPELY_QUAD_SEGS_VISUALIZATION
106+
94107 normal = np .array (normal )
95108 unit_normal = normal / (np .sum (normal ** 2 ) ** 0.5 )
96109 projection = np .dot (np .array (origin ) - np .array (self .center ), unit_normal )
@@ -106,13 +119,18 @@ def intersections_tilted_plane(
106119 u /= np .sum (u ** 2 ) ** 0.5
107120 v = np .cross (unit_normal , u )
108121
109- angles = np .linspace (0 , 2 * np .pi , _N_SHAPELY_QUAD_SEGS * 4 + 1 )[:- 1 ]
122+ angles = np .linspace (0 , 2 * np .pi , quad_segs * 4 + 1 )[:- 1 ]
110123 circ = center + np .outer (np .cos (angles ), radius * u ) + np .outer (np .sin (angles ), radius * v )
111124 vertices = np .dot (np .hstack ((circ , np .ones ((angles .size , 1 )))), to_2D .T )
112125 return [shapely .Polygon (vertices [:, :2 ])]
113126
114127 def intersections_plane (
115- self , x : Optional [float ] = None , y : Optional [float ] = None , z : Optional [float ] = None
128+ self ,
129+ x : Optional [float ] = None ,
130+ y : Optional [float ] = None ,
131+ z : Optional [float ] = None ,
132+ cleanup : bool = True ,
133+ quad_segs : Optional [int ] = None ,
116134 ) -> list [BaseGeometry ]:
117135 """Returns shapely geometry at plane specified by one non None value of x,y,z.
118136
@@ -124,22 +142,30 @@ def intersections_plane(
124142 Position of plane in x direction, only one of x,y,z can be specified to define plane.
125143 z : float = None
126144 Position of plane in x direction, only one of x,y,z can be specified to define plane.
145+ cleanup : bool = True
146+ If True, removes extremely small features from each polygon's boundary.
147+ quad_segs : Optional[int] = None
148+ Number of segments used to discretize circular shapes. If ``None``, uses
149+ ``_N_SHAPELY_QUAD_SEGS_VISUALIZATION`` for high-quality visualization.
127150
128151 Returns
129152 -------
130153 List[shapely.geometry.base.BaseGeometry]
131154 List of 2D shapes that intersect plane.
132155 For more details refer to
133- `Shapely's Documentation <https://shapely.readthedocs.io/en/stable/project.html>`_ .
156+ `Shapely's Documentation <https://shapely.readthedocs.io/en/stable/project.html>`` .
134157 """
158+ if quad_segs is None :
159+ quad_segs = _N_SHAPELY_QUAD_SEGS_VISUALIZATION
160+
135161 axis , position = self .parse_xyz_kwargs (x = x , y = y , z = z )
136162 if not self .intersects_axis_position (axis , position ):
137163 return []
138164 z0 , (x0 , y0 ) = self .pop_axis (self .center , axis = axis )
139165 intersect_dist = self ._intersect_dist (position , z0 )
140166 if not intersect_dist :
141167 return []
142- return [shapely .Point (x0 , y0 ).buffer (0.5 * intersect_dist , quad_segs = _N_SHAPELY_QUAD_SEGS )]
168+ return [shapely .Point (x0 , y0 ).buffer (0.5 * intersect_dist , quad_segs = quad_segs )]
143169
144170 @cached_property
145171 def bounds (self ) -> Bound :
@@ -430,7 +456,11 @@ def _update_from_bounds(self, bounds: tuple[float, float], axis: Axis) -> Cylind
430456
431457 @verify_packages_import (["trimesh" ])
432458 def _do_intersections_tilted_plane (
433- self , normal : Coordinate , origin : Coordinate , to_2D : MatrixReal4x4
459+ self ,
460+ normal : Coordinate ,
461+ origin : Coordinate ,
462+ to_2D : MatrixReal4x4 ,
463+ quad_segs : Optional [int ] = None ,
434464 ) -> list [Shapely ]:
435465 """Return a list of shapely geometries at the plane specified by normal and origin.
436466
@@ -442,6 +472,9 @@ def _do_intersections_tilted_plane(
442472 Vector defining the plane origin.
443473 to_2D : MatrixReal4x4
444474 Transformation matrix to apply to resulting shapes.
475+ quad_segs : Optional[int] = None
476+ Number of segments used to discretize circular shapes. If ``None``, uses
477+ ``_N_SHAPELY_QUAD_SEGS_VISUALIZATION`` for high-quality visualization.
445478
446479 Returns
447480 -------
@@ -452,6 +485,9 @@ def _do_intersections_tilted_plane(
452485 """
453486 import trimesh
454487
488+ if quad_segs is None :
489+ quad_segs = _N_SHAPELY_QUAD_SEGS_VISUALIZATION
490+
455491 z0 , (x0 , y0 ) = self .pop_axis (self .center , self .axis )
456492 half_length = self .finite_length_axis / 2
457493
@@ -471,7 +507,7 @@ def _do_intersections_tilted_plane(
471507 r_bot = 0
472508 z_bot = z0 + self ._radius_z (z0 ) / self ._tanq
473509
474- angles = np .linspace (0 , 2 * np .pi , _N_SHAPELY_QUAD_SEGS * 4 + 1 )
510+ angles = np .linspace (0 , 2 * np .pi , quad_segs * 4 + 1 )
475511
476512 if r_bot > 0 :
477513 x_bot = x0 + r_bot * np .cos (angles )
@@ -525,13 +561,18 @@ def _do_intersections_tilted_plane(
525561 path , _ = section .to_2D (to_2D = to_2D )
526562 return path .polygons_full
527563
528- def _intersections_normal (self , z : float ) -> list [BaseGeometry ]:
564+ def _intersections_normal (
565+ self , z : float , quad_segs : Optional [int ] = None
566+ ) -> list [BaseGeometry ]:
529567 """Find shapely geometries intersecting cylindrical geometry with axis normal to slab.
530568
531569 Parameters
532570 ----------
533571 z : float
534572 Position along the axis normal to slab
573+ quad_segs : Optional[int] = None
574+ Number of segments used to discretize circular shapes. If ``None``, uses
575+ ``_N_SHAPELY_QUAD_SEGS_VISUALIZATION`` for high-quality visualization.
535576
536577 Returns
537578 -------
@@ -540,6 +581,8 @@ def _intersections_normal(self, z: float) -> list[BaseGeometry]:
540581 For more details refer to
541582 `Shapely's Documentation <https://shapely.readthedocs.io/en/stable/project.html>`_.
542583 """
584+ if quad_segs is None :
585+ quad_segs = _N_SHAPELY_QUAD_SEGS_VISUALIZATION
543586
544587 static_self = self .to_static ()
545588
@@ -550,7 +593,7 @@ def _intersections_normal(self, z: float) -> list[BaseGeometry]:
550593 return []
551594
552595 _ , (x0 , y0 ) = self .pop_axis (static_self .center , axis = self .axis )
553- return [shapely .Point (x0 , y0 ).buffer (radius_offset , quad_segs = _N_SHAPELY_QUAD_SEGS )]
596+ return [shapely .Point (x0 , y0 ).buffer (radius_offset , quad_segs = quad_segs )]
554597
555598 def _intersections_side (self , position : float , axis : int ) -> list [BaseGeometry ]:
556599 """Find shapely geometries intersecting cylindrical geometry with axis orthogonal to length.
0 commit comments