fitParabola | R Documentation |
This function fits a data set to a parabola, including any rotation angle.
fitParabola(x, y = NULL, searchAngle = c(-pi/2, pi/2), ...)
x |
vector of x-values, or a Nx2 array of x and y values. In the latter case, the input |
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 |
... |
For possible future expansion to pass to additional features. |
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.
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 |
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.
Carl Witthoft <carl@witthoft.com>
Some of the code is based on https://www.mathworks.com/matlabcentral/answers/80541
createConic
# 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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.