Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ultra symmetrical line algorithm?

Tags:

java

algorithm

I ran into special case where I need to produce ultra symmetrical line or ray in 2D grid in order from (x0, y0) through (x1, y1) like this:

void drawSymmetricalLine(int x0, int y0, int x1, int y1)
{
    // loop and handle each (x, y)...
}

The actual problem lies in points where popular line drawing algorithms does NOT draw both coordinates (the other marked as x below) since it seems as thicken, which is desired in my case. Also performance is not important but simplicity.

Here is what I mean as ultra symmetrical lines:

ox   ooo
 oo     ooo


o    o
 o    o
  o   o
       o
like image 973
Jazz Avatar asked Aug 30 '10 17:08

Jazz


People also ask

Which is the best line algorithm?

Explanation: Bresenham's line algorithm is a very efficient and accurate algorithm.

What is Bresenham's line drawing algorithm with example?

Given the starting and ending coordinates of a line, Bresenham Line Drawing Algorithm attempts to generate the points between the starting and ending coordinates.


1 Answers

You can probably use Bresenham's line algorithm and modify it slightly so when the step change to move the draw position from one row to another you paint both the before and after pixels on the y-axis for the current x-axis.

like image 100
Mike Q Avatar answered Oct 17 '22 04:10

Mike Q