# \donttest{
library(pliman)
# A 2 x 2 square
df <- draw_square(side = 2)
# square area
poly_area(df)
# polygon perimeter
poly_perimeter(df)
# center of mass of the square
cm <- poly_mass(df)
plot_mass(cm)
# The convex hull will be the vertices of the square
(conv_square <- conv_hull(df) |> poly_close())
plot_contour(conv_square,
col = "blue",
lwd = 6)
poly_area(conv_square)
################### Example with a polygon ##################
x <- c(0, 1, 2, 3, 5, 2, -1, 0, 0)
y <- c(5, 6.5, 7, 3, 1, 1, 0, 2, 5)
df_poly <- cbind(x, y)
# area of the polygon
plot_polygon(df_poly, fill = "red")
poly_area(df_poly)
# perimeter of the polygon
poly_perimeter(df_poly)
# center of mass of polygon
cm <- poly_mass(df_poly)
plot_mass(cm, col = "blue")
# vertices of the convex hull
(conv_poly <- conv_hull(df_poly))
# area of the convex hull
poly_area(conv_poly)
plot_polygon(conv_poly,
fill = "red",
alpha = 0.2,
add = TRUE)
############ example of circularity measures ################
tri <- draw_circle(n = 200, plot = FALSE)
plot_polygon(tri, aspect_ratio = 1)
poly_circularity_norm(tri)
set.seed(1)
tri2 <-
draw_circle(n = 200, plot = FALSE) |>
poly_jitter(noise_x = 100, noise_y = 100, plot = FALSE)
plot_polygon(tri2, aspect_ratio = 1)
poly_circularity_norm(tri2)
# }
Run the code above in your browser using DataLab