Possible Duplicate:
Fast algorithm for polar -> cartesian conversion
I am running some pathfinding code (which is a bit slow) through jvisualvm, what I found was that 80% time is being spent in my vector implementation more specifically the part that convert cartesian to polar,
r = Math.sqrt((x * x) + (y * y));
t = Math.atan2(y,x);
are there any old school tricks that would get me some more performance?
In my experience in path finding algorithms, the problem is not those lines.
The main questions is "How many times you call these two lines?"
You should investigate your path finding algorithm.
Anyway, if you want reduce the delay of those lines, it is possible to make a pre-calculated table for sqrt
and atan2
for each x
and y
. Or even a table that maps each (x, y) to (r, t) directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With