Learn R Programming

matlib (version 0.6.0)

point_on_line: Position of a point along a line

Description

A utility function for drawing vector diagrams. Find position of an interpolated point along a line from x1 to x2.

Usage

point_on_line(x1, x2, d, absolute = TRUE)

Arguments

x1
A vector of length 2 or 3, representing the starting point of a line in 2D or 3D space
x2
A vector of length 2 or 3, representing the ending point of a line in 2D or 3D space
d
The distance along the line from x1 to x2 of the point to be found
absolute
logical; if TRUE, d is taken as an absolute distance along the line; otherwise it is calculated as a relative distance, i.e., a fraction of the length of the line

Value

  • The interpolated point, a vector of the same length as x1

See Also

Other vector diagrams: Proj, arrows3d, corner, vectors3d, vectors

Examples

Run this code
x1 <- c(0, 0)
x2 <- c(1, 4)
point_on_line(x1, x2, 0.5)
point_on_line(x1, x2, 0.5, absolute=FALSE)
point_on_line(x1, x2, 1.1)

y1 <- c(1, 2, 3)
y2 <- c(3, 2, 1)
point_on_line(y1, y2, 0.5)
point_on_line(y1, y2, 0.5, absolute=FALSE)

Run the code above in your browser using DataLab