
Line Math?
I'm trying to create a line algorithim. I'm going crazy.
I just can't seem to get the math strait. Heres what i'm doing...
First, i am getting two points from the user, then getting the slope.
Then i do this...
1. Check which percent is smaller.
2. Moved on the axis with the smaller percent.
3. Loop to 1
Oddly enough(not really)
i will end up with a line like this
Code:
KEY: 0's = BLANK, # = LINE
# # 0 0 0
0 # 0 0 0
0 # 0 0 0
0 # 0 0 0
0 ##0 0 0
instead of a line like this...
Code:
# 0 0 0 0
0 # 0 0 0
0 # 0 0 0
0 # 0 0 0
0 0 # 0 0
In short, i can't think of a way to calculate when to move diagonly, insted of horizontaly or verticaly. I've thought about comparing the percents, but i don't know how close they should be for a diagonal move. (If you check the percent of both axis when they (should) move diagonal, they are usually pretty close.)
Any info would be greatly appreciated.

Do a web search for "bresenham line algorithm"

Perfect, thanks salem. If anyone else is interested ...