Skip to contents

Converts a spherical direction given as azimuth and elevation into the length-3 direction vector used by coord_3d() and light(). Both of those arguments take a vector of the form c(x, y, z) whose magnitude is ignored; direction() is an alternative way to express such a vector for people who find angles easier to reason about than components.

Usage

direction(azimuth, elevation)

Arguments

azimuth

Numeric bearing in degrees, measured clockwise from the positive y axis. Values outside [0, 360) are wrapped.

elevation

Numeric angle in degrees above the xy plane, between -90 and 90.

Value

A unit-length numeric vector of length 3.

Details

Azimuth is a compass-style bearing measured clockwise from the positive y axis, matching the convention used by terrain shading functions such as terra::shade(). Elevation is measured upward from the xy plane, so elevation = 90 points along the positive z axis and elevation = -90 points along the negative z axis.

The returned vector is scaled to unit length, but since both coord_3d() and light() normalize their inputs, the magnitude carries no meaning.

See also

coord_3d() and light(), which accept the result.

Examples

# The default viewing angle, expressed as a direction
direction(210, 30)
#> [1] -0.4330127 -0.7500000  0.5000000

# The default lighting angle: with the default camera anchor, light from
# the upper left of the plot, tilted 45 degrees toward the viewer
direction(315, 45)
#> [1] -0.5000000  0.5000000  0.7071068

# Light from directly above the data
light(direction = direction(0, 90), anchor = "scene")
#> Lighting specification:
#>   Ramp: smooth (neutral 45 deg) 
#>   Tone: lightness 
#>   Strength: shadow 0.8 , highlight 0.6 
#>   Direction: [ 0, 6.123e-17, 1 ] (directional lighting)
#>     azimuth: 180 deg, elevation: 90 deg
#>   anchor: scene 
#>   Lights: fill + color