27
27
import pyvista as pv
28
28
from scipy .spatial .transform import Rotation as SpatialRotation
29
29
30
+ from ansys .geometry .core .logger import LOG
30
31
from ansys .geometry .core .math .constants import ZERO_POINT2D
31
32
from ansys .geometry .core .math .matrix import Matrix33
32
33
from ansys .geometry .core .math .point import Point2D
@@ -42,45 +43,57 @@ class Trapezoid(SketchFace):
42
43
43
44
Parameters
44
45
----------
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.
47
48
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.
54
58
center: Point2D, default: ZERO_POINT2D
55
59
Center point of the trapezoid.
56
60
angle : ~pint.Quantity | Angle | Real, default: 0
57
61
Placement angle for orientation alignment.
58
62
59
63
Notes
60
64
-----
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
63
67
is applied to the right-most angle.
64
68
"""
65
69
66
70
@check_input_types
67
71
def __init__ (
68
72
self ,
69
- width : Quantity | Distance | Real ,
73
+ base_width : Quantity | Distance | Real ,
70
74
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 ,
73
77
center : Point2D = ZERO_POINT2D ,
74
78
angle : Quantity | Angle | Real = 0 ,
75
79
):
76
80
"""Initialize the trapezoid."""
77
81
super ().__init__ ()
78
82
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
+
79
90
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 )
84
97
85
98
self ._height = height if isinstance (height , Distance ) else Distance (height , center .unit )
86
99
if self ._height .value <= 0 :
@@ -91,21 +104,42 @@ def __init__(
91
104
angle = Angle (angle , DEFAULT_UNITS .ANGLE )
92
105
angle = angle if isinstance (angle , Angle ) else Angle (angle , angle .units )
93
106
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 )
98
111
)
99
112
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
102
115
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."
109
143
)
110
144
111
145
rotation = Matrix33 (
@@ -119,14 +153,12 @@ def __init__(
119
153
rotated_point_1 = rotation @ [center .x .m - half_w , center .y .m - half_h , 0 ]
120
154
rotated_point_2 = rotation @ [center .x .m + half_w , center .y .m - half_h , 0 ]
121
155
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 ,
123
157
center .y .m + half_h ,
124
158
0 ,
125
159
]
126
160
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 ,
130
162
center .y .m + half_h ,
131
163
0 ,
132
164
]
@@ -154,9 +186,9 @@ def center(self) -> Point2D:
154
186
return self ._center
155
187
156
188
@property
157
- def width (self ) -> Quantity :
189
+ def base_width (self ) -> Quantity :
158
190
"""Width of the trapezoid."""
159
- return self ._width .value
191
+ return self ._base_width .value
160
192
161
193
@property
162
194
def height (self ) -> Quantity :
0 commit comments