How to detect intersection between a circle/sphere and a triangle?

Hello,

I want to make collision detection between a circle/sphere and a triangle? I know that .intersectsSphere() and .intersectsTriangle() exists. Now I use .intersectsBox() but that obviously does not work well, as you can see in the left part of fig1. I only want detection if they really collide each other, like in the right part of fig1

I made the circle with THREE.CircleGeometry() and the triangle with a custom THREE .Vector3() geometry. It is no problem for me to make the circle and triangle different. For example with a sphere and/or THREE.Triangle().

This is what I want to achieve, but preferably with three.js functions:
http://www.jeffreythompson.org/collision-detection/tri-point.php

Thanks in advance!

The linked code implements a 2D triangle/point containments test. Notice that a point has no extension in 3D space. An instance of CircleGeometry however does.

So you can’t use the linked code even as a reference. It’s a totally different thing.

Besides, THREE.CircleGeometry is intended for rendering, not for intersection tests. You want to use math classes like THREE.Triangle, THREE.Sphere or THREE.Plane which are intended for collision detection logic.

Question: Are you working with 2D or 3D data? If it’s the former one, you maybe can give this algorithm a try:

https://www.phatcode.net/articles.php?id=459

When working with 3D data you have to project the circle onto the plane the triangle lies in first.

2 Likes