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.

Printable View

- 01-14-2008invinciblevnPithagore-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. - 01-14-2008vart
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 - 01-14-2008iMalc
Post the function in your current code that uses it and we'll show you an optimised version.

- 01-14-2008invinciblevn
just now I use this function:

c=(int) sqrt(a*a+b*b); - 01-14-2008vart
- 01-14-2008invinciblevn
- 01-14-2008matsp
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 - 01-14-2008Dino
Pythagorean. Pythagoras invented it.

- 01-14-2008iMalc
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. - 01-15-2008invinciblevn
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. - 01-15-2008Adak
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. - 01-15-2008matsp
Most games use the trick I explained, by not using sqrt unless absolutely necessary.

For image rotation, you could use the trick of Bresenham's circle algorithm: http://www.ecse.rpi.edu/Homepages/wr...bresenham.html

--

Mats