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

ringDirxy

Compute direction of points in a polygon.


Description

This is (private, not exported) R code replacing the call to maptools:::.ringDirxy, which links to C code.

Usage

.ringDirxy(xy)

Arguments

xy

a two-column matrix with x and y coordinates of at least 3 points which form a polygon

Value

Returns the integer -1 if the direction is counter-clockwise and 1 if the direction is clockwise.

Note

The function uses vectorization and should not be very much slower than the original.

Author(s)

Daniel Sabanes Bove

Examples

## create test polygon ordered clockwise
nPoints <- 200
sequence <- seq(from=1, to=10, length=nPoints)
firstHalf <- sequence[1:(nPoints/2)]

test <- cbind(x=c(sequence, rev(sequence)),
              y=c(firstHalf, rev(firstHalf), -firstHalf, -rev(firstHalf)))
plot(test,
     type="n")
polygon(test)

## compute direction with this and the original function
stopifnot(identical(BayesX:::.ringDirxy(test), as.integer(+1)))
## Not run: maptools:::.ringDirxy(test)

## now transform to counter-clockwise and try that
test[, 2] <- - test[, 2]
stopifnot(identical(BayesX:::.ringDirxy(test), as.integer(-1)))
## Not run: maptools:::.ringDirxy(test)

BayesX

R Utilities Accompanying the Software Package BayesX

v0.3-1
GPL-2 | GPL-3
Authors
Nikolaus Umlauf [aut, cre], Thomas Kneib [aut], Nadja Klein [aut], Felix Heinzl [ctb], Andreas Brezger [ctb], Daniel Sabanes Bove [ctb]
Initial release
2019-08-23

We don't support your browser anymore

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