Skip to contents

This function will calculate the angle at each vertex of a polygon or polyline. The measured angle is that on the left side of the line, ie if it turns left the angle will be between 0 and pi, and if it turns right it will be between pi and 2pi.

Usage

approx_vert_angle(x, ...)

Arguments

x

A polyclid_polyline or polyclid_polygon vector

...

Arguments passed on to methods

Value

A numeric vector of matchng the vertices returned by euclid::vert()

Examples

# Polylines
sine <- polyline(
  seq(0, 2*pi, length.out = 20),
  sin(seq(0, 2*pi, length.out = 20))
)
approx_vert_angle(sine)
#>       11       12       13       14       15       16       17       18 
#>       NA 3.198748 3.267490 3.354400 3.439966 3.463283 3.400501 3.308881 
#>       19      110      111      112      113      114      115      116 
#> 3.231008 3.169427 3.084438 3.015695 2.928785 2.843220 2.819902 2.882685 
#>      117      118      119      120 
#> 2.974305 3.052177 3.113758       NA 

# Polygons
poly <- polygon(
  c(0, 10, 10, 0, 1, 5, 1),
  c(0, 0, 10, 10, 1, 1, 5),
  hole_id = c(1, 1, 1, 1, 2, 2, 2)
)
approx_vert_angle(poly)
#> [1] 1.5707963 1.5707963 1.5707963 1.5707963 1.5707963 0.7853982 0.7853982