public static float getIntersection(LineElement line, Joint joint)
{
Microsoft.DirectX.Vector3 i = line.I.Position;
Microsoft.DirectX.Vector3 j = line.J.Position;
Microsoft.DirectX.Vector3 pos = joint.Position;
float ret, retx, rety, retz;
float eps = 0.001f;
//retx = (j.X != i.X) ? (pos.X - i.X) / (j.X - i.X) : (equals(pos.X, i.X, eps)) ? float.NaN : 0;
//rety = (j.Y != i.Y) ? (pos.Y - i.Y) / (j.Y - i.Y) : (equals(pos.Y, i.Y, eps)) ? retx : 0;
//retz = (j.Z != i.Z) ? (pos.Z - i.Z) / (j.Z - i.Z) : (equals(pos.Z, i.Z, eps)) ? rety : 0;
//rety = (!float.IsNaN(rety)) ? rety : retz;
//retx = (!float.IsNaN(retx)) ? retx : rety;
//return (equals(retx, rety, eps) && equals(rety, retz, eps) && retx - eps > 0 && retx + eps < 1) ? retx : 0;
Microsoft.DirectX.Vector3 xmp = joint.Position - line.I.Position;
Microsoft.DirectX.Vector3 dir = line.J.Position - line.I.Position;
ret = (Math.Abs(xmp.X) > Math.Abs(xmp.Y)) ? ((Math.Abs(xmp.X) > Math.Abs(xmp.Z)) ? xmp.X / dir.X : xmp.Z / dir.Z) : ((Math.Abs(xmp.Y) > Math.Abs(xmp.Z)) ? xmp.Y / dir.Y : xmp.Z / dir.Z);
return (equals(ret * dir.X, xmp.X, eps) && equals(ret * dir.Y, xmp.Y, eps) && equals(ret * dir.Z, xmp.Z, eps)) ? ret : 0;
}