Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Re:Distance to target check

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 altra4u   Members   

122
Like
0Likes
Like

Posted 06 April 2012 - 01:03 PM

Hi
So normally a distance check would be done by simply doing distance < range check. So lets say distance between character a from character b.
However to optimize one would do d^2 < r^2 check.

However if one has to include the radius of each of the characters then the check would be
distance - characterradii < range where characterradii = raidusofa + radiusofb

I'm trying to think of some way where I could keep the squared optimization and also be able to include the radii part.
Thoughts??
I'm discounting this one
(d^2 - r^2)/(d+r)
as that will need the square root value of d
Thanks.

#2 Álvaro   Members   

20937
Like
0Likes
Like

Posted 06 April 2012 - 01:12 PM

distance < range + sum_of_radii

distance^2 < range^2 + 2*range*sum_of_radii + sum_of_radii^2

You should be able to precompute everything on the right-hand side and then the check again becomes distance^2 < constant. So no square root needed.

#3 altra4u   Members   

122
Like
0Likes
Like

Posted 06 April 2012 - 01:27 PM

Good suggestion.
Do you think its worth doing this addition and multiplication operations over doing square root of distance though?
Plus I will either have radius or radius^2. So if I have radius then I will have to square it and if I have radius^2 then I will have to root it. lol.
Or I would have to save both. Probably not a good idea to double data storage.

#4 altra4u   Members   

122
Like
0Likes
Like

Posted 06 April 2012 - 01:36 PM

Basically I have distance^2, range^2 and radius of each character and I want to keep it the most optimized.
Looks like its going to have to be d - r < range check.

#5 Álvaro   Members   

20937
Like
0Likes
Like

Posted 06 April 2012 - 02:15 PM

Multiplications and additions are much cheaper than square roots. Don't bother storing the squares of numbers, because they are easy to compute.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.