Skip to contents

Returns the planar angle measured from the positive x-axis towards the positive y-axis, in (-pi, pi]. That is the signed range the animovement suite uses for every direction (see anicore::wrap_angle()), and the one atan2() gives, except that a point on the negative x-axis is pi, never -pi. For [0, 2 * pi), wrap the result with anicore::wrap_angle(phi, "2pi").

Usage

cartesian_to_phi(x, y)

Arguments

x

A numeric vector of x-coordinates.

y

A numeric vector of y-coordinates.

Value

A numeric vector of azimuth angles in radians, in (-pi, pi].

Examples

cartesian_to_phi(1, 1)
#> [1] 0.7853982

# Below the x-axis, the azimuth is negative
cartesian_to_phi(-1, -1)
#> [1] -2.356194

# On the negative x-axis, it is pi
cartesian_to_phi(-1, 0)
#> [1] 3.141593

# For [0, 2 * pi), wrap the result
anicore::wrap_angle(cartesian_to_phi(-1, -1), "2pi")
#> [1] 3.926991