IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Self-intersecting Quadrilateral

    Jerry Tuttle发表于 2025-05-26 05:21:00
    love 0
    [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.

          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 quadrilateral
    library(ggplot2)
    
    # Define coordinates for original quadrilateral
    original_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 side
    color_map <- c("AB" = "red", "BC" = "blue", "CD" = "green", "DA" = "purple")
    
    # Function to plot the quadrilateral
    plot_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 visibility
    x_range <- c(-1, 7)  
    y_range <- c(-3, 7)  
    
    # Plot the original quadrilateral
    p1 <- plot_quad(original_quad, "Original Quadrilateral", x_range, y_range)
    
    # Plot the self-intersecting quadrilateral
    p2 <- plot_quad(stretched_quad, "Self-Intersecting Quadrilateral", x_range, y_range)
    
    # Display both plots
    library(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.
    Continue reading: Self-intersecting Quadrilateral


沪ICP备19023445号-2号
友情链接