File Exchange

image thumbnail

Bresenham optimized for Matlab

version 1.1.0.0 (1.4 KB) by Aaron Wetzler
An implementation of the classic algorithm with code optimized for Matlab

12 Downloads

Updated 15 Jul 2010

View License

This code does not use any for loops and takes advantage of Matlabs internally optimized routines to produce a fast, optimized version of Bresenham's line drawing algorithm

Comments and Ratings (13)

Readability is not so good! But I appreciate your work. Thanks.

Missing a couple of terminating ';', but I don't care _because it works_ .

Xoab Perez

Excellent, especially because he will work with negative values!

SAASTN

I believe cumsum(q) is equivalent to round(0:(dy/dx):dy), anyway, I posted some code at: stackoverflow.com/a/43726466/2093077 that uses same logic but is about 20% faster.

Toby

im577

q=[0;diff(mod([floor(dx/2):-dy:-dy*dx+floor(dx/2)]',dx))>=0]
What does this equation mean?

Aaron

Very efficient, and well made. Code comments messy, and lines not terminated with ;.

Aaron

compact and elegant implementation

Updates

1.1.0.0

Fixed bug which allowed non integer points.
Fixed bug which prevented vertical or horizontal lines.

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags