0
\$\begingroup\$

For my Maths unit at university, we have to manually calculate if a sphere is colliding with a capsule collider.

Point Description

The information I have to go with is this;

You have the following Sphere:

  • LadyBird3 - CentrePoint = (0, 0, 0), Radius = 18.0

And the following capsule

  • Sanic - BottomPoint = (0,2,6), TopPoint = (0, 12, 6), Radius = 5.0

Determine if the following pair-wise collision occurs:

Sanic & LadyBird3

In our lecture, we are told the following;

NOTE: Normalizing at this step is unimportant

First, we are going to check the Dot Product of AC and AB

  • If this Dot Product is less than 0, that means the closest point from the line segment to C is A

  • So we can just return the squared length of AC and stop any further calculations

  • Now we perform the same test with the Dot Product of BA and BC

  • Once again, if the Dot Product is less than 0, B would be the closest point on the line segment to C, so we would just return the length of BC and stop any further calculations.

Projection... If the dot product returned > 0 for both points of the line segment, we need to project C onto AB to get the distance. There's an efficient way to get the squared distance if this is all we care about:

  • SquaredDistance = AC.LengthSq - (AC . AB) * (AC . AB) / AB.LengthSq

  • When performing the dot product here, we need to make sure that it is NOT normalized.

And the final step is to use this squared distance and compare it to the sum of both radii squared to determine if there is an intersection.


So, I'm trying to calculate if they are intersecting or not using the information from above.

All I've managed to come up with is this (Taking away the LadyBird3 positions from Sanics position (TP, BP))

AC = (0, 2, 6)

AB = (0, -10, 0)

Dot Product = -20

BA = (0, 10, 0)

BC = (0, 12, 6)

Dot Product = 120

It feels like with the values I'm getting are not correct, or the process I'm doing is wrong... Is anyone able to point me in the right direction?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

With those test values you were given, it's clear that sanic is standing above ladybird (both points of the capsule have a larger y coordinate). Looking at the dot products confirms this:

The dot product of AC and AB was -20, which is less than 0. From your notes:

If this Dot Product is less than 0, that means the closest point from the line segment to C is A

This makes sense if you think about it. If I were to stand above you, the smallest distance between us would be the distance between your head and my feet.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .