# Introduction

## What Is A Capsule?

The capsule collision is a simple extension to the sphere intersection test. A capsule is defined, in most cases, by a base point a and a tip point b.

A capsule collision can be defined like this:
$$R = {x|(x - [a + (b - a) * t]) ^ 2 \leq r }, 0 \leq t \leq 1$$ ## Why Is Capsule Important?

We can of course use cylinders as bounding volumes. Unfortunately, it turns out that the overlap test for cylinders is quite expensive.

As an alternative result, capsule shapes are wildly used in physics engines because of calculation simplicity. Thus it is always good to know what is happening deep inside when collisions are detected.

# Collision Detection Methods

## Sphere-Capsule Intersection

A useful property of capsules, or rather, sphere-swept volumes, is that the distance computation between the inner structures does not rely on the inner structures being of the same type.

So we only need to compare the shortest distance and the radius sum, and that’s it. The code is like this:

Distance from point to a segment can be easily calculated by:

Or you may want the reference point value:

## Capsule-Capsule Intersection

It is natural to consider a capsule-capsule intersection as a problem to solve the distance between two segments:

This is much more complicated, however, to compute closest points of two segments.

I simply copy the code from Real Time Collision Detection here since this is not the point in this article:

## Triangle-Capsule Intersection

Still we need to talk about triangle-capsule intersection.

First of all, we can find the closest point on a line to this triangle. And this is how we find the reference point:

I am so cute, please give me money...