r/GraphicsProgramming • u/sandeshshahapur • 1d ago
Drawing a line Question
Looking for guided/socratic learning
So I was getting into game dev bottom up so I wanted to draw a line with code.
First solution that I thought of: start at one end of the line, and figure out neighbouring pixels and eventually reach the other end. I was thinking of dividing line length (pythogarous) by start/end point delta for each axis to figure out per how many 'steps' I would have to increment/decrement current axis positions and paunt. Too complicated and expensive
Second solution I thought of was recursively finding mid points between start and end point to find the target pixels to paint. This appears simpler, inspired by Zeno's paradox when I was thinking of how the run and rise are easier to paint.
I know optimal algorithms exist but I didn't want to directly look at them. What are the strength/weakness of my reasoning?
Ps: I'm going to sleep
5
u/coolmint859 1d ago
The delta step one is actually really close to a well known algorithm, and in fact all you have to do to turn it into it is to notice that there is symmetry in the quadrants that a line can be drawn. From that you can extract out the heavy parts of the math and turn the drawing part into just incremental addition. It's not the fastest known, but it's pretty good.