dist.2d.line: Computes orthogonal distance between a point and a line

Description Usage Arguments Details Value Examples

View source: R/trig.funs.R

Description

Computes 2D orthogonal distance between a point and a line given the points coordinates and the line's slope and intercept or model formula

Usage

1
dist.2d.line(x = NULL, y = NULL, slope = NULL, intercept = NULL, form = NULL)

Arguments

x

numeric, the x coordinate of the point

y

numeric, the y coordinate of the point

slope

numeric, the slope of the line

intercept

numeric, the slope of the line

form

formula of type lm describing the line, ignored if slope and intercept are specified

Details

if slope and intercept are missing, a model formula of form lm(y~x) can be passed to form.

Value

The distance between the point and line

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
x <- runif(1:10)
y <- x*0.5

xy.lm <- lm(y~x)

x.p <- y.p <- -3

#one way . . .
dist.2d.line(x.p,y.p,form=xy.lm)

#or another
dist.2d.line(x.p,y.p,slope=coef(xy.lm)[2],intercept=coef(xy.lm)[1])

ckenaley/trackter documentation built on Feb. 11, 2022, 6:43 a.m.