# nearestPointOnSegment

From maptools v0.9-9
by Roger Bivand

##### Get the nearest point on a segment to a given point

This function calculates the coordinates of and the distance to the nearest point on a segment to a given point. This function does not work with geographic coordinates.

- Keywords
- spatial

##### Usage

`nearestPointOnSegment(s, p)`

##### Arguments

- s
A matrix representing the coordinates of the segment. The matrix has 2x2 dimension where each row represents one of the end points.

- p
A vector representing the X and Y coordinates of the point.

##### Value

A vector with three numeric values representing X and Y coordinates of the nearest point on a segment to a given point as well as the distance between both points.

##### References

The function was ported to R based on this code: http://pastebin.com/n9rUuGRh

##### See Also

##### Examples

```
# NOT RUN {
segment = cbind(c(1,2),c(1,1.5))
point = c(1.2,1.5)
nearestPointOnSegment(segment, point)
# }
```

*Documentation reproduced from package maptools, version 0.9-9, License: GPL (>= 2)*

### Community examples

Looks like there are no examples yet.