dist.2d: Computes distance between two points in Cartesian space

View source: R/trig.funs.R

dist.2dR Documentation

Computes distance between two points in Cartesian space

Description

Computes distance between two points in Cartesian space using simple trigonometry functions

Usage

dist.2d(x1, x2, y1, y2)

Arguments

x1

Numeric; x position of coordinate 1

x2

numeric; x position of coordinate 2

y1

numeric; y position of coordinate 1

y2

numeric; y position of coordinate 2

Value

A single value of the distance between p[x1,y1] and p[x2,y2]

Examples

#Find the lengths of the sides of a tringle and print to plot
x <- c(0,3,2)
y <- c(0,3,0)
plot(x,y)
lines(x,y)
lines(x[c(1,3)],y[c(1,3)])
hyp <- dist.2d(x[1],x[2],y[1],y[2])
s1 <- dist.2d(x[1],x[3],y[1],y[3])
s2 <- dist.2d(x[2],x[3],y[2],y[3])
text(mean(x[1:2],mean(y[2:3])),labels=round(hyp,1))
text(mean(x[c(1,3)]),y[1]+0.25,labels=round(s1,1))
text(mean(x[c(2:3)]),mean(y[2:3]),labels=round(s2,1))

ckenaley/trackter documentation built on Jan. 9, 2025, 10:45 p.m.