Skip to contents

shape_ellipse is a drawable defined by a centroid and independent x/y radii; its vertices are computed as evenly spaced points around the circumference, generalizing shape_circle() (which is a shape_ellipse with equal radii in both directions).

shape_ellipses() is a vectorized version of shape_ellipse(): each argument may be a vector, recycled against the others. The result is a sketch containing one shape_ellipse() per recycled row, rather than a single drawable.

Usage

shape_ellipse(
  x = 0,
  y = 0,
  x_radius = 1,
  y_radius = 1,
  n = 100L,
  trans = trans_identity(),
  ...
)

shape_ellipses(
  x = 0,
  y = 0,
  x_radius = 1,
  y_radius = 1,
  n = 100L,
  trans = trans_identity(),
  ...
)

Arguments

x, y

Centroid coordinates. Default 0.

x_radius, y_radius

Radii along the x and y axes. Must be non-negative. Default 1.

n

Number of points used to approximate the ellipse. Default 100L.

trans

A trans object applied to the shape's computed points. Default trans_identity() (no transform).

...

Arguments passed to style().

Value

A drawable.

For shape_ellipses(), a sketch.

Details

Recycling uses purrr::pmap()'s own vctrs-based rules: any length-1 element is broadcast to the common length; mismatched lengths greater than 1 raise an error.

Examples

draw(shape_ellipse(x_radius = 2, y_radius = 1))

draw(shape_ellipse(
  x = 1,
  y = 1,
  x_radius = 0.5,
  y_radius = 1,
  n = 6,
  color = "darkred"
))

draw(shape_ellipse(
  x_radius = 2,
  y_radius = 1,
  fill = fill_gradient(angle = 90)
))


# rotating an ellipse (rather than swapping its radii) tilts its axes
draw(shape_ellipse(
  x_radius = 2,
  y_radius = 0.7,
  trans = trans_rotate(pi / 6)
))


draw(shape_ellipses(x = 1:3, x_radius = c(0.5, 1, 1.5), y_radius = 0.5))

draw(shape_ellipses(
  x = 0, y = 0, x_radius = 1, y_radius = 0.3,
  trans = purrr::map(seq(0, pi, length.out = 6), trans_rotate)
))