translation: Translation

View source: R/translation.R

translationR Documentation

Translation

Description

Compute a translation for a set of points. The transformed set of points is optionally add to the current plot.

Usage

translation(x, y, xtrans = 0, ytrans = 0, add = FALSE, ...)

Arguments

x, y

x and y coordinates of points to be translated (can also be a matrix, see details).

xtrans, ytrans

the x and y coordinates of the translation vector.

add

logical. If TRUE the set of transformed points is drawn as a polygon.

...

Additional arguments to be passed to polygon function (used only if add is TRUE).

Details

For details about what is a translation, see https://en.wikipedia.org/wiki/Translation_(geometry). Note that if x is a matrix with more than 2 columns, then x is the first column and y the second one.

Examples

# Example 1:
plot0(c(0,10),c(0,10))
x <- c(4,6,5)
y <- c(2,2,4)
polygon(x,y)
trans1 <- translation(x,y,xtrans=2,ytrans=5, add=TRUE, border=4, lwd=2)

# Example 2:
x <- c(2,4,3,1)
y <- c(1,1,3,3)
plot0(c(0,10),c(0,10))
polygon(x,y)
for (i in seq_len(6)) translation(x,y,xtrans=i,ytrans=i, add=TRUE,
border=i+1, lwd=2)

KevCaz/graphicsutils documentation built on Sept. 16, 2022, 10:05 a.m.