Hi, I had some problem to get the method JigLibX.Geometry.Intersection.SegmentCapsuleIntersection

to work corectly. I got a true value when my segment and capsule soulden't collide.

So I looked at the implementation in JigLibX and compared it to the C++ implementation.

First of all i find it strange that the two SegmentSphereIntersection method as followed was made with to identical spheres in the xna implemetation.

I supose it got lost in the C# translation and it sould be capsuel.GetEnd() in the last row as in the C++ implementation.

```
// do the two ends
float originFrac = float.MaxValue;
SegmentSphereIntersection(out originFrac, seg, new Sphere(capsule.Position, capsule.Radius));
float endFrac = float.MaxValue; // Check this!
SegmentSphereIntersection(out endFrac, seg, new Sphere(capsule.Position, capsule.Radius));
```

Then I noticed that the SegmentSphereIntersection method was giving me strange results.

When I looked at it I realized that the C# impementation assigned the first parameter (ts) in a bad way.

Instead of assign it to 0.0f it sould me assigned float.MaxValue so if it fales it it sould return the max value as in

the C++ implementaion.

```
public static bool SegmentSphereIntersection(out float ts, Segment seg, Sphere sphere)
{
Vector3 r = seg.Delta;
Vector3 s = seg.Origin - sphere.Position;
float radiusSq = sphere.Radius * sphere.Radius;
float rSq = r.LengthSquared();
ts = 0.0f;
if (rSq < radiusSq)
{
// starting inside
ts = 0.0f;
return false;
}
float sDotr = Vector3.Dot(s, r);
float sSq = s.LengthSquared();
float sigma = (sDotr * sDotr) - rSq * (sSq - radiusSq);
if (sigma < 0.0f)
return false;
float sigmaSqrt = (float)System.Math.Sqrt((float)sigma);
float lambda1 = (-sDotr - sigmaSqrt) / rSq;
float lambda2 = (-sDotr + sigmaSqrt) / rSq;
if (lambda1 > 1.0f || lambda2 < 0.0f)
return false;
// intersection!
ts = MathHelper.Max(lambda1, 0.0f);
return true;
}
```

When I did these two changes in the code my collison test works as it should.

SegmentCapsuleIntersection:

1. SegmentSphereIntersection(out endFrac, seg, new Sphere(capsule.GetEnd(), capsule.Radius));

SegmentSphereIntersection

2. ts = float.MaxValue;

When I looked at the C++ implementation of the method SegmentCapsuleIntersection I also noticed that

the originFrac variable was passed as a parameter in both sphere tests and I think shuld be endFrac

in the secound one, otherwise it did not make any sense to me..

```
// do the two ends
tScalar originFrac = SCALAR_HUGE;
SegmentSphereIntersection(&originFrac, seg, tSphere(capsule.GetPos(), capsule.GetRadius()));
tScalar endFrac = SCALAR_HUGE;
SegmentSphereIntersection(&originFrac, seg, tSphere(capsule.GetEnd(), capsule.GetRadius()));
bestFrac = Min(sideFrac, originFrac, endFrac);
```

Please reply if I made any wrong observation or if I maybe used the methodes in a bad way.