# Cylinder contact detection

**URL:** <https://discourse.julialang.org/t/cylinder-contact-detection/85145>\
**Category:** General Usage\
**Created:** [August 2, 2022, 6:39am UTC](https://discourse.julialang.org/t/cylinder-contact-detection/85145 "2022-08-02T06:39:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![frogdog](https://avatars.discourse-cdn.com/v4/letter/f/13edae/32.png) [@frogdog](https://discourse.julialang.org/u/frogdog)\
**Post date:** [August 2, 2022, 6:39am UTC](https://discourse.julialang.org/t/cylinder-contact-detection/85145/1 "2022-08-02T06:39:10Z")

</div>

Is there a package that deals with contact search/contact detection?  
I want to check for collision between two 3D cylinders, and there are a bunch of edge cases that are a bit tricky to code, so I was hoping there exist a package already.

Modia3D seems to have contact detection… anyone know if it has an API so I can simply call `is_contact(cyl1, cyl2)`?

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [August 2, 2022, 7:03am UTC](https://discourse.julialang.org/t/cylinder-contact-detection/85145/2 "2022-08-02T07:03:23Z")

</div>

This [Intersection · Meshes.jl](https://juliageometry.github.io/Meshes.jl/stable/algorithms/intersection.html) looks promissing, but not for cylinders…

Or this [GitHub - janvorisek/SolidModeling.jl: Perform boolean operations on solids in Julia - union, intersection and subtraction](https://github.com/janvorisek/SolidModeling.jl)

---

<div class="post-metadata">

**Author:** ![frogdog](https://avatars.discourse-cdn.com/v4/letter/f/13edae/32.png) [@frogdog](https://discourse.julialang.org/u/frogdog)\
**Post date:** [August 2, 2022, 9:37am UTC](https://discourse.julialang.org/t/cylinder-contact-detection/85145/3 "2022-08-02T09:37:33Z")

</div>

Meshes.jl seems promising indeed. It seems like they have an [generic 3d collision detection alg](https://github.com/JuliaGeometry/Meshes.jl/blob/656ad5f248f5e228c0f417951a251fc2fcaedd28/src/intersections.jl#L153), but it does not work for Cyliders…

```julia
using Meshes
c1 = Cylinder(1.0, Segment((0., 0., 0.), (1.,1.,1.)))
c2 = Cylinder(0.5, Segment((0.1, 0.1, 0.1), (1.,1.,1.)))
I = hasintersect(c1, c2)

```

```julia
ERROR: LoadError: MethodError: no method matching center(::Cylinder{Float64})
Closest candidates are:
  center(::Point) at ~/.julia/packages/Meshes/C9CHD/src/points.jl:152
  center(::Box) at ~/.julia/packages/Meshes/C9CHD/src/primitives/box.jl:34
  center(::Ball) at ~/.julia/packages/Meshes/C9CHD/src/primitives/ball.jl:23
  ...
Stacktrace:
 [1] centroid(g::Cylinder{Float64})
   @ Meshes ~/.julia/packages/Meshes/C9CHD/src/geometries.jl:41
 [2] hasintersect(g1::Cylinder{Float64}, g2::Cylinder{Float64})
   @ Meshes ~/.julia/packages/Meshes/C9CHD/src/intersections.jl:164

```

I think I will try to use a simplified polygon/hexahedron mesh instead of cylinders ( I dont need the collision to be super accurate). Still open for suggestion on other packages/algorithms however.
