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

View source: R/trig.funs.R

dist.2d.lineR Documentation

Computes orthogonal distance between a point and a line

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

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

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 Jan. 9, 2025, 10:45 p.m.