## gdalgorithms-list

 RE: [Algorithms] Prism problems... From: Gino van den Bergen - 2005-11-15 20:58:05 Attachments: application/ms-tnef ```When it comes to speed and robustness I would put my money on (1) = construct separating-axes tests for all pairs of simple polytopes = (prisms, OBBs, AABBs, triangles). The problem with this approach is that = if the number of primitive types is large you will spend a lot of time = coding, testing, and debugging. Furthermore, if you need contact = information, then a SAT is not very helpful. (2) I know several Convex = Hull approaches (Cameron's explicit Minkowski sum, Lin-Canny, = Chung-Wang, V-Clip, SWIFT, to name a few). These approaches are usually = far less robust than a SAT en slower for the object complexities that = you are interested in. (3) If you need a single magic solution "that = rules them all", try GJK. You can argue whether GJK is simple, but it = surely is the most powerful approach to collision detection of convex = shapes. So, my 2 cents worth would be: Try (1) if the number of = primitive types is small (fewer than, say, 5), and have low-complexity = (fewer than 5 edge directions and face orientations), otherwise, invest = some time in discovering GJK. Gino van den Bergen http://www.dtecta.com =20 -----Original Message----- From: gdalgorithms-list-admin@... on behalf of Diogo = de Andrade Sent: Tue 11/15/2005 8:55 PM To: gdalgorithms-list@... Cc:=09 Subject: [Algorithms] Prism problems... Hey all. =20 Continuing my ongoing saga on creating a 3rd person action title in an insanely short time, I have a piece of advice to ask you. I'm still trying to automate the building a navigation mesh for the AI's in my game (not using it for player anymore, though). I have limited success with my raycasting approach, if I use lots of samples per triangle (in the order of 500 per tri). Well, with 10000 tris up-facing tris in the whole scene, and with subdivisioning of the "ground" mesh, I have more than 25M rays being cast. Even using some optimizations, this still takes about 10 mins to calculate, and it misses some stuff sometime, which makes the enemies walk through walls and stuff like that. So, I wanted to make this better, and, following the suggestion of Jon Watte, and use a triangular prism per tri, instead of 500 rays. Well, I searched the net all over, my library, and still couldn't find an explanation on the best way to do Prism/OBB, Prism/AABB and Prism/Tri intersection test (I don't need intersection points, or any other of that sort of thing, just an yes or no answer will do). So, I have to roll my own, but before I leap into it (which already sounds like a terrible ordeal), I understand there are several approaches to this problem: =20 1) SAT test. While I understand it in concept, I still have some problem understanding which are the candidate planes, how to extract them and all that. So this one is very hard for me at the moment. 2) Convex Hull approach: treat the prism as a convex hull. Apparently I can find on the net more information on convex hull construction and testing than SAT tests, so although this seems pretty hard by itself, it's also better documented, I think. 3) Some magic/simple solution that I can't think of and someone did. This would be probably the best, but I guess that's just wishful thinking. =20 So, which of the solutions is faster/more robust/easier to implement?=20 Of course, if someone has a Prism/OBB and Prism/Triangle routine somewhere on the hard drive, I would appreciate that even more (call me lazy with a short development time), but considering the lack of info I found on the net, I guess not many people need this kind of algorithm, so it probably nobody has it/wants to give it away. :-) =20 Well, thanks in advance for helping me with another simple problem. =20 Diogo de Andrade Spellcaster Studios diogo.andrade@... ; http://www.spellcasterstudios.com =20 =20 ```
 RE: [Algorithms] Prism problems... From: Gino van den Bergen - 2005-11-22 15:44:06 Attachments: application/ms-tnef ```First of all, do yourself a favor and get rid of the absolute epsilons. = They do not make any sense. If you think that in the end you can fix the = test by tweaking the epsilons you are in deeper throuble than you = imagined. Collinear edges are harmless. In the rare case where the cross product = is a zero vector (Under Visual C++ 7.1 the cross product of the same = vectors does not even yield a zero vector.) all points are projected to = zero and thus a zero vector is not a separating axis. (Make sure you = multiply out all divisions!) In the case where the cross product is very = close to zero, the direction of the cross product is of course very = noisy but this doesn't matter, since the cross product had a very VERY = slim chance of being a (unique) separating axis to start with. The worst = that could happen is that the theoricial cross product was a separating = axis (and the only separating axis), and its noisy computed counterpart = is not. In case the noisy version turns out to be a separating axis then = no harm is done, since albeit not the vector you intended to test, it = still is a valid separating axis. =20 In general, a pure finite-precision SAT may return false positives, but = never false negatives. Using epsilons only makes its behavior worse = (more false positives).=20 Gino van den Bergen http://www.dtecta.com =20 -----Original Message----- From: gdalgorithms-list-admin@... on behalf of Diogo = de Andrade Sent: Tue 11/22/2005 12:50 PM To: gdalgorithms-list@... Cc:=09 Subject: RE: [Algorithms] Prism problems... Yes, that's what I did, sorry, got mixed up... :) I already do a more robust test for=20 if ( t > 0 ) positive++; else if ( t < 0 ) negative++; Replaced it with if (t>-EPSILON_FLOAT) positive++; else if (t Yes, what I'm having are false negatives, basically everything that's > separated by an axis that is not one of the face-normal axis isn't being > detected... removing the " side0*side1 < 0" test gets me an almost ok > collision test, although in that case I get some false positives... Just checking this isn't a typo - my suggestion was to replace the=20 return false on the two earlier tests with continue, you will need to=20 keep the side0*side1 < 0 test. That is, change the algorithm to: for each pair of edges { int side0 =3D WhichSide(C0.V,D,C0.E(i).vertex); if ( side0 =3D=3D 0 ) continue; // not return false int side1 =3D WhichSide(C1.V,D,C0.E(i).vertex); if ( side1 =3D=3D 0 ) continue; // not return false if ( side0*side1 < 0 ) return false; } The first two tests just try for early outs in the case where the axis=20 cannot separate the two polyhedra (though the second test doesn't save=20 much). If you are still having problems, I would suggest it might come down to=20 issues with numerical robustness. The definition of the WhichSide=20 function given in the document is not very robust for points close to=20 the plane being tested; try modifying the line: if ( t > 0 ) positive++; else if ( t < 0 ) negative++; to compare against a tolerance value rather than 0. At least one vertex=20 is going to lie directly on the potential separating plane due to the=20 way the algorithm works, and any numerical error could cause this axis=20 to be dismissed as separating and thereby cause a false positive. HTH James ------------------------------------------------------- This SF.Net email is sponsored by the JBoss Inc. Get Certified Today Register for a JBoss Training Course. Free Certification Exam for All Training Attendees Through End of 2005. For more info visit: http://ads.osdn.com/?ad_id=3D7628&alloc_id=3D16845&op=3Dclick _______________________________________________ GDAlgorithms-list mailing list GDAlgorithms-list@... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=3D6188 ------------------------------------------------------- This SF.Net email is sponsored by the JBoss Inc. Get Certified Today Register for a JBoss Training Course. Free Certification Exam for All Training Attendees Through End of 2005. For more info visit: http://ads.osdn.com/?ad_id=3D7628&alloc_id=3D16845&op=3Dclick _______________________________________________ GDAlgorithms-list mailing list GDAlgorithms-list@... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=3D6188 ```
 RE: [Algorithms] Prism problems... From: Erin Catto - 2005-11-22 17:34:31 ```Certain optimizations of the arithmetic for edge cross products can lead to false negatives. This came up in the Box-Box SAT. The edge-edge tests can be vectorized so that three tests can be combined into one 3-vector computation (good for SIMD). The form of the expression is no longer: separation = dot(axis, ...) I had a case where two boxes always have parallel edges due to constraints. In some cases they would overlap deeply before the SAT failed. Thus, I had a false negative. To get a robust test I compare the separation measure to FLT_EPSILON times the length scale of the boxes. It is conceivable that I will now get false positives. However, in that case the distance is small and I would not generate contact points. Erin -----Original Message----- From: gdalgorithms-list-admin@... [mailto:gdalgorithms-list-admin@...] On Behalf Of Gino van den Bergen Sent: Tuesday, November 22, 2005 7:44 AM To: gdalgorithms-list@... Subject: RE: [Algorithms] Prism problems... First of all, do yourself a favor and get rid of the absolute epsilons. They do not make any sense. If you think that in the end you can fix the test by tweaking the epsilons you are in deeper throuble than you imagined. Collinear edges are harmless. In the rare case where the cross product is a zero vector (Under Visual C++ 7.1 the cross product of the same vectors does not even yield a zero vector.) all points are projected to zero and thus a zero vector is not a separating axis. (Make sure you multiply out all divisions!) In the case where the cross product is very close to zero, the direction of the cross product is of course very noisy but this doesn't matter, since the cross product had a very VERY slim chance of being a (unique) separating axis to start with. The worst that could happen is that the theoricial cross product was a separating axis (and the only separating axis), and its noisy computed counterpart is not. In case the noisy version turns out to be a separating axis then no harm is done, since albeit not the vector you intended to test, it still is a valid separating axis. In general, a pure finite-precision SAT may return false positives, but never false negatives. Using epsilons only makes its behavior worse (more false positives). Gino van den Bergen http://www.dtecta.com ```
 RE: [Algorithms] Prism problems... From: Diogo de Andrade - 2005-11-22 18:31:57 ```I've already removed the epsilon tests, they were causing more problems that they solved (so thanks Gino!)... Now, Erin, what do you mean by separation measure? I'm approaching a suitable (not wholly robust, but for the purpose (navmesh generation) it doesn't matter that much, I have bigger problems on that) test for prism/OBB and prism/tri, and in the process I think I finally understood how SAT tests work... should come in handy someday... :) So I want to thank you all again for the invaluable help and the patience to get me through this! :) Diogo de Andrade Creative & Technical Director Spellcaster Studios diogo.andrade@... http://www.spellcasterstudios.com -----Original Message----- From: gdalgorithms-list-admin@... [mailto:gdalgorithms-list-admin@...] On Behalf Of Erin Catto Sent: Tuesday, November 22, 2005 17:34 To: gdalgorithms-list@... Subject: RE: [Algorithms] Prism problems... Certain optimizations of the arithmetic for edge cross products can lead to false negatives. This came up in the Box-Box SAT. The edge-edge tests can be vectorized so that three tests can be combined into one 3-vector computation (good for SIMD). The form of the expression is no longer: separation = dot(axis, ...) I had a case where two boxes always have parallel edges due to constraints. In some cases they would overlap deeply before the SAT failed. Thus, I had a false negative. To get a robust test I compare the separation measure to FLT_EPSILON times the length scale of the boxes. It is conceivable that I will now get false positives. However, in that case the distance is small and I would not generate contact points. Erin -----Original Message----- From: gdalgorithms-list-admin@... [mailto:gdalgorithms-list-admin@...] On Behalf Of Gino van den Bergen Sent: Tuesday, November 22, 2005 7:44 AM To: gdalgorithms-list@... Subject: RE: [Algorithms] Prism problems... First of all, do yourself a favor and get rid of the absolute epsilons. They do not make any sense. If you think that in the end you can fix the test by tweaking the epsilons you are in deeper throuble than you imagined. Collinear edges are harmless. In the rare case where the cross product is a zero vector (Under Visual C++ 7.1 the cross product of the same vectors does not even yield a zero vector.) all points are projected to zero and thus a zero vector is not a separating axis. (Make sure you multiply out all divisions!) In the case where the cross product is very close to zero, the direction of the cross product is of course very noisy but this doesn't matter, since the cross product had a very VERY slim chance of being a (unique) separating axis to start with. The worst that could happen is that the theoricial cross product was a separating axis (and the only separating axis), and its noisy computed counterpart is not. In case the noisy version turns out to be a separating axis then no harm is done, since albeit not the vector you intended to test, it still is a valid separating axis. In general, a pure finite-precision SAT may return false positives, but never false negatives. Using epsilons only makes its behavior worse (more false positives). Gino van den Bergen http://www.dtecta.com ------------------------------------------------------- This SF.Net email is sponsored by the JBoss Inc. Get Certified Today Register for a JBoss Training Course. Free Certification Exam for All Training Attendees Through End of 2005. For more info visit: http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click _______________________________________________ GDAlgorithms-list mailing list GDAlgorithms-list@... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=6188 ```
 RE: [Algorithms] Prism problems... From: Erin Catto - 2005-11-22 18:53:11 ```From page 83 of Gino's book, the SAT for box-box is: |dot(v, c)| > dot(|v|, hA) + dot(|Bt v|, hB) Where v is the axis, c is the position of box B in box A's frame, B is the rotation matrix of box B relative to box A, hA are the half-widths of box A, and hB are the half-widths of box B. The separation measure is the amount that the left side of the relation is greater than the right side. Namely: separation = |dot(v, c)| - dot(|v|, hA) - dot(|Bt v|, hB) If v is formed from nearly parallel axes, then the separation measure may be a very small positive number, even when the boxes overlap. This is a false negative. Erin -----Original Message----- From: gdalgorithms-list-admin@... [mailto:gdalgorithms-list-admin@...] On Behalf Of Diogo de Andrade Sent: Tuesday, November 22, 2005 10:27 AM To: gdalgorithms-list@... Subject: RE: [Algorithms] Prism problems... I've already removed the epsilon tests, they were causing more problems that they solved (so thanks Gino!)... Now, Erin, what do you mean by separation measure? I'm approaching a suitable (not wholly robust, but for the purpose (navmesh generation) it doesn't matter that much, I have bigger problems on that) test for prism/OBB and prism/tri, and in the process I think I finally understood how SAT tests work... should come in handy someday... :) So I want to thank you all again for the invaluable help and the patience to get me through this! :) Diogo de Andrade Creative & Technical Director Spellcaster Studios diogo.andrade@... http://www.spellcasterstudios.com ```
 RE: [Algorithms] Prism problems... From: - 2005-11-22 19:13:16 ```Gino van den Bergen wrote: > In general, a pure finite-precision SAT may return false positives, > but never false negatives. Using epsilons only makes its behavior > worse (more false positives). Erin Catto already pointed out that this is not correct, but I thought I'd also disagree. In fact, I'd argue the exact opposite: you *need* epsilons to avoid false negatives. For a real-world example of a false negative see section 4.5 of Gottschalk's thesis, available for download here: http://www.cs.unc.edu/~geom/theses/gottschalk/main.pdf Christer Ericson http://realtimecollisiondetection.net/ ```
 RE: [Algorithms] Prism problems... From: Gino van den Bergen - 2005-11-22 22:35:39 Attachments: application/ms-tnef ```I guess Erin and Christer are right about this case. False negatives = seem to occur for SATs, so this was a bad call from my side (*blush*). = The point still stands that you should not use absolute epsilons. = Gottshalk's fix adds an epsilon to the matrix values (before = multiplication) not to the terms of the inequality. =20 Gino van den Bergen http://www.dtecta.com -----Original Message----- From: gdalgorithms-list-admin@... on behalf of = christer_ericson@... Sent: Tue 11/22/2005 8:17 PM To: gdalgorithms-list@... Cc:=09 Subject: RE: [Algorithms] Prism problems... Gino van den Bergen wrote: > In general, a pure finite-precision SAT may return false positives, > but never false negatives. Using epsilons only makes its behavior > worse (more false positives). Erin Catto already pointed out that this is not correct, but I thought I'd also disagree. In fact, I'd argue the exact opposite: you *need* epsilons to avoid false negatives. For a real-world example of a false negative see section 4.5 of Gottschalk's thesis, available for download here: http://www.cs.unc.edu/~geom/theses/gottschalk/main.pdf Christer Ericson http://realtimecollisiondetection.net/ ------------------------------------------------------- This SF.Net email is sponsored by the JBoss Inc. Get Certified Today Register for a JBoss Training Course. Free Certification Exam for All Training Attendees Through End of 2005. For more info visit: http://ads.osdn.com/?ad_id=3D7628&alloc_id=3D16845&op=3Dclick _______________________________________________ GDAlgorithms-list mailing list GDAlgorithms-list@... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=3D6188 ```
 [Algorithms] Linear-Z && w < 0 From: Jim Offerman - 2005-11-23 15:44:33 ```Hi guys, We're using linear-z (as described here: http://www.mvps.org/directx/articles/linear_z/linearz.htm) to render our shadow maps. For reference, this is the shader code that is used to get linear-z: float4 vPos = mul(Input.Pos,worldViewProj); vPos.z = vPos.z * vPos.w; Output.Pos = vPos; (additionally, the projection matrix has been modified so that the far-plane is scaled to 1) It works perfectly in most cases, but we're having some problems with large polygons being clipped away when they really shouldn't be... Using my (admittedly limited) math-brain, I have deduced that the clipping problems arise when one or more of the transformed vertices have both z < 0 and w < 0. In those cases, the sign for z/w (normal 1/z) and z*w/w (linear-z) are different: z/w > 0, whereas z*w/w < 0 In order to correct this, I changed the shader to use "vPos.z = vPos.z * abs(vPos.w)". Now, the signs match up again (z/w > 0 and z*abs(w)/w > 0) and the polygons are no longer clipped away. So far so good, but is this mathematically correct? Any chance of this hackery upsetting the clipper completely (thus accepting *all* polygons)? If anyone of you math wizzards could shed some light on this, that would be greatly appreciated! thx, Jim. -- Jim Offerman Nixxes Software http://www.nixxes.com / http://www.jimofferman.nl ```
 Re: [Algorithms] Prism problems... From: Pierre Terdiman - 2005-11-30 14:57:12 ```We also found real-world examples where not using epsilons produced false negatives. Here is one: http://www.codercorner.com/CorrectBoxBoxOverlap.htm - Pierre ----- Original Message ----- From: "Gino van den Bergen" To: Sent: Tuesday, November 22, 2005 23:35 Subject: RE: [Algorithms] Prism problems... I guess Erin and Christer are right about this case. False negatives seem to occur for SATs, so this was a bad call from my side (*blush*). The point still stands that you should not use absolute epsilons. Gottshalk's fix adds an epsilon to the matrix values (before multiplication) not to the terms of the inequality. Gino van den Bergen http://www.dtecta.com -----Original Message----- From: gdalgorithms-list-admin@... on behalf of christer_ericson@... Sent: Tue 11/22/2005 8:17 PM To: gdalgorithms-list@... Cc: Subject: RE: [Algorithms] Prism problems... Gino van den Bergen wrote: > In general, a pure finite-precision SAT may return false positives, > but never false negatives. Using epsilons only makes its behavior > worse (more false positives). Erin Catto already pointed out that this is not correct, but I thought I'd also disagree. In fact, I'd argue the exact opposite: you *need* epsilons to avoid false negatives. For a real-world example of a false negative see section 4.5 of Gottschalk's thesis, available for download here: http://www.cs.unc.edu/~geom/theses/gottschalk/main.pdf Christer Ericson http://realtimecollisiondetection.net/ ------------------------------------------------------- This SF.Net email is sponsored by the JBoss Inc. Get Certified Today Register for a JBoss Training Course. Free Certification Exam for All Training Attendees Through End of 2005. For more info visit: http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click _______________________________________________ GDAlgorithms-list mailing list GDAlgorithms-list@... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=6188 ```
 RE: [Algorithms] Prism problems... From: Gino van den Bergen - 2005-11-30 15:11:09 ```Thanks Piere! And I have found another reason why not to test the edge-edge cases in an oriented box test when doing culling. (Besides the fact that they make my AABB-tree test slower and can not be used when transformations contain non-uniform scalings.)=20 Gino -----Original Message----- From: gdalgorithms-list-admin@... [mailto:gdalgorithms-list-admin@...] On Behalf Of Pierre Terdiman Sent: Wednesday, November 30, 2005 3:57 PM To: gdalgorithms-list@... Subject: Re: [Algorithms] Prism problems... We also found real-world examples where not using epsilons produced false negatives. Here is one: http://www.codercorner.com/CorrectBoxBoxOverlap.htm - Pierre ----- Original Message -----=20 From: "Gino van den Bergen" To: Sent: Tuesday, November 22, 2005 23:35 Subject: RE: [Algorithms] Prism problems... I guess Erin and Christer are right about this case. False negatives seem to occur for SATs, so this was a bad call from my side (*blush*). The point still stands that you should not use absolute epsilons. Gottshalk's fix adds an epsilon to the matrix values (before multiplication) not to the terms of the inequality. Gino van den Bergen http://www.dtecta.com -----Original Message----- From: gdalgorithms-list-admin@... on behalf of christer_ericson@... Sent: Tue 11/22/2005 8:17 PM To: gdalgorithms-list@... Cc: Subject: RE: [Algorithms] Prism problems... Gino van den Bergen wrote: > In general, a pure finite-precision SAT may return false positives, > but never false negatives. Using epsilons only makes its behavior > worse (more false positives). Erin Catto already pointed out that this is not correct, but I thought I'd also disagree. In fact, I'd argue the exact opposite: you *need* epsilons to avoid false negatives. For a real-world example of a false negative see section 4.5 of Gottschalk's thesis, available for download here: http://www.cs.unc.edu/~geom/theses/gottschalk/main.pdf Christer Ericson http://realtimecollisiondetection.net/ ------------------------------------------------------- This SF.Net email is sponsored by the JBoss Inc. Get Certified Today Register for a JBoss Training Course. Free Certification Exam for All Training Attendees Through End of 2005. For more info visit: http://ads.osdn.com/?ad_id=3D7628&alloc_id=3D16845&op=3Dclick _______________________________________________ GDAlgorithms-list mailing list GDAlgorithms-list@... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=3D6188 ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick _______________________________________________ GDAlgorithms-list mailing list GDAlgorithms-list@... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=3D6188 ```

## Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks