Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cartesian equation

Status
Not open for further replies.

Taxidriver

Programmer
Jan 15, 2002
79
IT
Hello,
I would like to write a function that, given two points, returns the cartesian equation of the line passing through the two points. In other words, the function should return something like y = ax + b that will be calculated using the formula (x-x1)(y2-y1) = (y-y1)(x2-x1).
How should "y" be defined?
Thank you.
 
as double...
And x as well...
There is no predefined type for a function, if you are looking for something like that.

You may try to define your own struct type, like:
Code:
struct Cartesian_Func {
  double a;
  double b;
};

typedef struct Cartesian_Func TCartesianFunc

Then, after you calculated a and b, write a function that returns the value for a specific point.

Code:
double getYVal(TCartesianFunc* func, double xPoint) 
{
  return (func.a*xPoint + func.b)
}

However is an bit elaborate way to do it; you can simply declare the 2 doubles separately and work with them like that... But this way you get to be better organized and you can extend the structure and the functions to perform more elaborate tasks.

HTH... [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
So, you mean that I have to calculate a and b with the function and then define a string and write y=ax+b ? I suppose that I cannot use that string afterwards for any purpose...I don't need the value of the function in one point, I need the equation of the function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top