{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Fitting" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from geo3d.fit import fit_plane\n", "from geo3d import Point, Plane, Vector" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plane Fit to Points" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fit a plane to an array of points. The fitted plane is defined by a `Plane.point` attribute giving the centroid of the fitted points, and a normal vector attribute `Plane.normal`." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "Plane(normal=<Vector at 2697000856352> [0. 0. 1.], point=<Point at 2697005808896> [0. 0.33333333 0. ])" }, "metadata": {}, "execution_count": 3 } ], "source": [ "points = [[1,0,0], [0,1,0], [-1,0,0]]\n", "plane = fit_plane(points)\n", "plane" ] }, { "source": [ "Express the plane as coefficients `a`, `b`, `c`, `d` in $a x + b y + c z + d = 0$:" ], "cell_type": "markdown", "metadata": {} }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "(0.0, 0.0, 1.0, -0.0)" }, "metadata": {}, "execution_count": 6 } ], "source": [ "(a,b,c,d) = plane.as_abcd()\n", "(a,b,c,d)" ] } ], "metadata": { "kernelspec": { "name": "Python 3.8.5 64-bit", "display_name": "Python 3.8.5 64-bit", "metadata": { "interpreter": { "hash": "37a1b074fb9c9ef4aacfb1a90000d2bd42cc9fa0cfc568212542dcf6ac5fbe47" } } }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5-final" } }, "nbformat": 4, "nbformat_minor": 4 }