sortPointsRectangle {utilitiesR}R Documentation

sort vertices in a convex quadrilateral in anticlockwise fashion.

Description

sort vertices in a convex quadrilateral in anticlockwise fashion.

Usage

  sortPointsRectangle(pts, anticlockwise = TRUE,
    shift = FALSE, preserveStart = FALSE,
    index.return = FALSE)

Arguments

pts

the input points, nx2, colnames 'X' and 'Y'

anticlockwise

boolean, whether to return points in anticlockwise or clockwise fashion (default TRUE)

shift

default FALSE, whether to return results relative to origin

preserveStart

default FALSE, whether to start at the first input coordinate and proceed anticlockwise/ clockwise from there, or to start from the lower-left corner ('origin')

index.return

default FALSE, whether to return the indices into the original "pts" that reorder as specified.

Details

This calculates the coordinates of each vertex relative to the centroid of the points and sorts them by argument, assuming the bottom-left corner to be the one with angle closest to 5*pi/4.

Note that if two points are exactly equidistant to 5*pi/4, the one that occurs first in the 'pts' array is labelled the 'bottom-left corner' (as it is ambiguous in this case).

Value

the pts structure with columns 'X', 'Y', and rows sorted in anticlockwise or clockwise order. If "index.return" is TRUE, returns a list:

x

the points array

ix

indices into "pts" that reorder it into output$x

Additionally, the row-names of the output are labelled "bottom-left", "bottom-right", "top-left", and "top-right", based on an X-Y coordinate system, 0 being in the bottom left, increasing moving left-to-right and bottom-to-top.

Note

In versions <= 1.8.5, this used a naive method of determining "bottom-left", "top-right", etc. vertices, that would sometimes be WRONG! (particularly in the case of a quadrilateral that was in a diagonal orientation (where diagonally opposite corners had roughly equal Y values).


[Package utilitiesR version 2.0 Index]