Topic: Utilities

Topic Description:

Basic R utilities used in many packages and functions, such as date and string manipulations, statistical distributions, geometry of lines and distances. The R package date is required for the two data functions.



File: utilities/geometry.r

View File Source Download File No help file available

Function: perpendicular.distance

Function Description: perpendicular.distance

Distance from a point to a line (so it's the perpendicular distance); m and b are slope and intercept; x and y are coordinates. If both b,m and x,y are vectors, they must all be same length. Note check for infinite slope, meaning that the intercept b is the x-intercept.

Function Arguments:

ArgumentDefault Value
b
m
x
y

Arguments Description:

b: y-intercept m: line slope


Function Source:

perpendicular.distance=function(b,m,x,y)
{
len=ifelse(length(b)>length(x),length(b),length(x))
minf=is.infinite(m)
result=rep(NA,len)

result=sqrt((y-m*x-b)^2/(1+m^2))
result[minf]=abs(x-b)[minf]

return(result)
}