• 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
Koder4Fun

How to find minimum distance between two polygons in 3D space

7 posts in this topic

After some hours of search and some implementations that doesn't work I hope on help of people that know more about this topic.

I need this on a iterative radiosity renderer, using gathering method, writed in C# using GPU (with XNA), to speed up the rendering.

For each polygon I have a lightmap [b]and a list of lightmaps visible from it[/b]. That's work ok.
The idea is that when[b] all lightmaps in "visible list" [/b]have an average energy less than a thresold I can skip the light gathering for the entire polygon's lightmap.

In a first time I've considered only the average energy, but I find that accounting for distance (or better the square of the distance, that is the physical decay of light) i can rescale the average energy and check against the threshold to do a better filtering:
[code]
public void GatherEnergy(float accuracy, ref Hemicube h, ref SceneRenderer scene)
{
bool skip = true;
for (int i = 0; i < VisibleLightMaps.Length; ++i)
{
if ((VisibleLightMaps[i].lightmap.AverageEnergy / VisibleLightMaps[i].distSquared) > energyThreshold)
{
skip = false;
break;
}
}
if (skip)
return;
if (ForDetailMesh)
GatherEnergyForDetailMesh(accuracy, ref h, ref scene);
else
GatherEnergyForPoly(accuracy, ref h, ref scene);

CalculateMaxAndAverageEnergy();
}
[/code]

NOTE: the distance I need is the [b]real minimun distance[/b] (or distance squared) between the polygons. The points that define the distance segment can be on a vertex, on edge, or inside the polygon.

I hope to be clear.
Thanks in advance for help.
0

Share this post


Link to post
Share on other sites
I have to ask, are you sure you need the exact minimum distance? This could turn out to be zero if they intersect, which would cause problems for the division and comparison. This would happen frequently at the corners of rooms for example. Another question is what kind of polygons we're talking about. Triangles may have shortcuts not applicable to polygons made from arbitrary vertices, which may not even be co-planar due to rounding errors or malformation. And finally, for performance is it more important to have an exact answer or just a heuristic which always errs on a known side? This code will be run quite frequently, so you wouldn't want it to be slow. For arbitrary polygons an estimate based on an axis-aligned bounding box or a centroid-to-plane test would likely be much faster than an exact test.
0

Share this post


Link to post
Share on other sites
I'm sorry, it's true....

The [b]polygons are convex and planar and the vertices are ordered counter-clockwise[/b].

I already have an algo to check if two convex polys intersects so I can filter it out and return zero distance, otherwise I will use the algorithm I search for.

The distance must be [b]correct or at least underestimated[/b]. If the distance returned if bigger than real the contribution of lightmap is skipped making illuminations artifacts (darker regions).

I not search for speed, I precalculate these distances only once during radiosity setup.

[quote]I have another question now, a radiosity solution based on hemicubes is automatically unit-less?
I've thinked that the inverse square law is due to the area that a polygon fill onto the hemicube faces, so the perspective automatically reduce this.... and so the units of the scene are not important.
But now, misuring the distance directly from polys, i think i need to convert units it to meters to work well?[/quote]
I've partially solved, the assertions made on the box above are wrong i need to check for solid angle and thus accounting for the square of distance between hemicube origin and patch center.
I have also set an UnitsToMeters float to define the scene scale. Now it's all more correct.

The distance algorithm [b]is always needed[/b]... Edited by Koder4Fun
0

Share this post


Link to post
Share on other sites
I second jefferytitan. You should (if I understand the algorithm correctly) be able to get away with an approximation.

But if you *really* need the _exact_ distance between two polygons you should look into Minkowski Differences.
0

Share this post


Link to post
Share on other sites
If speed's not a huge concern, perhaps the below would work:
[url="http://cgm.cs.mcgill.ca/~orm/mind2p.html"]http://cgm.cs.mcgill.ca/~orm/mind2p.html[/url]
[url="http://en.wikipedia.org/wiki/Rotating_calipers"]http://en.wikipedia.org/wiki/Rotating_calipers[/url]

Personally I'd just go the AABB way for simplicity and speed, and then optimise if it's needed. Assuming you don't use single huge polygons, the chances of AABBs overlapping for arbitrary polygons should be pretty low.
1

Share this post


Link to post
Share on other sites
As an estimation (max bound), you can compute the minimum of all nine distances between the vertices of the triangles. Then, filtered by a threshold, you can choose candidates and compute the real distance between each vertex of one triangle and the plane that represents the other triangle.
1

Share this post


Link to post
Share on other sites
Would not the best way be to use standard quadratic programming tools for the job?
I mean there should be some fast algorithms to solve the problem,
0

Share this post


Link to post
Share on other sites
Thanks to all guys!
You've got me some differents solutions to the problem, now I test what fit better for me.

[quote name='pacobarter' timestamp='1345415093' post='4971244']
As an estimation (max bound), you can compute the minimum of all nine distances between the vertices of the triangles. Then, filtered by a threshold, you can choose candidates and compute the real distance between each vertex of one triangle and the plane that represents the other triangle.
[/quote]
I do this (I work with polys not triangles, but basically is the same).
Also I check for distance from center to center of the two polygons.
The only distance that I need to check is when the minimum distance is made by a segment with endpoints inside the polygons.

[quote name='jefferytitan' timestamp='1345406263' post='4971194']
If speed's not a huge concern, perhaps the below would work:
[url="http://cgm.cs.mcgill.ca/~orm/mind2p.html"]http://cgm.cs.mcgill...orm/mind2p.html[/url]
[url="http://en.wikipedia.org/wiki/Rotating_calipers"]http://en.wikipedia....tating_calipers[/url]

Personally I'd just go the AABB way for simplicity and speed, and then optimise if it's needed. Assuming you don't use single huge polygons, the chances of AABBs overlapping for arbitrary polygons should be pretty low.
[/quote]
I've already seen this approach but is for 2D.
If I'm correct, when I translate to 3D, support lines become planes parallels to polygon's normal...

Thanks again.
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