• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
BluePhase

Detecting a radius based on coordinates?

8 posts in this topic

Is it possible to detect a radius from a circle based on the coordinates of the object (X, Y, Z) where it's located on the center? It has to be abstract where I can get the radius from any model from any location. I am using the radius to draw a circle around a model for collision detection. This is being implemented into XNA. Edited by BluePhase
0

Share this post


Link to post
Share on other sites
So you are saying you need the smallest sphere that fully encloses an object from a given point inside the model?

All you need to do for that is loop through all of the points and find the point that has the furthest distance from the center. That distance is the radius of the sphere.
1

Share this post


Link to post
Share on other sites
Simply take the points with the smallest "Pythagorean" distance. If you perform this regularly, a data structure like a KDTree may be of use for some speed ups.
0

Share this post


Link to post
Share on other sites
Also, when finding the point furthest away, compare squared distances (skip the square root) and just do a full distance calculation once for the vertex furthest away.
0

Share this post


Link to post
Share on other sites
Let's restate the problem a little more precisely: Given a set of N points in R^3, find the smallest sphere that contains all of them. Since you don't know what the center might be, the problem is a little trickier than finding the point farthest away.

The basic algorithm that comes to mind takes time O(N^5) to run. The solution sphere will either touch two points (which will be diametrically opposed), or three points (which will be on the same plane as the center of the sphere) or four points. So loop over all the pairs, triplets and quartets of points, find the minimum sphere that contains them and see if all the other points are in there too.

You can probably do better than this by starting with a sphere large enough to hold all the points and shrinking it "appropriately", depending on how many points of contact you currently have. I think this method should take time O(N), but it could be tricky to implement.
0

Share this post


Link to post
Share on other sites
If you're happy with a loose fit, a quick method is to calculate the 3d bounding box that contains all points (by examining the min and max values for X,Y,Z of each of the points of the model), and then calculate the distance d from the centre of that bounding box to one of the corners. The resulting sphere, centred at the bounding box centre with radius d, contains all the points of the model.

A visual example in 2 dimensions:

[attachment=12241:circle-calculation.png]

Note: This technique will almost always generate a non-optimal bounding sphere, which you can see from the diagram, (there is a reasonable margin between the actual points and the calculated circle/sphere). Depending on how you want to use the sphere this may make this technique unsuitable. Though this has the advantage of requiring only 1 distance calculation, which makes it pretty fast.

If you need a tight fit, then something like what Alvaro is alluding to is what you're after.
0

Share this post


Link to post
Share on other sites
[quote name='Álvaro' timestamp='1352762067' post='5000371']You can probably do better than this by starting with a sphere large enough to hold all the points and shrinking it "appropriately", depending on how many points of contact you currently have. I think this method should take time O(N), but it could be tricky to implement.
[/quote]

I don't think that it's possible to do it in O(n) time for dimensions larger than 1 (I think that it's possible to construct a reduction from the diameter problem to the CH problem, but I'm not 100% sure about this). On the other hand an O(n*log(k)) implementation is possible (n is the number of vertices and k is the number of vertices on the convex hull), though it's not that trivial. Edited by max343
0

Share this post


Link to post
Share on other sites
[quote name='max343' timestamp='1352767997' post='5000398']
[quote name='Álvaro' timestamp='1352762067' post='5000371']You can probably do better than this by starting with a sphere large enough to hold all the points and shrinking it "appropriately", depending on how many points of contact you currently have. I think this method should take time O(N), but it could be tricky to implement.
[/quote]

I don't think that it's possible to do it in O(n) time for dimensions larger than 1 (I think that it's possible to construct a reduction from the diameter problem to the CH problem, but I'm not 100% sure about this). On the other hand an O(n*log(k)) implementation is possible (n is the number of vertices and k is the number of vertices on the convex hull), though it's not that trivial.
[/quote]

Yes, you are right. The method I was thinking of is not O(n), but something like O(n*log(n)) or O(n*log(k)). I have to think the details through before I can be sure.
0

Share this post


Link to post
Share on other sites
It seems I was wrong. This problem can be solved in linear expected time.
This simple (general position) algorithm should do the trick:

[code]
FindMinSphere(S, origSphereVerts)
1. sphereVerts = origSphereVerts, remainingVerts = empty
2. for each i[k] in random pi(1,2,...,length(S))
2.1 if S[i[k]] is not contained in the sphere spanned by sphereVerts
2.1.1 sphereVerts = FindMinSphere(remainingVerts, EliminateExtraVertex(origSphereVerts + S[i[k]]))
2.2 remainingVerts += S[i[k]]
3. return sphereVerts

EliminateExtraVertex(S)
1. X=S
2. if length(S)==5
2.1 X = from the 5 possible spheres in X choose the one that contains all five points
3. return X
[/code] Edited by max343
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0