computing distance
play

Computing Distance Erin Catto Blizzard Entertainment Convex - PowerPoint PPT Presentation

Computing Distance Erin Catto Blizzard Entertainment Convex polygons Closest points Overlap Goal Compute the distance between convex polygons Keep in mind 2D Code not optimized Approach simple complex Geometry If all else


  1. Computing Distance Erin Catto Blizzard Entertainment

  2. Convex polygons

  3. Closest points

  4. Overlap

  5. Goal  Compute the distance between convex polygons

  6. Keep in mind  2D  Code not optimized

  7. Approach simple complex

  8. Geometry

  9. If all else fails …

  10. DEMO!

  11. Outline 1. Point to line segment 2. Point to triangle 3. Point to convex polygon 4. Convex polygon to convex polygon

  12. Concepts 1. Voronoi regions 2. Barycentric coordinates 3. GJK distance algorithm 4. Minkowski difference

  13. Section 1 Point to Line Segment

  14. A line segment A B

  15. Query point Q A B

  16. Closest point Q P A B

  17. Projection: region A Q A B

  18. Projection: region AB Q A B

  19. Projection: region B Q A B

  20. Voronoi regions region A region AB region B A B

  21. Barycentric coordinates A G B G(u,v)=uA+vB u+v=1

  22. Fractional lengths v=0.5 u=0.5 A G B G(u,v)=uA+vB u+v=1

  23. Fractional lengths v=0.25 u=0.75 A G B G(u,v)=uA+vB u+v=1

  24. Fractional lengths u=1.25 v=-0.25 G A B G(u,v)=uA+vB u+v=1

  25. Unit vector A B n B-A n = B-A

  26. (u,v) from G A G B v u       G-A n B-G n v= u= B-A B-A

  27. (u,v) from Q Q A G B v u       Q-A n B-Q n v= u= B-A B-A

  28. Voronoi region from (u,v) v > 0 u > 0 A G B u > 0 and v > 0 region AB

  29. Voronoi region from (u,v) u > 0 v < 0 G A B v <= 0 region A

  30. Voronoi region from (u,v) u < 0 v > 0 A B G u <= 0 region B

  31. Closet point algorithm input: A, B, Q compute u and v if (u <= 0) P = B else if (v <= 0) P = A else P = u*A + v*B

  32. Aside: center of mass A COM B mass A = mass B

  33. Aside: center of mass A COM B mass A > mass B

  34. Aside: center of mass A COM B mass A < mass B

  35. Aside: center of mass massA massB   COM A B   massA massB massA massB massA>0 massB>0

  36. Section 2 Point to Triangle

  37. Triangle B A C

  38. Closest feature: vertex Q P=B A C

  39. Closest feature: edge B A P Q C

  40. Closest feature: interior B A P=Q C

  41. Voronoi regions B Region B Region AB A Region A Region ABC Region BC Region CA C Region C

  42. 3 line segments Q   u ,v AB AB B A   C u ,v BC BC   u ,v CA CA

  43. Vertex regions  u 0 AB B  v 0 BC  A u 0 CA  v 0 AB C  u 0 Using line segment uv’s BC  v 0 CA

  44. Edge regions  u 0 AB  v 0 B AB ? A C Line segment uv’s are not sufficient

  45. Interior region B A ? C Line segment uv’s don’t help at all

  46. Triangle barycentric coordinates B A Q    Q uA vB wC C    u v w 1

  47. Linear algebra solution       A B C u Q x x x x       A B C v = Q       y y y y        1 1 1    w  1 

  48. Fractional areas B A Q C

  49. The barycenctric coordinates are the fractional areas B  w Area(ABQ) A w Q u v  u Area(BCQ)  v Area(CAQ) C C

  50. Barycentric coordinates B  w 0 A Q  u 1  v 0 C

  51. Barycentric coordinates area(QBC)  u area(ABC) area(QCA)  v area(ABC) area(QAB)  w area(ABC)

  52. Barycentric coordinates are fractional line segment : fractional length triangles : fractional area tetrahedrons : fractional volume

  53. Computing Area C B A 1   signed area= cross B-A,C-A 2

  54. Q outside the triangle B A Q C C

  55. P outside the triangle B A w  0 Q v  0 v+w>1 C C

  56. P outside the triangle B A Q u  0 C C

  57. Voronoi versus Barycentric  Voronoi regions != barycentric coordinate regions  The barycentric regions are still useful

  58. Barycentric regions of a triangle B A C

  59. Interior B A Q    u 0, v 0, w 0 C

  60. Negative u B A Q u  0 C

  61. Negative v B A Q v  0 C

  62. Negative w Q B w  0 A C

  63. The uv regions are not exclusive B A P C Q

  64. Finding the Voronoi region  Use the barycentric coordinates to identify the Voronoi region  Coordinates for the 3 line segments and the triangle  Regions must be considered in the correct order

  65. First: vertex regions  u 0 AB B  v 0 BC  A v 0 AB  u 0 CA C  u 0 BC  v 0 CA

  66. Second: edge regions  u 0 AB  v 0 B AB ? A C

  67. Second: edge regions solved  u 0 AB  v 0 B AB  w 0 ABC A C

  68. Third: interior region B A u > 0 ABC v > 0 ABC w > 0 ABC C

  69. Closest point  Find the Voronoi region for point Q  Use the barycentric coordinates to compute the closest point Q

  70. Example 1 Q B A C

  71. Example 1 Q B A C uAB <= 0

  72. Example 1 Q B A C uAB <= 0 and vBC <= 0

  73. Example 1 Q P=B A Conclusion: C P = B

  74. Example 2 Q B A C

  75. Example 2 Q B A C Q is not in any vertex region

  76. Example 2 Q B A C uAB > 0

  77. Example 2 Q B A C uAB > 0 and vAB > 0

  78. Example 2 Q B A C uAB > 0 and vAB > 0 and wABC <= 0

  79. Example 2 Q B A P C Conclusion: P = uAB*A + vAB*B

  80. Implementation input: A, B, C, Q compute uAB, vAB, uBC, vBC, uCA, vCA compute uABC, vABC, wABC // Test vertex regions … // Test edge regions … // Else interior region …

  81. Testing the vertex regions // Region A if (vAB <= 0 && uCA <= 0) P = A return // Similar tests for Region B and C

  82. Testing the edge regions // Region AB if (uAB > 0 && vAB > 0 && wABC <= 0) P = uAB * A + vAB * B return // Similar for Regions BC and CA

  83. Testing the interior region // Region ABC assert(uABC > 0 && vABC > 0 && wABC > 0) P = Q return

  84. Section 3 Point to Convex Polygon

  85. Convex polygon B C A D E

  86. Polygon structure struct Polygon { Vec2* points; int count; };

  87. Convex polygon: closest point B Query point Q C A Q D E

  88. Convex polygon: closest point B Closest point Q C A Q P D E

  89. How do we compute P?

  90. What do we know? Closest point to point Closest point to line segment Closest point to triangle

  91. Simplex 0-simplex 1-simplex 2-simplex

  92. Idea: inscribe a simplex B C A Q D E

  93. Idea: closest point on simplex B P = C A Q D E

  94. Idea: evolve the simplex B C A Q D E

  95. Simplex vertex struct SimplexVertex { Vec2 point; int index; float u; };

  96. Simplex struct Simplex { SimplexVertex vertexA; SimplexVertex vertexB; SimplexVertex vertexC; int count; };

  97. We are onto a winner!

  98. The GJK distance algorithm  Computes the closest point on a convex polygon  Invented by Gilbert, Johnson, and Keerthi

  99. The GJK distance algorithm  Inscribed simplexes  Simplex evolution

  100. Starting simplex B Start with arbitrary vertex. Pick E. C This is our starting A simplex. Q D E

Recommend


More recommend