peri: Calculates the length of an arc defined by a function

View source: R/peri.R

periR Documentation

Calculates the length of an arc defined by a function

Description

1. This function returns the length of an arc which is defined by the function whose data points are present in the df dataframe.
2. The dataframe should be a 2 column dataframe with column names should be defined as 'X' and 'Y', where 'X' denotes the x-axis of the function.
3. The function also allows to calculate segments of the function by placing it within the xmin and xmax boundaries.

Usage

peri(df, xmin, xmax)

Arguments

df

Two column dataframe with columns defined a 'X' and 'Y' defining the arc whose length needs to be calculated

xmin

A single element numeric vector which defines the starting point of the section of the arc

xmax

A single element numeric vector which defines the ending point of the section of the arc

Value

The returned value is a single element numeric vector

Author(s)

Chitran Ghosal

Examples

#define a semi-circle in the range (-1, 1) centered at the origin with a radius of 1
X <- seq(-2, 2, by = 0.01)
Y <- rep(NA, times = length(X))
for(i in 1:length(X)){
  if( (X[i] < -1) | (X[i] > 1)){
  Y[i] <- 0
  }else{
  Y[i] <- sqrt(1 - X[i]^2)
  }
}
dat <- data.frame(X, Y)
names(dat) <- c('X', 'Y')
plot(dat$X, dat$Y, type = 'l', col = 'red', asp = 1)
peri(df = dat, xmin = 0, xmax = 1)
peri(df = dat, xmin = -1, xmax = 1 )

Chitran1987/StatsChitran documentation built on Feb. 23, 2025, 8:30 p.m.