Learn R Programming

fitConic (version 1.2.1)

fitParabola: 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), ...)

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

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.

Author

Carl Witthoft <carl@witthoft.com>

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.

References

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

See Also

createConic

Examples

Run this code

# 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')

Run the code above in your browser using DataLab