Thread: Line Math?

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    31

    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.
    I never lie... except for right now.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Do a web search for "bresenham line algorithm"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    31
    Perfect, thanks salem. If anyone else is interested ...
    I never lie... except for right now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading a buffer line by line, while using system read
    By Hammad Saleem in forum C Programming
    Replies: 9
    Last Post: 05-27-2008, 05:41 AM
  2. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  3. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  4. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM
  5. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM