Sep 27, 2010 at 7:39pm UTC
i need to Compute the length of the line using the distance equation given below: √(x1-x2)2 + (y1-y2)2
Sep 27, 2010 at 7:54pm UTC
ok i read everything but it does not compile i do not know why look
line = sqrt(((x1-x2)^2 + (y1-y1)^2)));
Sep 27, 2010 at 7:56pm UTC
You can't use ^ like that in C++. Try using plain old multiplication.
-Albatross
Sep 27, 2010 at 8:04pm UTC
i did this
line = sqrt((pow(x1,2)-pow(x2, 2)) + (pow(y1, 2) - pow(y1,2))); but in the graphic windows it shows this whenever i try to display it with the gout
-1.#IND00 algo asi porq
Sep 27, 2010 at 8:06pm UTC
Whoa whoa whoa.
(a-b)^n is NOT the same as (a^n) - (b^n). You should know that, surely.
Again, though. I recommend plain old multiplication. :)
As for your error, that I can't solve as I am not on Windows and have lost my familiarity with that platform's API. Sorry.
-Albatross
Last edited on Sep 27, 2010 at 8:07pm UTC
Sep 27, 2010 at 8:15pm UTC
I suppose that (pow(x1,2)-pow(x2, 2)) + (pow(y1, 2) - pow(y1,2)) happened to be a negative number.
Don't use pow for squaring. (x1-x2)*(x1-x2) would do..
Sep 27, 2010 at 8:16pm UTC
The formula is completely wrong for the reason Albatross has pointed out. Under certain conditions, you'll end up trying to compute the square root of a negative number.