public float IsRayIntersect(Vector2 pos, Vector2 dir) { float d = 1e10f; GeoInsectPointInfo info = new GeoInsectPointInfo(); if (GeoRayUtils.IsRayInsectSegment2(pos, dir, mP1, mP2, ref info)) { d = info.mLength; } info = new GeoInsectPointInfo(); if (GeoRayUtils.IsRayInsectSegment2(pos, dir, mP3, mP2, ref info)) { d = Math.Min(d, info.mLength); } info = new GeoInsectPointInfo(); if (GeoRayUtils.IsRayInsectSegment2(pos, dir, mP1, mP4, ref info)) { d = Math.Min(d, info.mLength); } info = new GeoInsectPointInfo(); if (GeoRayUtils.IsRayInsectSegment2(pos, dir, mP3, mP4, ref info)) { d = Math.Min(d, info.mLength); } return(d); }
public bool IsIntersect(ref GeoRay2 dist, ref GeoInsectPointArrayInfo insect) { GeoInsectPointInfo info = new GeoInsectPointInfo(); bool isInsect = GeoRayUtils.IsRayInsectSegment2(dist.mOrigin, dist.mDirection, mSeg.mP1, mSeg.mP2, ref info); insect.mIsIntersect = isInsect; if (isInsect) { insect.mHitObject2 = this; insect.mHitGlobalPoint.mPointArray.Add(info.mHitGlobalPoint); insect.mLength = (GeoUtils.ToVector2(info.mHitGlobalPoint) - dist.mOrigin).magnitude; } return(isInsect); }