04-26-2015, 12:41 AM
(This post was last modified: 04-26-2015, 12:47 AM by LogicParrot.)
(04-26-2015, 12:06 AM)SphinxC0re Wrote: You could get rid of the sqrt function by using the octile search function.
here is an example: https://github.com/qiao/PathFinding.js/b...js#L33-L36
a friend of mine coded this. the SQRT-1 is a constant
Swapping euclidean distance with some other distance function will enhance performance at the cost of accuracy, there's also Manhatten distance which I think is even lighter. That's a possiblity, but I've been thinking about preserving euclidean distance AND enhancing performance, here's my thought:
I don't care about the F values, I only care about comparing F's, so I only care about their relative values.
Now, I thought of manipulating the math to get rid of sqrts, something along the lines of:
F=G+sqrt(stuff)
F^2=(G+sqrt(stuff))^2
F^2=g^2+2*g*stuff+stuff^2
F^2=g^2+stuff*(2*g+stuff)
Then I could store F^2 instead of F.
I need to check if there are some caveats here, and if this is actually faster, and if there's a cleverer math trick.