2727import pyvista as pv
2828from scipy .spatial .transform import Rotation as SpatialRotation
2929
30+ from ansys .geometry .core .logger import LOG
3031from ansys .geometry .core .math .constants import ZERO_POINT2D
3132from ansys .geometry .core .math .matrix import Matrix33
3233from ansys .geometry .core .math .point import Point2D
@@ -42,45 +43,57 @@ class Trapezoid(SketchFace):
4243
4344 Parameters
4445 ----------
45- width : ~pint.Quantity | Distance | Real
46- Width of the trapezoid.
46+ base_width : ~pint.Quantity | Distance | Real
47+ Width of the lower base of the trapezoid.
4748 height : ~pint.Quantity | Distance | Real
48- Height of the trapezoid.
49- slant_angle : ~pint.Quantity | Angle | Real
50- Angle for trapezoid generation.
51- nonsymmetrical_slant_angle : ~pint.Quantity | Angle | Real | None, default: None
52- Asymmetrical slant angles on each side of the trapezoid.
53- The default is ``None``, in which case the trapezoid is symmetrical.
49+ Height of the slot.
50+ base_angle : ~pint.Quantity | Distance | Real
51+ Angle for trapezoid generation. Represents the angle
52+ on the base of the trapezoid.
53+ base_asymmetric_angle : ~pint.Quantity | Angle | Real | None, default: None
54+ Asymmetrical angles on each side of the trapezoid.
55+ The default is ``None``, in which case the trapezoid is symmetrical. If
56+ provided, the trapezoid is asymmetrical and the right corner angle
57+ at the base of the trapezoid is set to the provided value.
5458 center: Point2D, default: ZERO_POINT2D
5559 Center point of the trapezoid.
5660 angle : ~pint.Quantity | Angle | Real, default: 0
5761 Placement angle for orientation alignment.
5862
5963 Notes
6064 -----
61- If a nonsymmetrical slant angle is defined, the slant angle is
62- applied to the left-most angle, and the nonsymmetrical slant angle
65+ If an asymmetric base angle is defined, the base angle is
66+ applied to the left-most angle, and the asymmetric base angle
6367 is applied to the right-most angle.
6468 """
6569
6670 @check_input_types
6771 def __init__ (
6872 self ,
69- width : Quantity | Distance | Real ,
73+ base_width : Quantity | Distance | Real ,
7074 height : Quantity | Distance | Real ,
71- slant_angle : Quantity | Angle | Real ,
72- nonsymmetrical_slant_angle : Quantity | Angle | Real | None = None ,
75+ base_angle : Quantity | Angle | Real ,
76+ base_asymmetric_angle : Quantity | Angle | Real | None = None ,
7377 center : Point2D = ZERO_POINT2D ,
7478 angle : Quantity | Angle | Real = 0 ,
7579 ):
7680 """Initialize the trapezoid."""
7781 super ().__init__ ()
7882
83+ # TODO: Remove this warning in the next major release (v0.8.0)
84+ # https://github.com/ansys/pyansys-geometry/issues/1359
85+ LOG .warning (
86+ "The signature of the Trapezoid class has changed starting on"
87+ "version 0.7.X. Please refer to the documentation for more information."
88+ )
89+
7990 self ._center = center
80- self ._width = width if isinstance (width , Distance ) else Distance (width , center .unit )
81- if self ._width .value <= 0 :
82- raise ValueError ("Width must be a real positive value." )
83- width_magnitude = self ._width .value .m_as (center .unit )
91+ self ._base_width = (
92+ base_width if isinstance (base_width , Distance ) else Distance (base_width , center .unit )
93+ )
94+ if self ._base_width .value <= 0 :
95+ raise ValueError ("Base width must be a real positive value." )
96+ width_magnitude = self ._base_width .value .m_as (center .unit )
8497
8598 self ._height = height if isinstance (height , Distance ) else Distance (height , center .unit )
8699 if self ._height .value <= 0 :
@@ -91,21 +104,42 @@ def __init__(
91104 angle = Angle (angle , DEFAULT_UNITS .ANGLE )
92105 angle = angle if isinstance (angle , Angle ) else Angle (angle , angle .units )
93106
94- if isinstance (slant_angle , (int , float )):
95- slant_angle = Angle (slant_angle , DEFAULT_UNITS .ANGLE )
96- slant_angle = (
97- slant_angle if isinstance (slant_angle , Angle ) else Angle (slant_angle , slant_angle .units )
107+ if isinstance (base_angle , (int , float )):
108+ base_angle = Angle (base_angle , DEFAULT_UNITS .ANGLE )
109+ base_angle = (
110+ base_angle if isinstance (base_angle , Angle ) else Angle (base_angle , base_angle .units )
98111 )
99112
100- if nonsymmetrical_slant_angle is None :
101- nonsymmetrical_slant_angle = slant_angle
113+ if base_asymmetric_angle is None :
114+ base_asymmetric_angle = base_angle
102115 else :
103- if isinstance (nonsymmetrical_slant_angle , (int , float )):
104- nonsymmetrical_slant_angle = Angle (nonsymmetrical_slant_angle , DEFAULT_UNITS .ANGLE )
105- nonsymmetrical_slant_angle = (
106- nonsymmetrical_slant_angle
107- if isinstance (nonsymmetrical_slant_angle , Angle )
108- else Angle (nonsymmetrical_slant_angle , nonsymmetrical_slant_angle .units )
116+ if isinstance (base_asymmetric_angle , (int , float )):
117+ base_asymmetric_angle = Angle (base_asymmetric_angle , DEFAULT_UNITS .ANGLE )
118+ base_asymmetric_angle = (
119+ base_asymmetric_angle
120+ if isinstance (base_asymmetric_angle , Angle )
121+ else Angle (base_asymmetric_angle , base_asymmetric_angle .units )
122+ )
123+
124+ # SANITY CHECK: Ensure that the angles are valid (i.e. between 0 and 180 degrees)
125+ for trapz_angle in [base_angle , base_asymmetric_angle ]:
126+ if (
127+ trapz_angle .value .m_as (UNITS .radian ) < 0
128+ or trapz_angle .value .m_as (UNITS .radian ) > np .pi
129+ ):
130+ raise ValueError ("The trapezoid angles must be between 0 and 180 degrees." )
131+
132+ # Check that the sum of both angles is larger than 90 degrees
133+ base_offset_right = height_magnitude / np .tan (
134+ base_asymmetric_angle .value .m_as (UNITS .radian )
135+ )
136+ base_offset_left = height_magnitude / np .tan (base_angle .value .m_as (UNITS .radian ))
137+
138+ # SANITY CHECK: Ensure that the trapezoid is not degenerate
139+ if base_offset_right + base_offset_left >= width_magnitude :
140+ raise ValueError (
141+ "The trapezoid is degenerate. "
142+ "The provided angles, width and height do not form a valid trapezoid."
109143 )
110144
111145 rotation = Matrix33 (
@@ -119,14 +153,12 @@ def __init__(
119153 rotated_point_1 = rotation @ [center .x .m - half_w , center .y .m - half_h , 0 ]
120154 rotated_point_2 = rotation @ [center .x .m + half_w , center .y .m - half_h , 0 ]
121155 rotated_point_3 = rotation @ [
122- center .x .m - half_w + height_magnitude / np . tan ( slant_angle . value . m_as ( UNITS . radian )) ,
156+ center .x .m + half_w - base_offset_right ,
123157 center .y .m + half_h ,
124158 0 ,
125159 ]
126160 rotated_point_4 = rotation @ [
127- center .x .m
128- + half_w
129- - height_magnitude / np .tan (nonsymmetrical_slant_angle .value .m_as (UNITS .radian )),
161+ center .x .m - half_w + base_offset_left ,
130162 center .y .m + half_h ,
131163 0 ,
132164 ]
@@ -154,9 +186,9 @@ def center(self) -> Point2D:
154186 return self ._center
155187
156188 @property
157- def width (self ) -> Quantity :
189+ def base_width (self ) -> Quantity :
158190 """Width of the trapezoid."""
159- return self ._width .value
191+ return self ._base_width .value
160192
161193 @property
162194 def height (self ) -> Quantity :
0 commit comments