Skip to main content

A library for fitting shapes and operations on geometrical objects

Project description

Crates.io Version PyPI - Version PyPI - Downloads

Shapers

Fitting shapes with Rust in python

Currently, only TaubinSVD and geometrical fitting are implemented.

This package is based on circle-fit. We are incorporating functions from the original work by Nikolai Chernov.

How to install

The software is available on crates.io or in PyPi.

Python

To install in python run

pip install shapers

Rust

To install in Rust, add the following to your Cargo.toml file

[dependencies]
shapers = "0.3.0"

Circle fitting

How to use

Currently, the exposed functions are:

Function Description
fit_geometrical(x_values: Vec<f64>, y_values: Vec<f64>) Calculate the geometrical mean
taubin_svd(x_values: Vec<f64>, y_values: Vec<f64>) Fit a circle using Taubin SVD
fit_lsq(x_values: Vec<f64>, y_values: Vec<f64>) Fit a circle using least squares

Python example:

import shapers as shs

# create example circle
circle_center = [5, 5]
circle_radius = 5
n_points = 50
theta = np.linspace(0, 2 * np.pi, n_points)
arrx = circle_center[0] + (circle_radius * np.random.normal(1, 0.1)) * np.cos(theta)
arry = circle_center[1] + (circle_radius * np.random.normal(1, 0.1)) * np.sin(theta)

# fit circle
x_center, y_center = shs.taubin_svd(arrx, arry)
# x_center, y_center = shs.fit_geometrical(arrx, arry)  # alternatively
# x_center, y_center = shs.fit_lsq(arrx, arry)  # alternatively

It is possible to modify the parameters of the algorithm through the FitCircleParams class in the following wway:

# fit circle
parameters = shs.FitCircleParams()
parameters.method = "lbfgs"
parameters.precision = 1e-4
parameters.max_iterations = 1000
x_center, y_center = shs.fit_lsq(arrx, arry, parameters)

Each method might have specific parameters. For more information, please refer to the documentation of the method.

Ellipsoid superposition

To determine if two ellipsoids are superimposed, you can use check_ellipsoid_intersection(ellipse_a: Ellipsoid, ellipse_b: Ellipsoid, parameters: Option<EllipsoidIntersectionParameters>.

Python example

import shapers as shs

# create example Ellipsoids
eli1 = shs.Ellipsoid(0, 0, 2, 1, 0)
eli2 = shs.Ellipsoid(4, 0, 2, 1, 0)

# check intersection
intersection = shs.check_ellipsoid_intersection(eli1, eli2)

If the value of intersection is positive, the ellipsoids are superimposed. If it is zero, they are only touching at one point. If it is negative, they are not touching at all.

To modify the parameters, you can use the EllipsoidIntersectionParameters class. For example:

# check intersection
parameters = shs.EllipsoidIntersectionParameters()
parameters.tolerance = 1e-4
parameters.max_iters = 1000
intersection = shs.check_ellipsoid_intersection(eli1, eli2, parameters)

Rust example

// create example Ellipsoids
let ellipse1 = Ellipsoid::new(0.0, 0.0, 2.0, 1.0, 0.0);
let ellipse2 = Ellipsoid::new(4.0, 0.0, 2.0, 1.0, 0.0);

// check intersection
let parameters = ellipsoids::EllipsoidIntersectionParameters::new()
    .with_tolerance(1e-6)
    .with_max_iters(100);
let intersection = ellipsoids::check_ellipsoid_intersection(ellipse1, ellipse2, Some(parameters));

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

shapers-0.3.0-pp310-pypy310_pp73-musllinux_1_2_x86_64.whl (7.9 MB view hashes)

Uploaded PyPy musllinux: musl 1.2+ x86-64

shapers-0.3.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

shapers-0.3.0-pp39-pypy39_pp73-musllinux_1_2_x86_64.whl (7.9 MB view hashes)

Uploaded PyPy musllinux: musl 1.2+ x86-64

shapers-0.3.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

shapers-0.3.0-pp38-pypy38_pp73-musllinux_1_2_x86_64.whl (7.9 MB view hashes)

Uploaded PyPy musllinux: musl 1.2+ x86-64

shapers-0.3.0-cp312-cp312-musllinux_1_2_x86_64.whl (7.9 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

shapers-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.8 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

shapers-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (340.4 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

shapers-0.3.0-cp312-cp312-macosx_10_12_x86_64.whl (373.5 kB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

shapers-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl (7.9 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

shapers-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

shapers-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (340.1 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

shapers-0.3.0-cp311-cp311-macosx_10_12_x86_64.whl (374.7 kB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

shapers-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl (7.9 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

shapers-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

shapers-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (340.2 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

shapers-0.3.0-cp39-cp39-musllinux_1_2_x86_64.whl (7.9 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

shapers-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

shapers-0.3.0-cp39-cp39-macosx_11_0_arm64.whl (341.2 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

shapers-0.3.0-cp38-cp38-musllinux_1_2_x86_64.whl (7.9 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

shapers-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

Supported by

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