Learn R Programming

dynutils (version 1.0.11)

project_to_segments: Project a set of points to to set of segments

Description

Finds the projection index for a matrix of points x, when projected onto a set of segments defined by segment_start and segment_end.

Usage

project_to_segments(x, segment_start, segment_end)

Value

A list with components

x_proj

a matrix of projections of x onto the given segments.

segment

the index of the segment a point is projected on

progression

the progression of a projection along its segment

distance

the distance from each point in x to its projection in x_proj

Arguments

x

a matrix of data points.

segment_start

a matrix of segment start points.

segment_end

a matrix of segment end points.

Examples

Run this code
x <- matrix(rnorm(50, 0, .5), ncol = 2)
segfrom <- matrix(c(0, 1, 0, -1, 1, 0, -1, 0), ncol = 2, byrow = TRUE)
segto <- segfrom / 10
fit <- project_to_segments(x, segfrom, segto)

str(fit) # examine output

Run the code above in your browser using DataLab