Equation of a line (y=mx+c)

G

gbvk

Hello,

i'm trying to implement "y=mx+c" into code to find the intercept of a
line.


#include <iostream.h>
#include <stdlib.h>
#include <math.h>

void main ()
{
int Ax, Ay, Bx, By;
float Dx, Dy, Dist, Grad;

cout<<"Please enter the 'x' coordinate of the first point: "<<endl;
cin>>Ax;
cout<<"Please enter the 'y' coordinate of the first point: "<<endl;
cin>>Ay;
cout<<"Please enter the 'x' coordinate of the second point: "<<endl;
cin>>Bx;
cout<<"Please enter the 'y' coordinate of the second point: "<<endl;
cin>>By;

Dx=Ax-Bx;
Dy=Ay-By;
Grad= Dy/Dx;

cout<<"Gradient = "<<Grad<<endl;
}

is what i have so far to find "m".

Ex A(2,3) B(6,5)

As I understand the fomula would be;

y-Ay = Grad*(x-Ax)

substituing from A;

y-3=0.5*(x-2)
y-3=0.5x-1
y=0.5x+2

therefore "c" would be: 2

any idea on how i could code this?


G
 
V

Victor Bazarov

i'm trying to implement "y=mx+c" into code to find the intercept of a
line.

[..multiple snips throughout..]
is what i have so far to find "m".

As I understand the fomula would be;

y-Ay = Grad*(x-Ax)

any idea on how i could code this?

y - Ay = Grad * x - Grad * Ax
y = Grad * x - Grad * Ax + Ay

y = Grad * x + (Ay - Grad * Ax)

Does this remind you of something? Please don't ask questions that
don't belong to this newsgroup. Figure your math first, figure your
algorithm second, translate it to C++ to the best of your ability
(even if almost none), then come back asking for help.

V
 
G

gbvk

i'm trying to implement "y=mx+c" into code to find the intercept of a
line.
[..multiple snips throughout..]
is what i have so far to find "m".
As I understand the fomula would be;
y-Ay = Grad*(x-Ax)
any idea on how i could code this?

y - Ay = Grad * x - Grad * Ax
y = Grad * x - Grad * Ax + Ay

y = Grad * x + (Ay - Grad * Ax)

Does this remind you of something? Please don't ask questions that
don't belong to this newsgroup. Figure your math first, figure your
algorithm second, translate it to C++ to the best of your ability
(even if almost none), then come back asking for help.

V

I asked for help on C++ coding.
Sorry Newsgroup commander!
 
G

gbvk

i'm trying to implement "y=mx+c" into code to find the intercept of a
line.
[..multiple snips throughout..]
is what i have so far to find "m".
As I understand the fomula would be;
y-Ay = Grad*(x-Ax)
any idea on how i could code this?

y - Ay = Grad * x - Grad * Ax
y = Grad * x - Grad * Ax + Ay

y = Grad * x + (Ay - Grad * Ax)

Does this remind you of something? Please don't ask questions that
don't belong to this newsgroup. Figure your math first, figure your
algorithm second, translate it to C++ to the best of your ability
(even if almost none), then come back asking for help.

V

strange how I got an answer then isn't it?
 
V

Victor Bazarov

i'm trying to implement "y=mx+c" into code to find the intercept of
a line.
[..multiple snips throughout..]
is what i have so far to find "m".
As I understand the fomula would be;
y-Ay = Grad*(x-Ax)
any idea on how i could code this?

y - Ay = Grad * x - Grad * Ax
y = Grad * x - Grad * Ax + Ay

y = Grad * x + (Ay - Grad * Ax)

Does this remind you of something? Please don't ask questions that
don't belong to this newsgroup. Figure your math first, figure your
algorithm second, translate it to C++ to the best of your ability
(even if almost none), then come back asking for help.

V

strange how I got an answer then isn't it?

You got your answer? Good, there may be a hope for you after
all... Now, did you also learn a lesson? Any? At all? If
you did, whatever it was, I'm glad I've helped. If you didn't,
well, maybe next time.

V
 
R

Ron Natalie

strange how I got an answer then isn't it?

Yep, and nobody pointed out your program is ill-formed and
if you had a compiler that obeyed the standard would have
issued a diagnostic (main must return int).
 
J

Juha Nieminen

I asked for help on C++ coding.
Sorry Newsgroup commander!

No, you asked for a solution to an mathematical problem. The
programming language in which the solution is implemented is irrelevant
in this case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top