fGetMovedLineSegments: Calculates coordiantes of a line segment moved from a base...

View source: R/fGetMovedLineSegments.R

fGetMovedLineSegmentsR Documentation

Calculates coordiantes of a line segment moved from a base line segment

Description

Calculates coordiantes of a line segment moved from a base line segment

Usage

fGetMovedLineSegments(x1, y1, x2, y2, distance, angle = pi/2)

Examples


library(data.table)

line_segment = data.table(
   x1 = c(0,10), y1 = c(0,10),
   x2 = c(1,5), y2 = c(1,5)
)

line_segment_top = fGetMovedLineSegments(
   x1 = line_segment[,x1], y1 = line_segment[,y1],
   x2 = line_segment[,x2], y2 = line_segment[,y2],
   distance = c(1,5),
   angle = c(pi/2,pi/4)
)
line_segment_top = data.frame(line_segment_top)

line_segment_bottom = fGetMovedLineSegments(
   x1 = line_segment[,x1], y1 = line_segment[,y1],
   x2 = line_segment[,x2], y2 = line_segment[,y2],
   distance = -c(1,5),
   angle = c(pi/2,pi/4)
)
line_segment_bottom = data.frame(line_segment_bottom)

library(ggplot2)

ggplot() +
   geom_segment(
      data = line_segment,
      aes(
         x = x1,
         y = y1,
         xend = x2,
         yend = y2
      )
   ) +
   geom_segment(
      data = line_segment_top,
      aes(
         x = x1,
         y = y1,
         xend = x2,
         yend = y2
      ),
      color = 'red'
   ) +
   geom_segment(
      data = line_segment_bottom,
      aes(
         x = x1,
         y = y1,
         xend = x2,
         yend = y2
      ),
      color = 'cyan'
   ) +
   coord_fixed()


thecomeonman/POV documentation built on Sept. 24, 2022, 8:31 p.m.