utils_shapes {pliman} | R Documentation |
Utilities for drawing coordinates of known shapes
Description
The functions computes the coordinates of common shapes such as squares triangles, rectangles and circles.
-
draw_circle()
Draws a perfect circle with a desired radius. -
draw_square()
Draws a square with a desired side. -
draw_rectangle()
Draws a rectangle given two desired sides. -
draw_trian_equi()
Draws an equilateral triangle with a desired side. -
draw_trian_rect()
Draws a triangle rectangle given two cathetus. -
draw_n_tagon()
Draws polygons withn
sides
Usage
draw_circle(radius = 1, n = 1000, plot = TRUE)
draw_square(side = 2, plot = TRUE)
draw_rectangle(side1 = 2, side2 = 3, plot = TRUE)
draw_trian_equi(side = 2, plot = TRUE)
draw_trian_rect(cat1 = 1, cat2 = 2, plot = TRUE)
draw_n_tagon(n, plot = TRUE)
Arguments
radius |
The radius of the circle. Defaults to |
n |
The number of sides in the |
plot |
Plots the result? Defaults to |
side |
The side of the square/equilateral triangle. Defaults to |
side1 , side2 |
The first and second sides of the rectangle. Defaults to
|
cat1 , cat2 |
The first and second cathetus of the right triangle.
Defaults to |
Value
A data frame with the x
and y
coordinates
Examples
########## An example of a circle ##########
library(pliman)
radius <- 3
circ <- draw_circle(radius = radius)
# area
pi * radius ^ 2
poly_area(circ)
# perimeter
2 * pi * radius
poly_perimeter(circ)
############ An example of a square ############
side <- 2
(square <- draw_square(side = side))
# area
side ^ 2
poly_area(square)
# perimeter
side * 4
poly_perimeter(square)
############ An example of a rectangle ############
side1 <- 2
side2 <- 3
(rect <- draw_rectangle())
# area
poly_area(rect)
# perimeter
poly_perimeter(rect)
########### An example of an equilateral triangle #########
side <- 1 # defaults
(trig <- draw_trian_equi(side = side))
### area (b*h / 2)
# height of the triangle
(h <- (side * sqrt(3)) / 2)
side * h / 2
poly_area(trig)
### perimeter (side * 3)
poly_perimeter(trig)
########### An example of a rectangle triangle ##########
cat1 <- 2
cat2 <- 3
(df <- draw_trian_rect(cat1, cat2))
# area
(cat1 * cat2) / 2
poly_area(df)
# perimeter
cat1 + cat2 + sqrt(cat1^2 + cat2^2)
poly_perimeter(df)
############ An creating shapes with n sides ############
side <- 2
(square <- draw_square(side = side))
# area
side ^ 2
poly_area(square)
# perimeter
side * 4
poly_perimeter(square)