Self-intersecting Quadrilateral
R-bloggers 2025-05-26
[This article was first published on Online College Math Teacher, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
A quadrilateral is a polygon having four sides, four angles, and four vertices. A polygon means that the figure is a closed shape, meaning the last line segment connects back to the first one, effectively enclosing an area. Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
We usually think of quadrilaterals as squares, rectangles, parallelograms, trapezoids, rhombuses, or kites. (I was impressed that my four year-old granddaughter knew the last one, although she called it a diamond!)
However, a polygon may intersect itself. A five-sided star is one example, where the sides are connected to alternating vertices.
A quarilateral may also intersect itself. In the following diagram, the original quadrilateral has points A (0,0), B (4,0), C (3,3), D (1,4). The self-intersecting quadrilateral is formed from the original quadrilateral by shifting point D from (1,4) to (2, -2), so side CD crosses AB).
This self-intersecting quadrilateral is still four-sided and closed, so it is no less a quadrilateral than the original.Here is some R code:
# Self-intersecting quadrilaterallibrary(ggplot2)# Define coordinates for original quadrilateraloriginal_quad <- data.frame( x1 = c(0, 4, 3, 1), y1 = c(0, 0, 3, 4), x2 = c(4, 3, 1, 0), y2 = c(0, 3, 4, 0), group = c("AB", "BC", "CD", "DA"), labels = c("A", "B", "C", "D"))# Define coordinates for self-intersecting quadrilateral# Shift point D from (1,4) to (2, -2), so side CD crosses AB)stretched_quad <- data.frame( x1 = c(0, 4, 3, 2), y1 = c(0, 0, 3, -2), x2 = c(4, 3, 2, 0), y2 = c(0, 3, -2, 0), group = c("AB", "BC", "CD", "DA"), labels = c("A", "B", "C", "D"))# Define colors for each sidecolor_map <- c("AB" = "red", "BC" = "blue", "CD" = "green", "DA" = "purple")# Function to plot the quadrilateralplot_quad <- function(data, title, x_lim, y_lim) { ggplot(data) + geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2, color = group), size = 1.5) + # Draw each side geom_point(aes(x = x1, y = y1), size = 3, color = "black") + # Show points geom_text(aes(x = x1, y = y1, label = labels), vjust = -1, hjust = -0.5, size = 6, fontface = "bold") + # Label A, B, C, D scale_color_manual(values = color_map) + coord_fixed() + xlim(x_lim[1], x_lim[2]) + ylim(y_lim[1], y_lim[2]) + theme_minimal() + ggtitle(title)}# Expanded limits for full visibilityx_range <- c(-1, 7) y_range <- c(-3, 7) # Plot the original quadrilateralp1 <- plot_quad(original_quad, "Original Quadrilateral", x_range, y_range)# Plot the self-intersecting quadrilateralp2 <- plot_quad(stretched_quad, "Self-Intersecting Quadrilateral", x_range, y_range)# Display both plotslibrary(gridExtra)grid.arrange(p1, p2, ncol = 2)End
To leave a comment for the author, please follow the link and comment on their blog: Online College Math Teacher.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.