Skip to main content

Volumes and surface areas of solids of revolution (disc, washer, shell) via SymPy.

Project description

pydisks

Compute volumes and surface areas of solids of revolution — the disc, washer, and shell methods plus surface area of revolution — symbolically, using SymPy. Built for checking calculus homework: you get an exact answer, and mistakes (wrong variable, self-intersecting solids, curves in the wrong order) raise clear errors instead of silently returning a wrong number.

Install

pip install pydisks

Quick start

from pydisks import disc, washer, shell, surface_area, revolve, x, y
import sympy as sp

# Volume of a sphere of radius 2: revolve y = sqrt(4 - x^2) about the x-axis
disc(sp.sqrt(4 - x**2), -2, 2)          # -> 32*pi/3

# Washer: region between y = x and y = x^2 on [0, 1], about the x-axis
washer(x, x**2, 0, 1)                    # -> 2*pi/15

# Shell: revolve y = x^2 on [0, 2] about the y-axis
shell(x**2, 0, 2)                        # -> 8*pi

# Dispatcher: disc if no inner curve, else washer; also gives a float check
revolve(x, 0, 3)                         # -> {'method': 'disc', 'volume': 9*pi, 'approx': 28.27...}

The axis of rotation

The axis is written as a string — either a named axis or a line equation:

You write Means Line
"x" the x-axis y = 0
"y" the y-axis x = 0
"x=2" vertical line x = 2
"y=-1" horizontal line y = -1

A bare letter names an axis; an equation is a literal line. Note the asymmetry this creates: "x" is the x-axis (y = 0), but "x=0" is the line x = 0 (the y-axis).

The variable you write your curve in is derived from the axis and method:

  • disc / washer / surface_area: horizontal axis → f(x); vertical axis → f(y)
  • shell: horizontal axis → f(y); vertical axis → f(x)

If you pass a curve in the wrong variable, pydisks raises VariableMismatchError rather than trying to invert it for you — solving for the right variable is part of the problem.

Functions

Function Method
disc(f, a, b, axis="x") region between f and the axis
washer(outer, inner, a, b, axis="x") region between two curves; outer stays farther from the axis
shell(f, a, b, axis="y", bottom=0) cylindrical shells; pass bottom for a two-curve region
surface_area(f, a, b, axis="x") surface area of revolution
revolve(f, a, b, axis="x", inner=None) disc/washer dispatcher; returns {method, volume, approx}

Errors

Every error subclasses RevolutionError, and messages name the likely fix. Validation runs before integration:

Exception When
AxisError malformed axis string/pair
VariableMismatchError curve or bound in the wrong variable
BoundsError non-constant bounds, or a >= b
SelfIntersectingSolidError the axis passes through the region
CurveCrossingError two boundary curves cross or are given in the wrong order
DomainError curve discontinuous on [a, b]
UnevaluatedIntegralError SymPy found no closed form

Caveat: the geometric and domain checks use sp.solve / continuous_domain, which quietly no-op when the bounds are symbolic or SymPy can't solve. They catch common concrete-number mistakes, not every symbolic edge case — treat a returned volume as validated only for numeric bounds.

Tests

python3 -m pytest test_main.py -v                  # all tests
python3 -m pytest test_main.py::test_disc_sphere   # a single test

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydisks-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydisks-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file pydisks-0.1.0.tar.gz.

File metadata

  • Download URL: pydisks-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pydisks-0.1.0.tar.gz
Algorithm Hash digest
SHA256 86a39b831cabd90a1b54fcd5e9ae4c917f55f39862368ca2eecf7ee5caf4be7f
MD5 e42d2af3593e6b64f269453685d8a7fb
BLAKE2b-256 a8077d1babd171eca45486d13fea8e88c0338cd12c994fef372130cd8886a2ba

See more details on using hashes here.

File details

Details for the file pydisks-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pydisks-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pydisks-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36701433c0572356fb7293970710be9ef091f6caaa542cfb3f692cb642e03e4c
MD5 2c0deff57961002d78aa21dff9d54a17
BLAKE2b-256 f445f61513a9e6f760d2ae15d54c2bb3408ee11b954a3f82e48095a2789927fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page