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

  • SEARCH
  • Home
  • 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 6772915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:36:18+00:00 2026-05-26T15:36:18+00:00

So I am writing a program which is moving circle through a line, I

  • 0

So I am writing a program which is moving circle through a line, I need the coordinates of line pixels, so I am using y = mx + b formula, but the coordinates of y don’t change if I use x++, can anyone tell me what i am doing wrong?

Here is a part of my code, where i am using this formula:

void draw_picture(Canvas & canvas) {

srand((unsigned)time(0));

PairXY a(200,400);
PairXY b(300,100);
int o=20;
Line l(a,b);
double x=0;
Circle cir(a,o);
draw_circle(cir, canvas);
draw_line(l, canvas);

x=a.x;
for (int i=20; i>0; i--){

  x++;

  ///////

  double m = (b.y-a.y)/(b.x-a.x);
  double b1 = a.y - m * x;
  double y = m * x + b1; 

  ///////

  a.x=x;
  a.y=y;

  Circle cir1(a,o); 
  draw_circle(cir1, canvas);
 }  
}
  • 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-05-26T15:36:18+00:00Added an answer on May 26, 2026 at 3:36 pm
    double m = (b.y-a.y)/(b.x-a.x);
    double b1 = a.y - m * x;
    double y = m * x + b1; 
    

    C++ does not use what you do with a value to influence how the value is computed. The fact that you are assigning these values to doubles does not cause them to be computed as doubles. Since the math is on integers, you get integer math, which is definitely not what you want.

    One fix:

    double m = (b.y-a.y) / (double) (b.x-a.x);
    double b1 = a.y - (double) m * x;
    double y = m * (double) x + b1;
    

    By forcing at least one parameter to be a double in each operation, you force the other to be promoted to a double as well and force the operation to be done on the doubles.

    Note that the first line is only safe if y is a signed type. If not, (b.y-a.y) could underflow. In that case, you need (b.y - (double) a.y).

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

Sidebar

Related Questions

I'm writing a program which takes filenames and options on the command line in
I need to writing a Delphi program which will monitor a folder for changes
I'm writing a program which will need to do a very large number of
I am writing a program in which I need to get a random value
I am writing a program which will type a line of text in 5
I'm writing program which captures audio in C# using DirectShow library and writes it
I am writing a program which has two panes (via CSplitter ), however I
I'm writing a program which has both an ASP.NET configuration system and a Silverlight
I am writing a program which if I compile on a Suse 10 32-bit
I'm writing a program which will use scan conversion on triangles to fill in

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.