what is the equation of the straight line lying between two points with coordinates (x1,y1) and (x2,y2). I got the point of finding the slope, and when (x2-x1!)=0. How you avoid the fact of fabs(y2-y1) much smaller than fabs(x2-x1).
The equation of a straight line is
y = m.x + c
Where m is the gradient and c is a constant.
If you have 2 points (x1, y1) (x2, y2) then you can use simulatneous equations to work out m and c (which I think you have already done) because
1) y1 = m.x1 + c
2) y2 = m.x2 + c
so
1 - 2) y1 - y2 = m.x1 + c - (m.x2 - c)
equivilent to y1 - y2 = m(x1 -x2c)
therefore m = (y1 - y2)/(x1 - x2)
Once you have m c is easily calculatable from either 1 or 2
c = y1 - m.x1
If x1 - x2 was 0 you'd have a divide by zero error, however if x1 - x2 == 0 then y1 - y2 == 0 and you actually only have 1 point.
(Sorry I've had to type all this out to get to the point of your question so I could actually understand what you were asking)
You have clearly got to this point and found that in the case that (y1 - y2) is very much smaller than (x1 - x2) you get a 0 result for m when you were expecting a very very very small value. Apart from making sure thatyou are using doubles not floats so that you don't hit this point so soon there is not much you can do, at some point the value of m will get to the point where it is too small to be represented in a double.
There is not much you can do about it mathematically (i.e. using arithmatic), there may be a way of doing something by cheating.
if (y1 - y2)/(x1 - x2) is a very small number that can not be represented in a double then try
1000000.0*(y1 - y2)/(x1 - x2)
What you will get is a value 1000000 times the value of m call it m6 and
c = (1000000.0.y1 - m6.x1)/1000000.0
if c is too small to represent then leave out the last /1000000.0
The smallest positive value that a double(64 bit) can represent is 2.2250738585072014e-308
suppose your m6 = 2.2250738585072014e-306
But this is actually 1000000 times the actual result value. How do you output the value? (And here is the cheat
First convert your double to a string (using sprintf)
"2.2250738585072014e-306"
now find the e using strstr or strchr
Then starting at the character after the e ('-') use strtol to convert the exponent to an integer e = -306. Then terminate the string after the e
"2.2250738585072014e"
now we know that the value is 1000000 times to big which means that the exponent (which is a power of 10) is +6 to large so take 6 off it -306 - 6 = -312.
convert that to a string and add it to the end of the original string giving the string
"2.2250738585072014e-312"
And there is your result string, a value too small to hold in a double.
I have to say that I am quite pleased with this given that I was going to answer that there is no solution to your problem, of course you may not consider that this is a practical solution but hey ho.