1. ## Pithagore-fast computation

Dear all.
I'm doing the computation rectangle's edge using Pithagore theory.
All 3 rectangle's edge are integer.
Is there any algorithm for fast computation that don't use sqrt() function?
Thanks.

2. c is less than a+b but greater than max(a,b)
you can use some search algorithm in this range with test condition c*c == a*a +b*b
to find c
not guaranteed to be faster, but it uses only integer math

3. Post the function in your current code that uses it and we'll show you an optimised version.

4. just now I use this function:
c=(int) sqrt(a*a+b*b);

5. Originally Posted by invinciblevn
just now I use this function:
c=(int) sqrt(a*a+b*b);
that can be 1 less than the actual value

6. Originally Posted by vart
that can be 1 less than the actual value
I'm doing compute distant in an image which use pixel as unit.
sqrt() require a lot resource.

7. So don't calculate the sqrt, just use the c * c value - for all intents and purposes, it's the same thing, just bigger.

--
Mats

8. Pythagorean. Pythagoras invented it.

9. Originally Posted by invinciblevn
just now I use this function:
c=(int) sqrt(a*a+b*b);
That's not what I meant. I meant, post the whole function that includes this line of code. Assuming of course that it isn't longer than a couple dozen lines...

It's extremely difficult to optimise 1 line of code, but if we can see the lines of code around it then it becomes quite easy.

10. Originally Posted by iMalc
That's not what I meant. I meant, post the whole function that includes this line of code. Assuming of course that it isn't longer than a couple dozen lines...

It's extremely difficult to optimise 1 line of code, but if we can see the lines of code around it then it becomes quite easy.
Thank you very much, iMalc.
I'm doing the image rotation. I use this for point distance computation.
This computation is used many times in my program, so that is require a lot resource.
I wonder whether there is any other way of point distant computation that does not use pythagore?
That is my problem.
Thanks.

11. Your problem must be a common one in gaming forums. (as opposed to general purpose programming forums like this). I'd check the gaming forum, and also game.dev for more detailed answers.

You can find the hypotenuse of a triangle by using it's two sides and the angle between them, but I have no idea if that is any faster, at all. The game programmers will know what's quick.