Skip to contents

Flips points across a vertical and/or horizontal line through the pivot (about_x, about_y): x = TRUE mirrors left-right (flips the x-coordinate), y = TRUE mirrors top-bottom (flips the y-coordinate). Setting both reflects through the pivot point itself (equivalent to a half turn, i.e. trans_rotate(pi, about_x, about_y)).

Usage

trans_reflect(x = FALSE, y = FALSE, about_x = 0, about_y = 0)

Arguments

x, y

Whether to flip the x/y coordinate. Default FALSE for both (i.e. the identity transform).

about_x, about_y

Pivot point coordinates. Default 0.

Details

Reflection across an arbitrary-angle line isn't exposed as a separate argument – it composes from existing pieces instead: rotate the desired line onto an axis, reflect, then rotate back, e.g. trans_rotate(-theta) + trans_reflect(y = TRUE) + trans_rotate(theta) reflects across a line through the origin at angle theta.

Examples

draw(shape_bezier(
  x = c(0, 0.5, 1),
  y = c(0, 1, 0.2),
  trans = trans_reflect(x = TRUE)
))


# overlay the original (faded) with each reflected copy (solid)
original <- shape_rectangle(
  x = 1,
  width = 1,
  height = 0.4,
  fill_alpha = 0.3,
  color_alpha = 0.3
)
draw(sketch() + original + (original + trans_reflect(x = TRUE)))

draw(sketch() + original + (original + trans_reflect(y = TRUE)))


# reflecting through both axes is equivalent to a half turn
draw(shape_bezier(
  x = c(0, 0.5, 1), y = c(0, 1, 0.2),
  trans = trans_reflect(x = TRUE, y = TRUE)
))