rounded_rectangle: Generate rectangle with rounded corners

Description Usage Arguments Value Note Author(s) Examples

View source: R/rounded-rectangle.R

Description

This function computes the vertices of a rectangle with rounded corners.

Usage

1
2
3
4
5
6
7
8
rounded_rectangle(
  center = c(0, 0),
  width = 1,
  height = 1,
  rotation = 0,
  corner.radius = NULL,
  vertices.per.corner = 50
)

Arguments

center

The center/centroid of the shape. Can either be a 1 x 2 data frame/matrix or a numeric vector length 2.

width, height

The width and height of the rectangle before the corners are rounded.

rotation

The amount of rotation applied to the shape, in radians.

corner.radius

The radius of the circular arcs. Should be less than min(width, height) / 2.

vertices.per.corner

The number of vertices that each circular arc consists of.

Value

A data frame containing the columns x and y, where each row is a vertex in the rounded rectangle.

Note

The result may contain less than 4*vertices.per.corner vertices. In certain situations, consecutive vertices will end up having the same coordinates. The duplicates are then removed.

Author(s)

Mathias Isaksen mathiasleanderi@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Create a rounded rectangle
vertex.df = rounded_rectangle(
  center = c(2, 5),
  width = 3,
  height = 6,
  rotation = pi/4,
  corner.radius = 1
)

# How the rounded rectangle looks:
library(ggplot2)
ggplot()+
  geom_polygon(data = vertex.df, aes(x = x, y = y))+
  coord_fixed()

mathiasisaksen/artKIT documentation built on Dec. 21, 2021, 2:52 p.m.