Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

project2segment

Move Point To Nearest Line


Description

Given a point pattern and a line segment pattern, this function moves each point to the closest location on a line segment.

Usage

project2segment(X, Y)

Arguments

X

A point pattern (object of class "ppp").

Y

A line segment pattern (object of class "psp").

Details

For each point x in the point pattern X, this function finds the closest line segment y in the line segment pattern Y. It then ‘projects’ the point x onto the line segment y by finding the position z along y which is closest to x. This position z is returned, along with supplementary information.

Value

A list with the following components. Each component has length equal to the number of points in X, and its entries correspond to the points of X.

Xproj

Point pattern (object of class "ppp" containing the projected points.

mapXY

Integer vector identifying the nearest segment to each point.

d

Numeric vector of distances from each point of X to the corresponding projected point.

tp

Numeric vector giving the scaled parametric coordinate 0 <= tp <= 1 of the position of the projected point along the segment.

For example suppose mapXY[2] = 5 and tp[2] = 0.33. Then Y[5] is the line segment lying closest to X[2]. The projection of the point X[2] onto the segment Y[5] is the point Xproj[2], which lies one-third of the way between the first and second endpoints of the line segment Y[5].

Author(s)

and Rolf Turner r.turner@auckland.ac.nz

See Also

nearestsegment for a faster way to determine which segment is closest to each point.

Examples

X <- rsyst(square(1), nx=5)
  Y <- as.psp(matrix(runif(20), 5, 4), window=owin())
  plot(Y, lwd=3, col="green")
  plot(X, add=TRUE, col="red", pch=16)
  v <- project2segment(X,Y)
  Xproj <- v$Xproj
  plot(Xproj, add=TRUE, pch=16)
  arrows(X$x, X$y, Xproj$x, Xproj$y, angle=10, length=0.15, col="red")

spatstat.geom

Geometrical Functionality of the 'spatstat' Family

v2.1-0
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Tilman Davies [ctb], Ute Hahn [ctb], Abdollah Jalilian [ctb], Sebastian Meyer [ctb], Suman Rakshit [ctb], Dominic Schuhmacher [ctb], Rasmus Waagepetersen [ctb]
Initial release
2021-04-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.