# ConvexBodyProximityQueries False Collision Detection and Proximity

**URL:** <https://discourse.julialang.org/t/convexbodyproximityqueries-false-collision-detection-and-proximity/88249>\
**Category:** General Usage\
**Tags:** package, mesh\
**Created:** [October 4, 2022, 7:03pm UTC](https://discourse.julialang.org/t/convexbodyproximityqueries-false-collision-detection-and-proximity/88249 "2022-10-04T19:03:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![karelispanagiotis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karelispanagiotis/32/42748_2.png) [@karelispanagiotis](https://discourse.julialang.org/u/karelispanagiotis)\
**Post date:** [October 4, 2022, 7:03pm UTC](https://discourse.julialang.org/t/convexbodyproximityqueries-false-collision-detection-and-proximity/88249/1 "2022-10-04T19:03:31Z")

</div>

I have been using the package ConvexBodyProximityQueries and I cannot find the reason why it fails to calculate the distance between the following 3D Triangles.  
If I reverse the arguments order, I get the correct answer.

```julia
using Meshes
using StaticArrays
using ConvexBodyProximityQueries

t1 = Triangle(Point(-0.37579435f0, 0.014414025f0, 0.3265663f0),
              Point(-0.37263185f0, 0.0108978925f0, 0.36118037f0),
              Point(-0.35647663f0, 0.03625821f0, 0.34328437f0));

t2 = Triangle(Point(0.23884095f0, -1.6477574f0, 0.116889484f0),
              Point(0.26891768f0, -1.6353351f0, 0.10821109f0),
              Point(0.26338503f0, -1.6657706f0, 0.10510237f0));
p = StaticArrays.sacollect(SMatrix{3, 3}, x for v in t1.vertices for x in v.coords);
q = StaticArrays.sacollect(SMatrix{3, 3}, x for v in t2.vertices for x in v.coords);

dir = centroid(t2) - centroid(t1);
dist1 = minimum_distance(p, q, dir)
dist2 = minimum_distance(q, p, dir)

```

Output:

```julia
julia> dist1
0.0f0

julia> dist2
1.7844534f0

```

---

<div class="post-metadata">

**Author:** ![pitsianis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pitsianis/32/26588_2.png) [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Post date:** [October 7, 2022, 7:26pm UTC](https://discourse.julialang.org/t/convexbodyproximityqueries-false-collision-detection-and-proximity/88249/2 "2022-10-07T19:26:04Z")

</div>

> [@karelispanagiotis](#):
>
> `ConvexBodyProximityQueries`

I am not familiar with this specific software package. Since nobody else provided any comments so far, I will try to provide my “wisdom” 😉

This works with identical coordinates.

```julia
using StaticArrays
using ConvexBodyProximityQueries

p = SMatrix{3,3}(reshape([-0.37579435f0, 0.014414025f0, 0.3265663f0,
                          -0.37263185f0, 0.0108978925f0, 0.36118037f0,
                          -0.35647663f0, 0.03625821f0, 0.34328437f0], 3,3))

q = SMatrix{3,3}(reshape([0.23884095f0, -1.6477574f0, 0.116889484f0,
                           0.26891768f0, -1.6353351f0, 0.10821109f0,
                           0.26338503f0, -1.6657706f0, 0.10510237f0], 3,3))

dir = @SVector(rand(Float32,3)) .- 0.5f0

dist1 = minimum_distance(p, q, dir)
dist2 = minimum_distance(q, p, dir)

dist1 ≈ dist2

```

---

<div class="post-metadata">

**Author:** ![karelispanagiotis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karelispanagiotis/32/42748_2.png) [@karelispanagiotis](https://discourse.julialang.org/u/karelispanagiotis)\
**Post date:** [October 9, 2022, 12:36pm UTC](https://discourse.julialang.org/t/convexbodyproximityqueries-false-collision-detection-and-proximity/88249/3 "2022-10-09T12:36:20Z")

</div>

Thank you for the reply professor,

This does not solve my issue.  
I am calling this routine to calculate distances for hundreds or thousand of times.  
If any of these routine calls fails, then the whole result is wrong.

Unfortunately, this is not rare to happen, I can reproduce it almost always.  
I thought that , theoretically, the GJK algorithm always converges regardless of the choice on the initial direction.
