Skip to content

Commit aeecfae

Browse files
jonahrbRobPasMue
andauthored
Feat/enhance parameters (#406)
Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent 5199a5f commit aeecfae

File tree

10 files changed

+1160
-132
lines changed

10 files changed

+1160
-132
lines changed
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
"""Provides the PyGeometry ``primitives`` subpackage."""
22

33
from ansys.geometry.core.primitives.circle import Circle, CircleEvaluation
4-
from ansys.geometry.core.primitives.cone import Cone
5-
from ansys.geometry.core.primitives.cylinder import Cylinder
4+
from ansys.geometry.core.primitives.cone import Cone, ConeEvaluation
5+
from ansys.geometry.core.primitives.cylinder import Cylinder, CylinderEvaluation
66
from ansys.geometry.core.primitives.ellipse import Ellipse, EllipseEvaluation
7-
from ansys.geometry.core.primitives.line import Line
8-
from ansys.geometry.core.primitives.sphere import Sphere
9-
from ansys.geometry.core.primitives.surface_evaluation import ParamUV, SurfaceEvaluation
7+
from ansys.geometry.core.primitives.line import Line, LineEvaluation
8+
from ansys.geometry.core.primitives.parameterization import (
9+
Parameterization,
10+
ParamForm,
11+
ParamType,
12+
ParamUV,
13+
)
14+
from ansys.geometry.core.primitives.sphere import Sphere, SphereEvaluation
15+
from ansys.geometry.core.primitives.surface_evaluation import SurfaceEvaluation
1016
from ansys.geometry.core.primitives.torus import Torus

src/ansys/geometry/core/primitives/circle.py

Lines changed: 103 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from ansys.geometry.core.math import UNITVECTOR3D_X, UNITVECTOR3D_Z, Point3D, UnitVector3D, Vector3D
99
from ansys.geometry.core.misc import Accuracy, Distance
1010
from ansys.geometry.core.primitives.curve_evaluation import CurveEvaluation
11+
from ansys.geometry.core.primitives.parameterization import (
12+
Interval,
13+
Parameterization,
14+
ParamForm,
15+
ParamType,
16+
)
1117
from ansys.geometry.core.typing import Real, RealSequence
1218

1319

@@ -99,12 +105,36 @@ def __eq__(self, other: "Circle") -> bool:
99105
and self._axis == other._axis
100106
)
101107

102-
def evaluate(self, parameter: float) -> "CircleEvaluation":
103-
"""Evaluate the circle at the given parameter."""
108+
def evaluate(self, parameter: Real) -> "CircleEvaluation":
109+
"""
110+
Evaluate the circle at the given parameter.
111+
112+
Parameters
113+
----------
114+
parameter : Real
115+
The parameter at which to evaluate the circle.
116+
117+
Returns
118+
-------
119+
CircleEvaluation
120+
The resulting evaluation.
121+
"""
104122
return CircleEvaluation(self, parameter)
105123

106124
def project_point(self, point: Point3D) -> "CircleEvaluation":
107-
"""Project a point onto the circle and return its ``CircleEvaluation``."""
125+
"""
126+
Project a point onto the circle and return its ``CircleEvaluation``.
127+
128+
Parameters
129+
----------
130+
point : Point3D
131+
The point to project onto the circle.
132+
133+
Returns
134+
-------
135+
CircleEvaluation
136+
The resulting evaluation.
137+
"""
108138
origin_to_point = point - self.origin
109139
dir_in_plane = UnitVector3D.from_points(
110140
Point3D([0, 0, 0]), origin_to_point - ((origin_to_point * self.dir_z) * self.dir_z)
@@ -116,13 +146,38 @@ def project_point(self, point: Point3D) -> "CircleEvaluation":
116146
return CircleEvaluation(self, t)
117147

118148
def is_coincident_circle(self, other: "Circle") -> bool:
119-
"""Determine if this circle is coincident with another."""
149+
"""
150+
Determine if this circle is coincident with another.
151+
152+
Parameters
153+
----------
154+
other : Circle
155+
The circle to determine coincidence with.
156+
157+
Returns
158+
-------
159+
bool
160+
Returns true if this circle is coincident with the other.
161+
"""
120162
return (
121163
Accuracy.length_is_equal(self.radius.m, other.radius.m)
122164
and self.origin == other.origin
123165
and self.dir_z == other.dir_z
124166
)
125167

168+
def get_parameterization(self) -> Parameterization:
169+
"""
170+
The parameter of a circle specifies the clockwise angle around the axis
171+
(right hand corkscrew law), with a zero parameter at `dir_x` and a period
172+
of 2*pi.
173+
174+
Returns
175+
-------
176+
Parameterization
177+
Information about how a circle is parameterized.
178+
"""
179+
return Parameterization(ParamForm.PERIODIC, ParamType.CIRCULAR, Interval(0, 2 * np.pi))
180+
126181

127182
class CircleEvaluation(CurveEvaluation):
128183
"""
@@ -132,11 +187,12 @@ class CircleEvaluation(CurveEvaluation):
132187
----------
133188
circle: ~ansys.geometry.core.primitives.circle.Circle
134189
The ``Circle`` object to be evaluated.
135-
parameter: float, int
190+
parameter: Real
136191
The parameter at which the ``Circle`` evaluation is requested.
137192
"""
138193

139194
def __init__(self, circle: Circle, parameter: Real) -> None:
195+
"""``CircleEvaluation`` class constructor."""
140196
self._circle = circle
141197
self._parameter = parameter
142198

@@ -151,31 +207,68 @@ def parameter(self) -> Real:
151207
return self._parameter
152208

153209
def position(self) -> Point3D:
154-
"""The position of the evaluation."""
210+
"""
211+
The position of the evaluation.
212+
213+
Returns
214+
-------
215+
Point3D
216+
The point that lies on the circle at this evaluation.
217+
"""
155218
return (
156219
self.circle.origin
157220
+ ((self.circle.radius * np.cos(self.parameter)) * self.circle.dir_x).m
158221
+ ((self.circle.radius * np.sin(self.parameter)) * self.circle.dir_y).m
159222
)
160223

161224
def tangent(self) -> UnitVector3D:
162-
"""The tangent of the evaluation."""
225+
"""
226+
The tangent of the evaluation.
227+
228+
Returns
229+
-------
230+
UnitVector3D
231+
The tangent unit vector to the circle at this evaluation.
232+
"""
163233
return (
164234
np.cos(self.parameter) * self.circle.dir_y - np.sin(self.parameter) * self.circle.dir_x
165235
)
166236

167237
def first_derivative(self) -> Vector3D:
168-
"""The first derivative of the evaluation."""
238+
"""
239+
The first derivative of the evaluation. The first derivative is in the direction of the
240+
tangent and has a magnitude equal to the velocity (rate of change of position) at that
241+
point.
242+
243+
Returns
244+
-------
245+
Vector3D
246+
The first derivative of this evaluation.
247+
"""
169248
return self.circle.radius.m * (
170249
np.cos(self.parameter) * self.circle.dir_y - np.sin(self.parameter) * self.circle.dir_x
171250
)
172251

173252
def second_derivative(self) -> Vector3D:
174-
"""The second derivative of the evaluation."""
253+
"""
254+
The second derivative of the evaluation.
255+
256+
Returns
257+
-------
258+
Vector3D
259+
The second derivative of this evaluation.
260+
"""
175261
return -self.circle.radius.m * (
176262
np.cos(self.parameter) * self.circle.dir_x + np.sin(self.parameter) * self.circle.dir_y
177263
)
178264

179265
def curvature(self) -> Real:
180-
"""The curvature of the evaluation."""
266+
"""
267+
The curvature of the circle.
268+
269+
Returns
270+
-------
271+
Real
272+
The curvature of the circle.
273+
"""
181274
return 1 / np.abs(self.circle.radius.m)

0 commit comments

Comments
 (0)