Skip to contents

Computes the angle (in degrees) between a line, defined by two points with coordinates (x0, y0) and (x1, y1), and the specified axis.

Usage

starting_angle(x0, x1, y0, y1, swap_x_y = TRUE)

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.

Value

Angle in degrees with \(-180 <= angle <= 180\).

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

Pfister, R., Tonn, S., Schaaf, M., Wirth, R. (2024). mousetRajectory: Mouse tracking analyses for behavioral scientists. The Quantitative Methods for Psychology, 20(3), 217-229. doi:10.20982/tqmp.20.3.p217

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