Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions structuralcodes/geometry/_circular.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@

import typing as t

import numpy as np
from numpy.typing import ArrayLike
from shapely import Polygon
from shapely import Point

from structuralcodes.core.base import Material

from ._geometry import SurfaceGeometry


def _create_circle(radius, npoints=20, origin: t.Optional[ArrayLike] = None):
def _create_circle(
radius, npoints: int = 20, origin: t.Optional[ArrayLike] = None
):
"""Create a circle with a given radius."""
origin = origin if origin is not None else (0.0, 0.0)
phi = np.linspace(0, 2 * np.pi, npoints + 1)
x = radius * np.cos(phi) + origin[0]
y = radius * np.sin(phi) + origin[1]
points = np.transpose(np.array([x, y]))
return Polygon(points)
pt = Point(origin)
quad_segs = 4 * round(npoints / 4) # Round to the nearest multiple of 4
return pt.buffer(radius, quad_segs=quad_segs)


class CircularGeometry(SurfaceGeometry):
Expand All @@ -50,7 +49,8 @@ def __init__(
diameter (float): The diameter of the geometry.
material (Material): A Material class applied to the geometry.
n_points (int): The number of points used to discretize the
circle as a shapely `Polygon` (default = 20).
circle as a shapely `Polygon` (default = 20). Note that the
number of points is rounded to the nearest multiple of 4.
concrete (bool): Flag to indicate if the geometry is concrete.
origin (Optional(ArrayLike)): The center point of the circle.
(0.0, 0.0) is used as default.
Expand Down
10 changes: 4 additions & 6 deletions tests/test_geometry/test_circular.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@

# Test create a circular geometry
@pytest.mark.parametrize(
'diameter, n_points',
[(100, 20), (200, 20), (300, 20), (300, 30), (400, 40), (500, 24)],
'diameter',
[100, 200, 300, 400, 500],
)
def test_create_circular_geometry(diameter, n_points):
def test_create_circular_geometry(diameter):
"""Test creating a CircularGeometry."""
mat = ElasticMaterial(E=300000, density=2450)
circle = CircularGeometry(diameter, mat, n_points)

assert len(circle.polygon.exterior.coords) == n_points + 2
circle = CircularGeometry(diameter, mat)

assert math.isclose(circle.diameter, diameter)
assert math.isclose(circle.radius, diameter / 2.0)
Expand Down
Loading