getRadius: Estimate the Radius of a Circle Fitting Four Points

View source: R/getRadius.R

getRadiusR Documentation

Estimate the Radius of a Circle Fitting Four Points

Description

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.

Usage

getRadius(frame)

Arguments

frame

The plot or frame to display the points and interact with the user.

Details

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.

Value

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).

Examples

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)
}


BioTrajectory documentation built on June 8, 2025, 11:54 a.m.