bresenham: Bresenham's Integer Line Drawing Algorithm

View source: R/bresenham.R

bresenhamR Documentation

Bresenham's Integer Line Drawing Algorithm

Description

Generate integer x,y points between vertices by Bresenham's algorithm.

Usage

bresenham(x, y = NULL, close = TRUE)

Arguments

x, y

the x and y coordinates a points to be joined where y can can be missing and the argument x is processed by xy.coords.

close

logical value indicating if the points form a closed polygon (without duplicating the first and last points)

Value

A list of length 2 with integer x,y coordinates connecting the vertices

Examples

# simple line
  bresenham(x = c(1, 4), y = c(1, 12))
# closed and open polygon
  verts <- list(x = c(1, 9, 6, 4, 2), y = c(9, 9, 2, 3, 1))
  plot(verts, type = "l", ylim = c(0, 10), xlim = c(0, 10))
  points(bresenham(verts)) # closed
  points(bresenham(verts, close = FALSE), col = 2, pch = 16)


ornelles/EBImageExtra documentation built on Aug. 10, 2022, 11:44 p.m.