Computes the angle (in degrees) between a line,
defined by two points with coordinates (x0
, y0
)
and (x1
, y1
), and the specified axis.
Arguments
- x0
x-value of the first point.
- x1
x-value of the second point.
- y0
y-value of the first point.
- y1
y-value of the second point.
- swap_x_y
Whether to compute the angle relative to the x or y axis. Defaults to
TRUE
, indicating that the angle is relative to the y axis.
Details
If the angle is computed relative to the x axis, counterclockwise changes are counted as positive. If the angle is computed relative to the y axis, clockwise changes are counted as positive.
References
Wirth, R., Foerster, A., Kunde, W., & Pfister, R. (2020). Design choices: Empirical recommendations for designing two-dimensional finger tracking experiments. Behavior Research Methods, 52, 2394 - 2416. doi:10.3758/s13428-020-01409-0
Examples
# Note that not the mathematical definition of angle is used by default:
starting_angle(0, 1, 0, 0)
#> [1] 90
starting_angle(0, 1, 0, 0, swap_x_y = FALSE)
#> [1] 0
# angles are clockwise and relative to the y-axis.
# Note that return values are in the range [-180, 180], not [0, 360]:
starting_angle(0, -1, 0, -1)
#> [1] -135
starting_angle(0, 1, 0, -1, swap_x_y = FALSE)
#> [1] -45