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: intersection.of.lines

Function Description: intersection.of.lines

Finds the point where 2 lines intersect, given lines as 2 parameters each (intercept b then slope m). If the two lines are identical, it returns NAs. Note the check for both slopes being infinite (vertical lines).

Function Arguments:

ArgumentDefault Value
b1
m1
b2
m2

Function Source:

intersection.of.lines=function(b1,m1,b2,m2)
{
if(is.infinite(m1) & is.infinite(m2)) return(c(NA,NA))
if(m1==m2 & b1==b2) return(c(x=NA,y=NA))

if(is.infinite(m1) & !is.infinite(m2)) return(c(b1,m2*b1+b2))
else if(!is.infinite(m1) & is.infinite(m2)) return(c(b2,m1*b2+b1))

x=(b2-b1)/(m1-m2)
y=m1*x+b1

return(c(x,y))
}