getRadius | R Documentation |
This function estimates the center and radius of a circle that best fits four points provided by the user. The user interacts with the plot to select four points, and the function optimizes the parameters (center and radius) using a least squares approach.
getRadius(frame)
frame |
The plot or frame to display the points and interact with the user. |
The function plots the provided 'frame' and then uses the 'locator()' function to allow the user to click on four points. The function then performs optimization using the 'optim()' function to minimize the difference between the selected points and the circle's equation.
The objective function ('ftemp') calculates the sum of squared differences between the points and the expected distance from the circle's center.
A vector of length 3, where: - The first element is the x-coordinate of the circle center (cx). - The second element is the y-coordinate of the circle center (cy). - The third element is the radius of the circle (r).
if(interactive()){
path <- system.file('extdata/data.tiff', package='BioTrajectory')
im <- tiff::readTIFF(path)
im <- imager::as.cimg(t(im[,,1]))
frame <- plot(im)
circle_params <- getRadius(frame)
print(circle_params)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.