ID:167991
Dec 28 2005, 8:41 am
|
|
How would I determin how many spaces away is point a to point b?
|
In response to Unknown Person
|
|
Using the ** operator here is a bad idea, as many times distance is something you want to calculate quickly for a loop. It's far better to simply use (B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y) instead.
Also important is that if you're merely comparing distances, you do not need to use sqrt(). Your game will be faster without it. Any comparison that's valid for distances will be just as valid for squared distances. Lummox JR |
In response to Lummox JR
|
|
Of course, it might not always be comparing distances so much as it is comparing a distance to a value. Just to point out that the sqrt() should be there, if the occasion calls for it. =D
Hiead |
In response to Hiead
|
|
Of course, it might not always be comparing distances so much as it is comparing a distance to a value. Still faster to compare a squred distance to value * value :P. The only time you need to do the sqrt is when you need to get the ratio of two distances in which case having them squared gives you largely different results. |
In response to Theodis
|
|
Theodis wrote:
Of course, it might not always be comparing distances so much as it is comparing a distance to a value. Indeed. Or the difference between distances, or sum of several distances, may be something you need to calculate, and that too will give you different results if you don't take the square root. It should also be noted that wherever possible, at least when this is occurring within a loop, you should inline your distance calculations instead of using a proc. I know that may not sound intuitive, but basically if you're in a tight loop and efficiency becomes a major concern (for instance, several AI procs running at once, each comparing several distances), the overhead of calling a proc starts to matter. Lummox JR |
The get_dist proc is pretty much the larger of the absolute value of delta x and delta y.
~~> Unknown Person