Shapes¶
sies.shapes.boundary ¶
Discretized \(C^2\)-smooth closed boundaries.
A C2Boundary stores the sampled boundary points of a simply
connected planar domain together with the tangent, acceleration and
outward normal vectors. It supports rigid motions and scaling, which
return new objects (instances are immutable by convention).
C2Boundary ¶
C2Boundary(points, tvec, avec, normal, center_of_mass=None, name='')
A discretized \(C^2\)-smooth closed curve in the plane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
(ndarray, shape(2, n))
|
Coordinates of the boundary points. The curve must not be tied off: the first and last points are distinct. |
required |
tvec
|
(ndarray, shape(2, n))
|
Tangent vectors at the boundary points. |
required |
avec
|
(ndarray, shape(2, n))
|
Acceleration (second derivative) vectors. |
required |
normal
|
(ndarray, shape(2, n))
|
Outward unit normal vectors. |
required |
center_of_mass
|
(ndarray, shape(2))
|
Center of mass of the enclosed domain. Computed from the Stokes formula if not provided. |
None
|
name
|
str
|
Human-readable name of the shape. |
""
|
Attributes:
| Name | Type | Description |
|---|---|---|
points |
(ndarray, shape(2, n))
|
Boundary points. |
tvec |
(ndarray, shape(2, n))
|
Tangent vectors. |
avec |
(ndarray, shape(2, n))
|
Acceleration vectors. |
normal |
(ndarray, shape(2, n))
|
Outward unit normal vectors. |
name |
str
|
Name of the shape. |
Source code in src/sies/shapes/boundary.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
sigma
property
¶
sigma
ndarray: Curve integration elements.
The boundary integral of a function f is approximated by
sum(f(points) * sigma).
principal_direction
property
¶
principal_direction
ndarray: Principal direction of the shape (unit vector).
The sign is normalized so that the first nonzero component is positive (the direction is defined up to a sign).
__add__ ¶
__add__(z0)
Translate the boundary by the vector z0.
Source code in src/sies/shapes/boundary.py
146 147 148 149 150 151 152 | |
__sub__ ¶
__sub__(z0)
Translate the boundary by the vector -z0.
Source code in src/sies/shapes/boundary.py
154 155 156 | |
__mul__ ¶
__mul__(s)
Scale the boundary by the positive factor s.
Source code in src/sies/shapes/boundary.py
162 163 164 165 166 167 168 169 170 171 172 173 | |
rotate ¶
rotate(phi)
Rotate the boundary around the origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
float
|
Rotation angle in radians (counterclockwise). |
required |
Returns:
| Type | Description |
|---|---|
C2Boundary
|
The rotated boundary. |
Source code in src/sies/shapes/boundary.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
is_inside ¶
is_inside(x)
Check whether a point lies in the ball circumscribing the shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(ndarray, shape(2))
|
Query point. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if |
Source code in src/sies/shapes/boundary.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
is_disjoint ¶
is_disjoint(other)
Check whether two shapes have disjoint circumscribed balls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
C2Boundary
|
The other shape. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the balls |
Source code in src/sies/shapes/boundary.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
plot ¶
plot(ax=None, **kwargs)
Plot the boundary curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes to draw on. A new figure is created if omitted. |
None
|
**kwargs
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes containing the plot. |
Source code in src/sies/shapes/boundary.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
stokes_center_of_mass
staticmethod
¶
stokes_center_of_mass(points, tvec, normal)
Compute the center of mass of a domain by the Stokes formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
(ndarray, shape(2, n))
|
Boundary points. |
required |
tvec
|
(ndarray, shape(2, n))
|
Tangent vectors. |
required |
normal
|
(ndarray, shape(2, n))
|
Outward unit normal vectors. |
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(2))
|
Center of mass of the enclosed domain. |
Source code in src/sies/shapes/boundary.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
check_sampling
staticmethod
¶
check_sampling(points)
Check that the sampled curve is locally consistent.
By a Taylor expansion, a \(C^1\) simple curve sampled finely enough satisfies \(\langle f(t_{n+1}) - f(t_n), f(t_n) - f(t_{n-1}) \rangle > 0\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
(ndarray, shape(2, n))
|
Boundary points. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the condition holds at every point. |
Source code in src/sies/shapes/boundary.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
sies.shapes.standard ¶
Catalog of standard parametric shapes.
Every class derives from C2Boundary and provides
the analytic tangent, acceleration and normal vectors of its boundary
whenever possible. Shapes with corners (triangle, rectangle) are
smoothed by spline resampling.
Ellipse ¶
Ellipse(axis_a, axis_b, nb_points)
Bases: C2Boundary
An ellipse centered at the origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis_a
|
float
|
Length of the semi-major axis. |
required |
axis_b
|
float
|
Length of the semi-minor axis; must satisfy |
required |
nb_points
|
int
|
Number of boundary discretization points. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
axis_a, axis_b |
float
|
Semi-axis lengths. |
phi |
float
|
Cumulated rotation angle of the shape. |
Source code in src/sies/shapes/standard.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
rotate ¶
rotate(phi)
Rotate the ellipse around the origin by the angle phi.
Source code in src/sies/shapes/standard.py
72 73 74 75 76 | |
Flower ¶
Flower(axis_a, axis_b, nb_points, nb_petals=5, epsilon=0.3, pertb=1)
Bases: C2Boundary
A flower-like perturbation of an ellipse.
The boundary is the curve
\(t \mapsto R_\phi A \, (1 + \epsilon \cos^k(nt)) (\cos t, \sin t)\)
where A = diag(a, b) and n is the number of petals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis_a
|
float
|
Length of the semi-major axis of the underlying ellipse. |
required |
axis_b
|
float
|
Length of the semi-minor axis. |
required |
nb_points
|
int
|
Number of boundary discretization points. |
required |
nb_petals
|
int
|
Number of petals. |
5
|
epsilon
|
float
|
Strength of the petal perturbation. |
0.3
|
pertb
|
int
|
Exponent |
1
|
Attributes:
| Name | Type | Description |
|---|---|---|
nb_petals |
int
|
Number of petals. |
epsilon |
float
|
Perturbation strength. |
Source code in src/sies/shapes/standard.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
Triangle ¶
Triangle(side, angle, nb_points, downsample=10)
Bases: C2Boundary
An isosceles triangle with smoothed corners.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
side
|
float
|
Length of the two equal sides. |
required |
angle
|
float
|
Angle between the two equal sides, in radians. |
required |
nb_points
|
int
|
Number of boundary discretization points. |
required |
downsample
|
int
|
Down-sampling factor used to smooth out the corners; values larger than one produce a \(C^2\) boundary. |
10
|
Attributes:
| Name | Type | Description |
|---|---|---|
side |
float
|
Length of the equal sides. |
angle |
float
|
Apex angle. |
Source code in src/sies/shapes/standard.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
Rectangle ¶
Rectangle(width, height, nb_points, downsample=10)
Bases: C2Boundary
An axis-aligned rectangle with smoothed corners.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
Size along the horizontal axis. |
required |
height
|
float
|
Size along the vertical axis. |
required |
nb_points
|
int
|
Number of boundary discretization points. |
required |
downsample
|
int
|
Down-sampling factor used to smooth out the corners. |
10
|
Attributes:
| Name | Type | Description |
|---|---|---|
width, height |
float
|
Rectangle dimensions. |
Source code in src/sies/shapes/standard.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
Banana ¶
Banana(axis_a, axis_b, center, curvature_center, nb_points)
Bases: C2Boundary
A banana-shaped object (an ellipse bent along a circular arc).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis_a
|
float
|
Length of the semi-major axis of the underlying ellipse. |
required |
axis_b
|
float
|
Length of the semi-minor axis. |
required |
center
|
(ndarray, shape(2))
|
Center of the underlying ellipse. |
required |
curvature_center
|
(ndarray, shape(2))
|
Center of the bending circle. |
required |
nb_points
|
int
|
Number of boundary discretization points. |
required |
Source code in src/sies/shapes/standard.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
sies.shapes.resampling ¶
Resampling of closed curves by periodic cubic splines.
These utilities reconstruct the tangent, acceleration and outward normal vectors of a closed curve from sampled points. Corner singularities can be smoothed out by down-sampling the curve before the spline fit.
resample_curve ¶
resample_curve(points, theta, nb_points, box=None, downsample=1)
Resample a closed curve and compute its differential quantities.
The curve is optionally rescaled to fit a bounding box, down-sampled (which smooths out corner singularities), then re-interpolated on a uniform parameter grid with a periodic cubic spline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
(ndarray, shape(2, n))
|
Coordinates of the curve samples, not tied off. |
required |
theta
|
(ndarray, shape(n))
|
Parameterization of the samples in |
required |
nb_points
|
int
|
Number of points of the resampled curve. |
required |
box
|
tuple of float
|
If given, target size |
None
|
downsample
|
int
|
Down-sampling factor applied before interpolation; values larger than one smooth out corners. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
points |
(ndarray, shape(2, nb_points))
|
Resampled curve. |
tvec |
(ndarray, shape(2, nb_points))
|
Tangent vectors (first derivative). |
avec |
(ndarray, shape(2, nb_points))
|
Acceleration vectors (second derivative). |
normal |
(ndarray, shape(2, nb_points))
|
Outward unit normal vectors. |
Source code in src/sies/shapes/resampling.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |