A python library for fitting 3D geometric shapes
This library performs least square fits on a series of 3D geometries. It will try to minimize the sum of the squares of the distance to these objects. For several geometric shapes this can be done algebraicly, but for most this is performed iteravely using scipy.
It also supports the use of a weights vector to give certain points more importance, it will then minize the following formula, where w_i
is the weight vector and d_i
the distance from the geometric shape to point i
.
The following geometries are currently supported:
-
line: An infinitely long line, parameterized by an anchor_point on the line and a direction.
-
plane: An infite plane parameterized by an anchor_point and a plane normal.
-
sphere: A sphere defined by the center and a positve radius.
-
circle: A circle positioned in 3D. It is given by a center and direction. The direction is the normal of the plane that this circle lies in. The third parameter is the radius
-
cylinder: A inifintely long cylinder, parameterized by an anchor_point and direction in the same way as the line is. And a radius of the cylinder.
-
torus: Similar to a circle in 3D, but with an extra tube radius. The radius of the circle is called major_radius, the radius of the tube is called minor_radius.
For some notebook examples see fit_example, plot_o3d.
Create some random data along a circle:
>>> points = np.random.uniform(low=-1, high=1, size=(3, 100))
>>> points[2] /= 10
>>> points[:2] /= np.linalg.norm(points[:2], axis=0) * np.random.uniform(
low=0.9, high=1.1, size=(100,)
)
>>> points = points.T
Perform a least square fit:
initial_guess = geom3d.Circle3D([0, 0, 0], [0, 0, 1], 1)
circle = fit3d.circle3D_fit(points, initial_guess=initial_guess)
circle
Plot the results using Open3D, if you have that installed:
geomfitty.plot.plot([point, circle])
First clone the repository
git clone [email protected]:mark-boer/geomfitty.git
cd geomfitty
Install the package as in editable mode and install the dev requirements.
poetry install
Run the tests
poetry run pytest
poetry run mypy .
Run the code formatter
poetry run black .
poetry run isort .
- Add cone
- Allow fits to run without initial guess
- Cylinder
- Circle3D
- Torus
- Add Coordinate transformations
- Add 2D geometries
- Line
- Circle
- Ellipse
- Add Sphinx documentation