Skip to main content

A tool for calculating definite integrals over a 2D polygonal domain

Project description

Pyntegrals

Pyntegrals is a simple library for computing a definite integral over a 2D polygonal domain.
At the moment the only function of the library is integrate_over_polygon, which perform the calculation.
It is possible that in the future other functions will be added.

pyntegrals.integrals

pyntegrals.integrals.integrate_over_polygon

pyntegrals.integrals.integrate_over_polygon(function: Union[Callable, float], polygon: list[tuple]) -> float

Computes the integral of a two-variables function over a polygonal domain in R2.

Returns the definite integral of function(x, y) = f(x, y) over polygon = Σ, that is:

Σ f(x, y) dΣ

Parameters

function : Union[Callable, float]

A scalar or a Python function with two arguments: the first one is x and the second one is y in R2 space.

polygon: list[tuple]

A polygon defined by a list of its vertices. Each vertex is described by a tuple containing its coordinated in the form (x, y). The vertices in the list must be in clockwise or counter-clockwise order (it makes no difference)

Returns

r : float

The definite integral of function(x, y) over polygon.

Example

Compute the integral of x2 + y over a 50 x 40 rectangle Σ with a vertex in (0, 0) and another in (50, 40)

Σ (x2 + y) dΣ
from pyntegrals.integrals import integrate_over_polygon
polygon = [(0, 0), (50, 0), (50, 40), (0, 40)]
rho = lambda x, y: x**2 + y
mass = integrate_over_polygon(function=rho, polygon=polygon)
>>> 1706666.666666667

For more example see examples/example.py

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

pyntegrals-1.0.0.tar.gz (39.4 kB view details)

Uploaded Source

Built Distribution

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

pyntegrals-1.0.0-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file pyntegrals-1.0.0.tar.gz.

File metadata

  • Download URL: pyntegrals-1.0.0.tar.gz
  • Upload date:
  • Size: 39.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.9

File hashes

Hashes for pyntegrals-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eceeac2f715c8aeaa805a167a2f2c3884e5f86737cfe61e3f66acd561e6d22b3
MD5 142f166112e8f6ff4f39368ea0b43a23
BLAKE2b-256 2e1104a260ec96313121b176e33bef64109f7d26cc4021e91c6ccb8f2ba979d1

See more details on using hashes here.

File details

Details for the file pyntegrals-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyntegrals-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.9

File hashes

Hashes for pyntegrals-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48ae01166059ee369102e044761b49809247b89ab61524c2f49f00a20295f06e
MD5 a26f8f07ff99abf4e1943fecc8153f77
BLAKE2b-256 18ac35cbe628da453352a5bc54adb9741bb4807cda78f586e5d0c14541a5d5f4

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