public static bool IsSegmentInsectCircle2(Vector2 seg1, Vector2 seg2, Vector2 center, float r, ref GeoInsectPointArrayInfo insect) { if (GeoCircleUtils.IsInCircle(center, r, seg1) && GeoCircleUtils.IsInCircle(center, r, seg2)) // 都在外面,不一定 { return(false); } bool isinsect = GeoLineUtils.IsLineInsectCircle2(seg1, seg2, center, r, ref insect); List <Vector3> array = insect.mHitGlobalPoint.mPointArray; List <int> removeIndex = new List <int>(); for (int i = 0; i < array.Count; ++i) { Vector2 temp = new Vector2(array[i].x, array[i].y); if (!IsPointInSegment2(seg1, seg2, ref temp)) { removeIndex.Add(i); } } for (int i = removeIndex.Count - 1; i >= 0; --i) { array.RemoveAt(i); } insect.mHitGlobalPoint.mPointArray = array; insect.mIsIntersect = insect.mHitGlobalPoint.mPointArray.Count > 0; return(insect.mIsIntersect); }
public static bool IsSegmentOverlapSegment2(Vector2 seg1, Vector2 seg2, Vector2 seg3, Vector2 seg4, ref GeoInsectPointArrayInfo insect) { // 4 点共线 if (GeoLineUtils.IsPointInLine2(seg3, seg4, ref seg1) && GeoLineUtils.IsPointInLine2(seg3, seg4, ref seg2)) { Vector2 seg12 = seg2 - seg1; Vector2 seg34 = seg4 - seg3; Vector2 seg13 = seg3 - seg1; Vector2 p1 = new Vector2(); Vector2 p2 = new Vector2(); bool isOver = false; if (seg34.magnitude < seg12.magnitude) { isOver = IsSegmentOverlapSegment2(seg1, seg2, seg3, seg4, ref p1, ref p2); } else { isOver = IsSegmentOverlapSegment2(seg3, seg4, seg1, seg2, ref p1, ref p2); } if (isOver) { insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(p1); insect.mHitGlobalPoint.mPointArray.Add(p2); } return(insect.mIsIntersect); } return(false); }
public static bool IsRayInsectAABB3(Vector3 rayOrigin, Vector3 rayDirection, Vector3 min, Vector3 max, ref GeoInsectPointArrayInfo insect) { bool isInsect = GeoLineUtils.IsLineInsectAABB3(rayOrigin, rayDirection + rayOrigin, min, max, ref insect); if (isInsect) { List <Vector3> tmp = new List <Vector3>(); List <Vector3> tmp1 = insect.mHitGlobalPoint.mPointArray; for (int i = 0; i < tmp1.Count; ++i) { Vector3 v = tmp1[i]; if (GeoRayUtils.IsPointInRay3(rayOrigin, rayDirection, ref v)) { tmp.Add(v); } } if (tmp.Count > 0) { insect.mHitGlobalPoint.mPointArray = tmp; insect.mHitGlobalPoint.mPointArray.Sort((v1, v2) => { return((v1 - rayOrigin).sqrMagnitude.CompareTo((v2 - rayOrigin).sqrMagnitude)); }); } else { insect.mIsIntersect = false; } } return(insect.mIsIntersect); }
public static bool IsRayInsectAABB2(Vector2 rayOrigin, Vector2 rayDirection, Vector2 min, Vector2 max, ref GeoInsectPointArrayInfo insect) { bool isInsect = GeoLineUtils.IsLineInsectAABB2(rayOrigin, rayDirection + rayOrigin, min, max, ref insect); if (isInsect) { List <Vector3> tmp = new List <Vector3>(); foreach (Vector3 v in insect.mHitGlobalPoint.mPointArray) { Vector2 v2 = new Vector2(v.x, v.y); if (GeoRayUtils.IsPointInRay2(rayOrigin, rayDirection, ref v2)) { tmp.Add(v); } } if (tmp.Count > 0) { insect.mHitGlobalPoint.mPointArray = tmp; } else { insect.mIsIntersect = false; } } return(insect.mIsIntersect); }
public static bool IsPlaneInsectCircle(Vector3 normal, float d, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointArrayInfo insect) { float tmp = Mathf.Abs(Vector3.Dot(plane.mNormal.normalized, normal.normalized)); if (1 - tmp < 1e-5f) { return(false); // 平行 或 共面 } GeoInsectPointArrayInfo tmp1 = new GeoInsectPointArrayInfo(); bool inSect = IsPlaneInsectPlane(normal, d, plane.mNormal, plane.mD, ref tmp1); if (inSect) { Vector3 line1 = tmp1.mHitGlobalPoint.mPointArray[0] + tmp1.mHitGlobalPoint.mPointArray[1]; GeoLineUtils.IsLineInsectCirclePlane2(tmp1.mHitGlobalPoint.mPointArray[0], line1, center, r, plane, ref insect); } return(insect.mIsIntersect); }
public static bool IsPlaneInsectAABB2(Vector3 normal, float d, Vector3 min, Vector3 max, GeoPlane plane, ref GeoInsectPointArrayInfo insect) { float dot = Vector3.Dot(normal, plane.mNormal); if (1 - Mathf.Abs(dot) < 1e-5f) { return(false); } GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo(); bool isInsect = GeoPlaneUtils.IsPlaneInsectPlane(normal, d, plane.mNormal, plane.mD, ref tmp); if (isInsect) { Vector3 l1 = tmp.mHitGlobalPoint.mPointArray[0]; Vector3 l2 = l1 + tmp.mHitGlobalPoint.mPointArray[1]; isInsect = GeoLineUtils.IsLineInsectAABBPlane2(l1, l2, min, max, plane, ref insect); } return(insect.mIsIntersect); }
public static bool IsSegmentInsectAABB2(Vector2 seg1, Vector2 seg2, Vector2 min, Vector2 max, ref GeoInsectPointArrayInfo insect) { bool isInsect = GeoLineUtils.IsLineInsectAABB2(seg1, seg2, min, max, ref insect); if (isInsect) { List <Vector3> tmp = new List <Vector3>(); foreach (Vector3 v in insect.mHitGlobalPoint.mPointArray) { Vector2 v2 = new Vector2(v.x, v.y); if (GeoSegmentUtils.IsPointInSegment2(seg1, seg2, ref v2)) { tmp.Add(v); } } insect.mHitGlobalPoint.mPointArray = tmp; } return(insect.mIsIntersect); }
public static bool IsRayInsectTriangle2(Vector2 rayOrigin, Vector2 rayDirection, Vector2 p1, Vector2 p2, Vector2 p3, ref GeoInsectPointArrayInfo insect) { if (GeoLineUtils.IsLineInsectTriangle2(rayOrigin, rayOrigin + rayDirection, p1, p2, p3, ref insect)) { List <Vector3> tmp = insect.mHitGlobalPoint.mPointArray; List <Vector3> tmp1 = new List <Vector3>(); for (int i = 0; i < tmp.Count; ++i) { Vector2 v = new Vector2(tmp[i].x, tmp[i].y); if (IsPointInRay2(rayOrigin, rayDirection, ref v)) { tmp1.Add(tmp[i]); } } if (tmp1.Count > 0) { insect.mHitGlobalPoint.mPointArray = tmp1; } } return(insect.mIsIntersect); }
public static bool IsCircleInsectCircle3(Vector3 center1, float r1, GeoPlane plane1, Vector3 center2, float r2, GeoPlane plane2, ref GeoInsectPointArrayInfo insect) { float dot = Mathf.Abs(Vector3.Dot(plane1.mNormal, plane2.mNormal)); if (1 - dot < GeoUtils.PRECISION) { if (GeoPlaneUtils.IsPointOnPlane(plane2.mNormal, plane2.mD, center1)) // 共面 { return(IsCircleInsectCirclePlane2(center1, r1, center2, r2, plane2, ref insect)); } return(false); } GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo(); bool isInsect = GeoPlaneUtils.IsPlaneInsectCircle(plane1.mNormal, plane1.mD, center2, r2, plane2, ref tmp); if (isInsect) { Vector3 lin1 = tmp.mHitGlobalPoint.mPointArray[0]; Vector3 lin2 = lin1 + tmp.mHitGlobalPoint.mPointArray[1]; GeoLineUtils.IsLineInsectCirclePlane2(lin1, lin2, center1, r1, plane1, ref insect); } return(insect.mIsIntersect); }
public static bool IsSegmentInsectAABB3(Vector3 seg1, Vector3 seg2, Vector3 min, Vector2 max, ref GeoInsectPointArrayInfo insect) { bool isInsect = GeoLineUtils.IsLineInsectAABB3(seg1, seg2, min, max, ref insect); if (isInsect) { List <Vector3> tmp = new List <Vector3>(); foreach (Vector3 v in insect.mHitGlobalPoint.mPointArray) { Vector3 v2 = v; if (GeoSegmentUtils.IsPointInSegment3(seg1, seg2, ref v2)) { tmp.Add(v); } } insect.mIsIntersect = false; if (tmp.Count > 0) { insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray = tmp; } } return(insect.mIsIntersect); }
public static bool IsAABBInsectLine3(Vector3 min, Vector3 max, Vector3 line1, Vector3 line2, ref GeoInsectPointArrayInfo insect) { return(GeoLineUtils.IsLineInsectAABB3(line1, line2, min, max, ref insect)); }
public static bool IsSegmentInsectLine3(Vector3 seg1, Vector3 seg2, Vector3 line1, Vector3 line2, ref GeoInsectPointInfo insect) { return(GeoLineUtils.IsLineInsectSegment3(line1, line2, seg1, seg2, ref insect)); }
public static bool IsRayInsectLine3(Vector3 rayOrigin, Vector3 rayDirection, Vector3 line1, Vector3 line2, ref GeoInsectPointInfo insect) { return(GeoLineUtils.IsLineInsectRay3(line1, line2, rayOrigin, rayDirection, ref insect)); }
public static bool IsTriangleInsectLine3(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 line1, Vector3 line2, ref GeoInsectPointInfo insect) { return(GeoLineUtils.IsLineInsectTriangle3(line1, line2, p1, p2, p3, ref insect)); }
public static bool IsTriangleInsectLine2(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 line1, Vector2 line2, ref GeoInsectPointArrayInfo insect) { return(GeoLineUtils.IsLineInsectTriangle2(line1, line2, p1, p2, p3, ref insect)); }