Archive for April, 2008

Recently I needed to calculate the distance between two points. Not too difficult by itself, all you need is the square root of the X/Y distances:

sqrt( (x1 - x2) * (x1-x2) + (y1 - y2) * (y1 - y2) )

Thing is: CLDC 1.0 does not have a sqrt function, only CLDC 1.1 has… Plus, double and float are also both CLDC 1.1 – which is OK, since I only needed an integer value.

Wikipedia proved to be a good source of information, once more, so I found that I could implement the Newton Method to achieve the desired result. Since I had no luck finding appropriate code with Google that I could employ, I wrote the function myself. See code below.

Read the rest of this entry »

Creative Commons License - © 2007 Codecat - powered by WordPress