Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8953531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:07:01+00:00 2026-06-15T14:07:01+00:00

There Is Something In Bresenham’s Floating Point Algorithm which annoying me. The Algorithm is

  • 0

There Is Something In Bresenham’s Floating Point Algorithm which annoying me.

The Algorithm is listed below :

void line(x0, x1, y0, y1)
{
  int deltax = x1 - x0;
  int deltay = y1 - y0;
  float error = 0;
  float deltaerr = Math.abs((float)deltay / (float)deltax);
  int y = y0

  for(int x=x0;x<=x1;x++)
  {
    SetPixel(x,y)
    error = error + deltaerr
    if (error >= 0.5)
    {
             y = y + 1
             error = error - 1.0
    }
  }
}

Suppose We Want to Draw Y=0.6X.
So In the first step for x=0 : error will be set as 0.6 and we will run into if statement and y
will increases. and error will be set to -0.4. how can the -0.4 will help us in next step?

So My problem is with this line of code :

error = error - 1.0

Why we should decease error by 1 ? I have read we do this because of readjustment ! how it can help us ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:07:02+00:00Added an answer on June 15, 2026 at 2:07 pm

    Error is accumulated. When it is greater than half a pixel, the line is moved one pixel over, and the error must then be corrected, again by a whole pixel.

    If you simply zero’d the error out, you would only have cancelled out part of the error, and thus the line will step again prematurely and would be the wrong gradient.

    In your example for y = 0.6x, if you calculate the error but zero it out, the following happens:

    error = 0;
    plot pixel;
    increment error. error = 0.6;
    error > 0.5, so move over and reset error to 0;
    plot pixel;
    increment error. error = 0.6;
    error > 0.5, so move over and reset error to 0;
    plot pixel;
    increment error. error = 0.6;
    error > 0.5, so move over and reset error to 0;
    ...
    

    So the line actually has a gradient of 1; Indeed any line with a gradient >= 0.5 will come out the same, which is obviously not very useful.

    If you do it correctly:

    error = 0;
    plot pixel;
    increment error. error = 0.6;
    error > 0.5, so move over and subtract one; error = -0.4;
    plot pixel;
    increment error. error = 0.2;
    plot pixel;
    increment error. error = 0.8;
    error > 0.5, so move over and subtract one; error = -0.2;
    ...
    

    The line has the correct gradient, because the error is acting as the fractional part of a fixed-point calculation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need the fastest sphere mapping algorithm. Something like Bresenham's line drawing one. Something
Is there something like Chef's open recipes on github which is recognized by community?
Is there something similar to setting -D javax.net.debug=ssl at the command line for Java
Is there something like HSQLDB (for Java) which can be run in a storage-in-file
Is there something similar to assignin() to fetch a variable which exists in another
Is there something in EF 4.1 that allows for a reconnect to a database
Is there something new about row-level security in SQL Server 2012? In 2008 and
Is there something equivalent to OmniCppComplete for java in vim ? I know of
Is there something akin to the .NET xsd.exe for java - generating classes from
Is there something like serialize/unserialize PHP functions in jQuery? These functions return a string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.