Jump to content
  • Advertisement
Sign in to follow this  

bresenham square filling

This topic is 3171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm trying to make a rotozoomer on an 8x32 LED matrix. I obviously don't have much room to work in, and this is mostly just an experiment to see if it can be done, but I'm running into problems. I have my LEDs displaying a checkerboard pattern of squares. When the checkerboard is not rotated, I can make the squares simply by doing s Bresenham lines from the top to the bottom of each square, where s is the size length in pixels. If this isn't the best method then let me know. Now say I rotate my checkerboard by theta around the center of the board, (cx,cy). Here's something thrown together to take a square's topleft point (x,y) and draw a square of side s (number of nodes a side contains) under rotation theta. It doesn't work well under rotation, and I think it's just not the right way to go about it.
void rectangle(float x, float y, int s, float theta)
    x-=cx;y-=cy; //translate so origin is board center
    float px1,py1,px2,py2;
    for (int i=0;i<s;i++)
      px1=x*cos(theta)-(y+i)*sin(theta); //rotation matrix for ith row in square
      py1 = x*sin(theta)+(y+i)*cos(theta);
      bres_line(px1+cx,py1+cy,px2+cx,py2+cy); //translate back to origin, plot line


Make theta 0, it works for my 8x32. When theta is nonzero, I can make out the checkerboard, but the squares are skewed or contain small gaps. I think that the rounding issues of bres_line create a different line at certain angles, or most angles, when the square side length is small compared to the spacing of the LEDs. Or rather, the top of a square has a line that is different from the line at the bottom of the square, and so gaps might appear. Either bres_line just won't work here, or it works and there's some other way to make sure it fills all the gaps. I read about people calculating the endpoints of the edges without rotation, then translating all of those, but it appears I'm kind of doing that here.. Is there a (working) way to draw and fill a square whose vertices you know on a square lattice under rotation? (note this post used to be a part of a different thread, but I decided to keep specific bres line issues separate from conceptual and general ideas for using LED matrices)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!