Skip to main content

No project description provided

Project description

r3fit

r3fit is a lightweight Rust library for fitting a circle to 2D points using a RANSAC-like method. It's built to handle noisy datasets by finding a circle that best fits the majority of inliers within a threshold.

Features

  • Fit a circle using random triplets of points
  • Detect and handle collinear cases
  • Configurable iterations and radius threshold
  • Deterministic mode via user-supplied RNG
  • Useful diagnostics (e.g. inlier counting)
  • Unit + property-based testing with proptest

Disclaimer

The Python bindings are not complete, and for that matter neither is the Rust library. This was mostly meant for me to use in a different project where I needed these very specific methods. I will most likely never update this ever again.

Installation

Rust

Add to your Cargo.toml:

[dependencies]
r3fit = "0.1.1"

Or run

$ cargo add r3fit

Python

$ pip install r3fit

Example (Rust)

Here's a simple example, more can be found in the unit tests.

use r3fit::Circle;

let points = vec![(0.0, 1.0), (1.0, 0.0), (-1.0, 0.0)];
let circle = Circle::fit(&points, 1000, 0.1).unwrap();

println!("{}", circle); // Circle: center=(0.0, 0.0), radius=1.0

assert_eq!(circle.x, 0.0);
assert_eq!(circle.y, 0.0);
assert_eq!(circle.r, 1.0);

As well as the corresponding image.

Rust Fit

Example (Python)

Here's a simple example for how to use it in Python.

import numpy as np
import r3fit

xs = np.array([[ 1.04074565,  0.06601208],
       [ 0.82567141,  0.62465951],
       [ 0.27211257,  1.05536321],
       [-0.3230298 ,  0.99809331],
       [-0.69139874,  0.49374204],
       [-1.03243453, -0.08763805],
       [-0.86916729, -0.52544072],
       [-0.22495387, -0.93536315],
       [ 0.25773429, -0.8631605 ],
       [ 0.8385662 , -0.52786283]])

circle = r3fit.fit(xs, 1000, 0.25)
print(circle) # Circle(x: -0.010063759065123072, y: 0.0614577470528755, r: 1.033185147957909)

As well as the corresponding image.

Python Fit

Derivation

There's a somewhat short document, where I put notes for deriving the main formulas used.

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

r3fit-0.1.3.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

r3fit-0.1.3-cp313-cp313-win_amd64.whl (167.6 kB view details)

Uploaded CPython 3.13Windows x86-64

File details

Details for the file r3fit-0.1.3.tar.gz.

File metadata

  • Download URL: r3fit-0.1.3.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.4

File hashes

Hashes for r3fit-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f62f40f81de8ea11fdfd81bb4d9aacbb67d660ff5235f61ffa9e726231067858
MD5 0bb75d367ec537729f56a2b71bab9e45
BLAKE2b-256 1fd9ee2b030789abd9672f509fed6109297a12bb32524c1b904111b02b26245b

See more details on using hashes here.

File details

Details for the file r3fit-0.1.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: r3fit-0.1.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 167.6 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.4

File hashes

Hashes for r3fit-0.1.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 638ce4fc626f6edb1aeb94239dab6f18a792b99175a0da1b4b1e896598ad1fd0
MD5 3a17315eff2cf6335419488802d2108b
BLAKE2b-256 fa2d54b1bc2f26ee780c880cd796ad105c96a445efeed423cf79e54c8adefe70

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