fitParabola: Fit Data to Parabola

View source: R/fitParabola.R

fitParabolaR Documentation

Fit Data to Parabola

Description

This function fits a data set to a parabola, including any rotation angle.

Usage

fitParabola(x, y = NULL, searchAngle = c(-pi/2, pi/2), ...)

Arguments

x

vector of x-values, or a Nx2 array of x and y values. In the latter case, the input y is ignored.

y

vector of y-values.

searchAngle

Optional pair of angles, in radians, defining the limits of the search range to find the rotation angle of the parabola. Usually the default range -pi/2:+pi/2 works acceptable.

...

For possible future expansion to pass to additional features.

Details

fitParabola starts by doing a RANSAC-style search to find the optimum rotation angle. Once that is chosen, the data are rotated by that angle and a simple polynomial fit to the (rotated) vertical parabola is done.

Value

vertex

calculated vertex of the parabola

theta

angle of rotation relative to a vertical parabola

parA

the "ABCDEF" coefficients of the fitted parabola

parQ

the coefficients of the derotated parabola's simple quadratic polynomial, highest power first

cost

final value of the "cost" parameter used for optimization

Note

When the function fitConic is called with instructions to fit to a parabola, it passes the inputs to fitParabola and does nothing else. For parabolic data, then, either function will give the same result.

Author(s)

Carl Witthoft <carl@witthoft.com>

References

Some of the code is based on https://www.mathworks.com/matlabcentral/answers/80541

See Also

createConic

Examples


# Create vertical parabola with some noise
parP <-c(.5,0,0,2,-1,4)
xp <- seq(-5,5,by=0.05)
 partest <-createConic(xp,param = parP,ranFun = rnorm, noise = 1)
 plot(partest, pch= '.',asp=TRUE, cex=3)
 # rotate the data
 partestr <-xyrot(partest,theta = -.35)
 points(partestr,col='green',pch='.',cex=3)
 # do the fit
 parfit <-fitParabola(partestr)
 points(parfit$vertex,pch='X',col='blue') 
 parout <- createConic(xp,parfit$parA)
 lines(parout,col='red')


fitConic documentation built on Aug. 29, 2023, 1:12 a.m.