Simple experimental functions working on 2D and 3D point sets to fit planes, estimate geometric transforms, etc.
It is header-only currently. Requires the ASL 1.11.10+ library.
Currently available functions (may change in the future):
-
fitPlaneXY: fits a plane z = a x + b y + c to a set of 3D points and returns [a, b, c]
-
fitPlane: fits a plane to a set of 3D points and returns it as a point and normal
-
fitLine: fits a line to a set of 2D or 3D points
-
fitCircle: fits a circle to a set of 2D or 3D points
-
fitEllipse: fits an ellipse to a set of 2D points
-
fitSphere: fits a sphere to a set of 3D points.
-
findAffineTransform: Estimates the affine transform between two sets of 2D or 3D points
-
findRigidTransform: Estimates the rigid transform between two sets of 2D or 3D points
-
findHomography: Computes a perspective transform between two sets of 2D points
-
fitPoly: fits a polynomial (univariate y=f(x), bivariate z=f(x,y) or trivariate w=f(x,y,z)) of any degree to a set of 2D, 3D or 4D points and returns its coefficients
-
shiftPoly: makes coefficients of
p(x+cx),p(x+cx,y+cy), orp(x+cx,y+cy,z+cz)using the same coefficient order asfitPoly. For example,shiftPoly(a, -cx)restores the input coordinates of a fit centered atcx. -
polynomial: evaluates a polynomial (single variable, bivariate or trivariate)
Can easily be included using CMake in other projects where ASL is already. For example:
There are also robust versions of those using a RANSAC algorithm in <pointsR.h>. They are named the same with an added 'R' (like fitPlaneR or findAffineTransformR) and they receive an extra argument for the outlier threshold distance.
include(FetchContent)
FetchContent_Declare(aslpoints URL https://github.com/aslze/aslpoints/archive/1.7.2.zip)
FetchContent_MakeAvailable(aslpoints)
target_link_libraries(myprogram asls aslpoints)fitPoly subtracts the centroid before solving and returns coefficients in the original coordinates. Centering improves the fitting system, but evaluating expanded coefficients far from the origin can still suffer from cancellation.