math_circle_from3points: Circle from 3 points

View source: R/math.R

math_circle_from3pointsR Documentation

Circle from 3 points

Description

calculate circle using 3 points.The function returns a tibble (data frame) or a named vector with the centre point and the radius.

Usage

math_circle_from3points(x)

Arguments

x

matrix with 3 rows of points and 2 columns with the coordinates.

Value

Returns data frame with centre coordinates and Radius.

Author(s)

Florian Wagner florian.wagner@wagnius.ch

Examples

x <- matrix(c(c(-2.23 , 4.389 ),
              c(-1.001,-3.23  ),
              c(  15.5,-7.2365)),
              dimnames = list(c("x","y"),paste0("x",1:3)),
              ncol = 3)|>t()
math_circle_from3points(x)

library(tidyverse)
library(ggforce)
ggplot()+
  geom_point(data = as.data.frame(x),aes(x,y), color = "blue", size = 1.5)+
  geom_point(data = math_circle_from3points(x),aes(x_center,y_center))+
  geom_label(data = math_circle_from3points(x),
    aes(x_center,y_center,label = "center"), nudge_y = 1.5)+
  geom_circle(data = math_circle_from3points(x),
    aes(x0 = x_center , y0 = y_center,r = radius))+
  geom_label(data = as.data.frame(x),
    aes(x,y,label = paste("input:",row.names(as.data.frame(x)))), nudge_y = 1.5)+
  geom_hline(yintercept = 0)+
  geom_vline(xintercept = 0)+
  scale_x_continuous(limits = c(-5,22))+
  coord_fixed()

wagnius-GmbH/slvwagner documentation built on Jan. 19, 2025, 7:10 a.m.