Learn R Programming

princurve (version 2.1.6)

project_to_curve: Project a set of points to the closest point on a curve

Description

Finds the projection index for a matrix of points x, when projected onto a curve s. The curve need not be of the same length as the number of points.

Usage

project_to_curve(x, s, stretch = 2)

Arguments

x

a matrix of data points.

s

a parametrized curve, represented by a polygon.

stretch

A stretch factor for the endpoints of the curve, allowing the curve to grow to avoid bunching at the end. Must be a numeric value between 0 and 2.

Value

A structure is returned which represents a fitted curve. It has components

s

The fitted points on the curve corresponding to each point x

ord

the order of the fitted points

lambda

The projection index for each point

dist

The total squared distance from the curve

dist_ind

The squared distances from the curve to each of the respective points

See Also

principal_curve

Examples

Run this code
# NOT RUN {
t <- runif(100, -1, 1)
x <- cbind(t, t ^ 2) + rnorm(200, sd = 0.05)
s <- matrix(c(-1, 0, 1, 1, 0, 1), ncol = 2)

proj <- project_to_curve(x, s)

plot(x)
lines(s)
segments(x[, 1], x[, 2], proj$s[, 1], proj$s[, 2])
# }

Run the code above in your browser using DataLab