| make_trig_vec | R Documentation | 
Projects point within a plane to a points based on angle and distance starting from one starting point.
make_trig_vec(start, angle, dist, prolong = NULL, prolong.opt = "m", d = Inf)
| start | Numeric vector of length two. First value sets x- and second value sets y-coordinate of the start. | 
| angle | Angles of the trigonometric vectors. | 
| dist | Distances from center to final points. | 
| prolong | Numeric vector or  | 
| prolong.opt | Character value. Either 'a' or 'm'. If 'a', the  | 
| d | Number of digits to which the output values are rounded. | 
Length of angle and dist should be equal or at least recyclable. This
means one of the two argument lengths should be a multiple of the other one.
d only affects the variables angle and dist.
Data.frame with four variables x, y, xend and yend. Each
row corresponds to a trigonometric vector. Values of x and y are equal
to input for center. Variables xend and yend correspond to the endpoints of each
projection.
library(tidyverse)
# argument input options -----
# not recyclable - fails
angle <- c(0, 90, 180)
dist <- c(10, 20)
trig_vecs <- make_trig_vec(start = c(0, 0), angle = angle, dist = dist)
# equal length - works
angle <- c(0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300)
dist <- c(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55)
trig_vecs <- make_trig_vec(start = c(0, 0), angle = angle, dist = dist)
trig_vecs
# recyclable - works
angle <- c(0, 55, 75, 200)
dist <- c(10)
trig_vecs <- make_trig_vec(start = c(0, 0), angle = angle, dist = dist)
trig_vecs
# plot results -----
ggplot(mapping = aes(x = x, y = y)) +
  geom_segment(
    data = trig_vecs,
    mapping = aes(xend = xend, yend = yend),
    arrow = arrow()
  )
# store prolonged projections -----
angle <- c(25, 135, 245, 315)
dist <- c(20, 22.5 , 25, 27.5)
trig_vecs_prol <-
  make_trig_vec(
    start = c(0, 0),
    angle = angle,
    dist = dist,
    prolong = c(1.1, 0.5), # stores additional projections with 1.1 and 0.5 times the length
    d = 2 # round info vars to two digits
    )
trig_vecs_prol
ggplot(mapping = aes(x = x, y = y)) +
  geom_segment(
    data = trig_vecs_prol,
    mapping = aes(xend = xend, yend = yend), # segments with original projection
    arrow = arrow()
  ) +
   geom_text(
    data = trig_vecs_prol,
    mapping = aes(
      x = xend_p1,
      y = yend_p1,
      label = str_c(angle, "; ", dist)
     )
   )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.