Skip to contents

Determine coordinates of points on a line with center and direction, based on the distances from the center given in dist_center.

This works by using the vector formulation of the line equation assuming direction is a \(n\)-dimensional unit vector. In other words, considering \(\mathbf{d}=\) as.matrix(direction) (\(n \times 1\) vector), \(\mathbf{c}=\) as.matrix(center) (\(n \times 1\) vector), and \(\mathbf{w}=\) as.matrix(dist_center) (\(p \times 1\) vector), the coordinates of points on the line are given by:

\[\mathbf{P}=\mathbf{1}\,\mathbf{c}^T + \mathbf{w}\mathbf{d}^T\]

where \(\mathbf{P}\) is the \(p \times n\) matrix of point coordinates on the line, and \(\mathbf{1}\) is a \(p \times 1\) vector with all entries equal to 1.

Usage

points_on_line(center, direction, dist_center)

Arguments

center

Center of the line (\(n\)-component vector).

direction

Line direction (\(n\)-component unit vector).

dist_center

Distance of each point to the center of the line (\(n\)-component vector, where \(n\) is the number of points).

Value

Coordinates of points on the specified line (\(p \times n\) matrix).

Examples

points_on_line(c(5, 5), c(1, 0), seq(-4, 4, length.out=5)) # 2D, 5 points
#>      [,1] [,2]
#> [1,]    1    5
#> [2,]    3    5
#> [3,]    5    5
#> [4,]    7    5
#> [5,]    9    5

points_on_line(c(-2, 0, 0, 2), c(0, 0, -1, 0), c(10, -10)) # 4D, 2 points
#>      [,1] [,2] [,3] [,4]
#> [1,]   -2    0  -10    2
#> [2,]   -2    0   10    2