Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make physics.mechanics.wrapping_geometry public #25510

Merged
merged 23 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cf05ca0
Make _geometry public in docstrings and minor docstring edits.
moorepants Aug 14, 2023
76d4763
Renamed _geometry.py to geometry.py.
moorepants Aug 14, 2023
5df0e3d
Add geometry api to the docstrings.
moorepants Aug 14, 2023
2cb3040
Update sympy/physics/mechanics/geometry.py
brocksam Aug 14, 2023
91775e8
Update sympy/physics/mechanics/geometry.py
brocksam Aug 14, 2023
915f987
Added GeometryBase to __all__
moorepants Aug 14, 2023
51ba7ca
Corrected the math rendering.
moorepants Aug 14, 2023
32f55d7
Renamed _point_is_on_surface to point_on_surface (making it public.
moorepants Aug 14, 2023
fe18fb7
Warned that points on surfaces need to be simply defined and removed …
moorepants Aug 14, 2023
47c6779
Removed type hints because of sphinx parsing bug.
moorepants Aug 14, 2023
e5993ff
Renamed geometry.py to wrapping_geometry.py.
moorepants Aug 14, 2023
acb0f12
Remove unused import.
moorepants Aug 14, 2023
638bbef
Fixed doc page title.
moorepants Aug 14, 2023
2eecd41
Fixed merge conflicts.
moorepants Aug 14, 2023
8c5937e
Fixed imports in _pathway.
moorepants Aug 14, 2023
19657c2
Fixed failing tests.
moorepants Aug 14, 2023
e28367d
Reformat imports
brocksam Aug 15, 2023
eab6a24
Make geodesic_end_vectors methods public
brocksam Aug 15, 2023
c6d9fa4
Rename classes to WrappingCylinder, WrappingGeometryBase, WrappingSphere
brocksam Aug 15, 2023
d6c7b98
Add WrappingCylinder, WrappingGeometryBase, WrappingSphere to module …
brocksam Aug 15, 2023
3a7d33a
Fix typo in docstring
brocksam Aug 15, 2023
f1fe991
Swap incorrect explanations for geodesic_length methods
brocksam Aug 15, 2023
e3e4d2f
Remove type hints from wrapping_geometry modules
brocksam Aug 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/src/modules/physics/mechanics/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Mechanics API Reference
linearize.rst
expr_manip.rst
printing.rst
wrapping_geometry.rst
6 changes: 6 additions & 0 deletions doc/src/modules/physics/mechanics/api/wrapping_geometry.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
==============================
Wrapping Geometry (Docstrings)
==============================

.. automodule:: sympy.physics.mechanics.wrapping_geometry
:members:
16 changes: 8 additions & 8 deletions sympy/physics/mechanics/_pathway.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from sympy.core.backend import S
from sympy.physics.mechanics import Force, Point
from sympy.physics.mechanics._geometry import GeometryBase
from sympy.physics.mechanics.wrapping_geometry import GeometryBase
from sympy.physics.vector import dynamicsymbols

if TYPE_CHECKING:
Expand Down Expand Up @@ -300,13 +300,13 @@ class WrappingPathway(PathwayBase):
>>> from sympy.physics.mechanics._pathway import WrappingPathway

To construct a wrapping pathway, a geometry object, which the pathway can
wrap, is required. Similar to above, the ``_geometry.py`` module is also
experimental so geometry classes needed to be imported directly from the
``sympy.physics.mechanics._geometry.py`` module. Let's create a wrapping
pathway that wraps around a cylinder. To do this we need to import the
``Cylinder`` class.
wrap, is required. Similar to above, the ``wrapping_geometry.py`` module is
also experimental so geometry classes needed to be imported directly from
the ``sympy.physics.mechanics.wrapping_geometry.py`` module. Let's create a
wrapping pathway that wraps around a cylinder. To do this we need to import
the ``Cylinder`` class.

>>> from sympy.physics.mechanics._geometry import Cylinder
>>> from sympy.physics.mechanics.wrapping_geometry import Cylinder

To construct a wrapping pathway, like other pathways, a pair of points must
be passed, followed by an instance of a geometry class as a keyword
Expand Down Expand Up @@ -419,7 +419,7 @@ def compute_loads(self, force: ExprType) -> list[LoadBase]:

>>> from sympy import Symbol
>>> from sympy.physics.mechanics import Point, ReferenceFrame
>>> from sympy.physics.mechanics._geometry import Cylinder
>>> from sympy.physics.mechanics.wrapping_geometry import Cylinder
>>> N = ReferenceFrame('N')
>>> r = Symbol('r', positive=True)
>>> pO = Point('pO')
Expand Down
3 changes: 2 additions & 1 deletion sympy/physics/mechanics/tests/test_pathway.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
ReferenceFrame,
dynamicsymbols,
)
from sympy.physics.mechanics._geometry import Cylinder, GeometryBase, Sphere
from sympy.physics.mechanics.wrapping_geometry import (Cylinder, GeometryBase,
Sphere)
from sympy.physics.mechanics._pathway import (
LinearPathway,
PathwayBase,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for the ``sympy.physics.mechanics._geometry.py`` module."""
"""Tests for the ``sympy.physics.mechanics.wrapping_geometry.py`` module."""

from __future__ import annotations

Expand All @@ -20,7 +20,7 @@
)
from sympy.core.relational import Eq
from sympy.physics.mechanics import Point, ReferenceFrame, dynamicsymbols
from sympy.physics.mechanics._geometry import Cylinder, Sphere
from sympy.physics.mechanics.wrapping_geometry import Cylinder, Sphere
from sympy.simplify.simplify import simplify

if TYPE_CHECKING:
Expand Down Expand Up @@ -52,7 +52,7 @@ def test_valid_constructor() -> None:
assert sphere.point == pO

@staticmethod
@pytest.mark.parametrize('position', [S.Zero, Integer(2) * r * N.x])
@pytest.mark.parametrize('position', [S.Zero, Integer(2)*r*N.x])
def test_geodesic_length_point_not_on_surface_invalid(position: Vector) -> None:
r = Symbol('r', positive=True)
pO = Point('pO')
Expand All @@ -71,19 +71,20 @@ def test_geodesic_length_point_not_on_surface_invalid(position: Vector) -> None:
@pytest.mark.parametrize(
'position_1, position_2, expected',
[
(r * N.x, r * N.x, S.Zero),
(r * N.x, r * N.y, S.Half * pi * r),
(r * N.x, r * -N.x, pi * r),
(r * -N.x, r * N.x, pi * r),
(r * N.x, r * sqrt(2) * S.Half * (N.x + N.y), Rational(1, 4) * pi * r),
(r*N.x, r*N.x, S.Zero),
(r*N.x, r*N.y, S.Half*pi*r),
(r*N.x, r*-N.x, pi*r),
(r*-N.x, r*N.x, pi*r),
(r*N.x, r*sqrt(2)*S.Half*(N.x + N.y), Rational(1, 4)*pi*r),
(
r * sqrt(2) * S.Half * (N.x + N.y),
r * sqrt(3) * Rational(1, 3) * (N.x + N.y + N.z),
r * acos(sqrt(6) * Rational(1, 3)),
r*sqrt(2)*S.Half*(N.x + N.y),
r*sqrt(3)*Rational(1, 3)*(N.x + N.y + N.z),
r*acos(sqrt(6)*Rational(1, 3)),
),
]
)
def test_geodesic_length(position_1: Vector, position_2: Vector, expected: ExprType) -> None:
def test_geodesic_length(position_1: Vector, position_2: Vector,
expected: ExprType) -> None:
r = Symbol('r', positive=True)
pO = Point('pO')
sphere = Sphere(r, pO)
Expand Down Expand Up @@ -209,14 +210,14 @@ def test_valid_constructor() -> None:
'position, expected',
[
(S.Zero, False),
(r * N.y, True),
(r * N.z, True),
(r * (N.y + N.z).normalize(), True),
(Integer(2) * r * N.y, False),
(r * (N.x + N.y), True),
(r * (Integer(2) * N.x + N.y), True),
(Integer(2) * N.x + r * (Integer(2) * N.y + N.z).normalize(), True),
(r * (cos(q) * N.y + sin(q) * N.z), True)
(r*N.y, True),
(r*N.z, True),
(r*(N.y + N.z).normalize(), True),
(Integer(2)*r*N.y, False),
(r*(N.x + N.y), True),
(r*(Integer(2)*N.x + N.y), True),
(Integer(2)*N.x + r*(Integer(2)*N.y + N.z).normalize(), True),
(r*(cos(q)*N.y + sin(q)*N.z), True)
]
)
def test_point_is_on_surface(position: Vector, expected: bool) -> None:
Expand All @@ -227,10 +228,10 @@ def test_point_is_on_surface(position: Vector, expected: bool) -> None:
p1 = Point('p1')
p1.set_pos(pO, position)

assert cylinder._point_is_on_surface(p1) is expected
assert cylinder.point_on_surface(p1) is expected

@staticmethod
@pytest.mark.parametrize('position', [S.Zero, Integer(2) * r * N.y])
@pytest.mark.parametrize('position', [S.Zero, Integer(2)*r*N.y])
def test_geodesic_length_point_not_on_surface_invalid(position: Vector) -> None:
r = Symbol('r', positive=True)
pO = Point('pO')
Expand All @@ -249,19 +250,19 @@ def test_geodesic_length_point_not_on_surface_invalid(position: Vector) -> None:
@pytest.mark.parametrize(
'axis, position_1, position_2, expected',
[
(N.x, r * N.y, r * N.y, S.Zero),
(N.x, r * N.y, N.x + r * N.y, S.One),
(N.x, r * N.y, -x * N.x + r * N.y, sqrt(x**2)),
(-N.x, r * N.y, x * N.x + r * N.y, sqrt(x**2)),
(N.x, r * N.y, r * N.z, S.Half * pi * sqrt(r**2)),
(-N.x, r * N.y, r * N.z, Integer(3) * S.Half * pi * sqrt(r**2)),
(N.x, r * N.z, r * N.y, Integer(3) * S.Half * pi * sqrt(r**2)),
(-N.x, r * N.z, r * N.y, S.Half * pi * sqrt(r**2)),
(N.x, r * N.y, r * (cos(q) * N.y + sin(q) * N.z), sqrt(r**2 * q**2)),
(N.x, r*N.y, r*N.y, S.Zero),
(N.x, r*N.y, N.x + r*N.y, S.One),
(N.x, r*N.y, -x*N.x + r*N.y, sqrt(x**2)),
(-N.x, r*N.y, x*N.x + r*N.y, sqrt(x**2)),
(N.x, r*N.y, r*N.z, S.Half*pi*sqrt(r**2)),
(-N.x, r*N.y, r*N.z, Integer(3)*S.Half*pi*sqrt(r**2)),
(N.x, r*N.z, r*N.y, Integer(3)*S.Half*pi*sqrt(r**2)),
(-N.x, r*N.z, r*N.y, S.Half*pi*sqrt(r**2)),
(N.x, r*N.y, r*(cos(q)*N.y + sin(q)*N.z), sqrt(r**2*q**2)),
(
-N.x, r * N.y,
r * (cos(q) * N.y + sin(q) * N.z),
sqrt(r**2 * (Integer(2) * pi - q)**2),
-N.x, r*N.y,
r*(cos(q)*N.y + sin(q)*N.z),
sqrt(r**2*(Integer(2)*pi - q)**2),
),
]
)
Expand Down