public static bool IsTriangleInsectPlaneCircle2(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointArrayInfo insect) { Vector3 p11 = plane.TransformToLocal(p1); Vector3 p21 = plane.TransformToLocal(p2); Vector3 p31 = plane.TransformToLocal(p3); Vector3 c1 = plane.TransformToLocal(center); Vector2 p12 = new Vector2(p11.x, p11.z); Vector2 p22 = new Vector2(p21.x, p21.z); Vector2 p32 = new Vector2(p31.x, p31.z); Vector2 c2 = new Vector2(c1.x, c1.z); GeoInsectPointArrayInfo temp = new GeoInsectPointArrayInfo(); bool isInsect1 = IsTriangleInsectCircle2(p12, p22, p32, c2, r, ref temp); if (isInsect1) { insect.mIsIntersect = true; foreach (Vector3 v in temp.mHitGlobalPoint.mPointArray) { Vector3 vv = new Vector3(v.x, 0.0f, v.y); vv = plane.TransformToGlobal(vv); insect.mHitGlobalPoint.mPointArray.Add(vv); } return(true); } return(false); }
public static bool IsTriangleInsectTriangle2(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 p5, Vector2 p6, ref GeoInsectPointArrayInfo insect) { GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo(); List <Vector2> tri = new List <Vector2>(); tri.Add(p1); tri.Add(p2); tri.Add(p3); bool inSect = false; for (int i = 0; i < 3; ++i) { int j = (i + 1) % 3; inSect = GeoSegmentUtils.IsSegmentInsectOrOverlapTriangle2(tri[i], tri[j], p4, p5, p6, ref tmp) || inSect; } if (inSect) { insect.mHitGlobalPoint.mPointArray.AddRange(tmp.mHitGlobalPoint.mPointArray); } insect.mIsIntersect = insect.mHitGlobalPoint.mPointArray.Count > 0; if (insect.mIsIntersect) { insect.UniquePoint(); } 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 IsTriangleInsectCircle3(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointArrayInfo insect) { bool isInsect = GeoPlaneUtils.IsPlaneInsectTriangle(plane.mNormal, plane.mD, p1, p2, p3, ref insect); if (isInsect) { if (insect.mHitGlobalPoint.mPointArray.Count == 3) // 共面, 转化成 2d { insect.Clear(); return(IsTriangleInsectPlaneCircle2(p1, p2, p3, center, r, plane, ref insect)); } else if (insect.mHitGlobalPoint.mPointArray.Count == 1) { if (GeoCircleUtils.IsInSphere(center, r, insect.mHitGlobalPoint.mPointArray[0])) { return(true); } } else if (insect.mHitGlobalPoint.mPointArray.Count == 2) { Vector3 seg1 = plane.TransformToLocal(insect.mHitGlobalPoint.mPointArray[0]); Vector3 seg2 = plane.TransformToLocal(insect.mHitGlobalPoint.mPointArray[1]); Vector3 c1 = plane.TransformToLocal(center); Vector2 p12 = new Vector2(seg1.x, seg1.z); Vector2 p22 = new Vector2(seg2.x, seg2.z); Vector2 c2 = new Vector2(c1.x, c1.z); insect.Clear(); GeoInsectPointArrayInfo temp = new GeoInsectPointArrayInfo(); if (GeoSegmentUtils.IsSegmentInsectCircle2(p12, p22, c2, r, ref temp)) { insect.mIsIntersect = true; foreach (Vector3 v in temp.mHitGlobalPoint.mPointArray) { Vector3 vv = new Vector3(v.x, 0.0f, v.y); vv = plane.TransformToGlobal(vv); insect.mHitGlobalPoint.mPointArray.Add(vv); } return(true); } } } return(false); }
public static bool IsTriangleInsectCircle2(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 center, float r, ref GeoInsectPointArrayInfo insect) { GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo(); if (GeoSegmentUtils.IsSegmentInsectCircle2(p1, p2, center, r, ref tmp)) { insect.mHitGlobalPoint.mPointArray.AddRange(tmp.mHitGlobalPoint.mPointArray); } tmp.Clear(); if (GeoSegmentUtils.IsSegmentInsectCircle2(p3, p2, center, r, ref tmp)) { insect.mHitGlobalPoint.mPointArray.AddRange(tmp.mHitGlobalPoint.mPointArray); } tmp.Clear(); if (GeoSegmentUtils.IsSegmentInsectCircle2(p1, p3, center, r, ref tmp)) { insect.mHitGlobalPoint.mPointArray.AddRange(tmp.mHitGlobalPoint.mPointArray); } tmp.Clear(); return(false); }
// 两三角面 共面的情况 private static bool IsTriangleInsectTrianglePlane2(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 p5, Vector3 p6, ref GeoInsectPointArrayInfo insect) { GeoPlane plane = GeoPlaneUtils.CreateFromTriangle(p1, p2, p3); Vector2 p11, p21, p31, p41, p51, p61; GeoPlaneUtils.PlaneTransformLocalTriangle(p1, p2, p3, plane, out p11, out p21, out p31); GeoPlaneUtils.PlaneTransformLocalTriangle(p4, p5, p6, plane, out p41, out p51, out p61); GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo(); bool isInsect = IsTriangleInsectTriangle2(p11, p21, p31, p41, p51, p61, ref tmp); if (isInsect) { foreach (Vector3 v in tmp.mHitGlobalPoint.mPointArray) { Vector3 vt = new Vector3(v.x, 0.0f, v.z); vt = plane.TransformToGlobal(vt); insect.mHitGlobalPoint.mPointArray.Add(vt); } insect.mIsIntersect = insect.mHitGlobalPoint.mPointArray.Count > 0; } 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 IsAABBInsectCircle3(Vector3 min, Vector3 max, GeoPlane plane1, Vector3 center, float r, GeoPlane plane2, ref GeoInsectPointArrayInfo insect) { float dot = Vector3.Dot(plane1.mNormal, plane2.mNormal); if (1 - Mathf.Abs(dot) < 1e-5f) { if (GeoPlaneUtils.IsPointOnPlane(plane2.mNormal, plane2.mD, min)) { return(IsAABBInsectCirclePlane2(min, max, center, r, plane1, ref insect)); // should use plane1 } return(false); } GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo(); bool isInsect = GeoPlaneUtils.IsPlaneInsectCircle(plane1.mNormal, plane1.mD, center, r, plane2, ref tmp); if (isInsect) { if (tmp.mHitGlobalPoint.mPointArray.Count == 1) { Vector3 line1 = tmp.mHitGlobalPoint.mPointArray[0]; if (GeoAABBUtils.IsPointInAABB2Plane(min, max, plane1, ref line1)) { insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(line1); return(true); } } else { Vector3 seg1 = tmp.mHitGlobalPoint.mPointArray[0]; Vector3 seg2 = seg1 + tmp.mHitGlobalPoint.mPointArray[1]; return(GeoSegmentUtils.IsSegmentInsectAABB2Plane(seg1, seg2, min, max, plane1, ref insect)); } } return(false); }
public static bool IsAABBInsectTriangle3(Vector3 min, Vector3 max, Vector3 p1, Vector3 p2, Vector3 p3, ref GeoInsectPointArrayInfo insect) { // to do return(false); }
public static bool IsAABBInsectTriangle2Plane(Vector3 min, Vector3 max, GeoPlane plane, Vector3 p1, Vector3 p2, Vector3 p3, ref GeoInsectPointArrayInfo insect) { Vector2 p11, p21, p31; GeoPlaneUtils.PlaneTransformLocalTriangle(p1, p2, p3, plane, out p11, out p21, out p31); Vector3 vmin = plane.TransformToLocal(min); Vector3 vmax = plane.TransformToLocal(max); bool isInsect = IsAABBInsectTriangle2(vmin, vmax, p11, p21, p31, ref insect); if (isInsect) { insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray = GeoPlaneUtils.PlaneTransformGlobal(insect.mHitGlobalPoint.mPointArray, plane); } return(insect.mIsIntersect); }
public static bool IsAABBInsectSegment3(Vector3 min, Vector3 max, Vector3 seg1, Vector3 seg2, ref GeoInsectPointArrayInfo insect) { return(GeoSegmentUtils.IsSegmentInsectAABB3(seg1, seg2, min, max, ref insect)); }
public static bool IsAABBInsectTriangle2(Vector2 min, Vector2 max, Vector2 p1, Vector2 p2, Vector2 p3, ref GeoInsectPointArrayInfo insect) { // x = minx x = maxx // y = miny y = maxy List <Vector2> res = new List <Vector2>(); Vector2 v = new Vector2(); List <Vector2> tmp = new List <Vector2>(); tmp.Add(p1); tmp.Add(p2); tmp.Add(p3); for (int i = 0; i < 3; ++i) { int j = (i + 1) % 3; if (GeoSegmentUtils.InterpolateX2(tmp[i], tmp[j], min[0], ref v)) { if (v.y <= max[1] && v.y >= min[1]) { res.Add(v); } } v = new Vector2(); if (GeoSegmentUtils.InterpolateX2(tmp[i], tmp[j], max[0], ref v)) { if (v.y <= max[1] && v.y >= min[1]) { res.Add(v); } } v = new Vector2(); if (GeoSegmentUtils.InterpolateY2(tmp[i], tmp[j], min[1], ref v)) { if (v.x <= max[0] && v.x >= min[0]) { res.Add(v); } } v = new Vector2(); if (GeoSegmentUtils.InterpolateY2(tmp[i], tmp[j], max[1], ref v)) { if (v.x <= max[0] && v.x >= min[0]) { res.Add(v); } } } insect.mIsIntersect = res.Count > 0; if (insect.mIsIntersect) { foreach (Vector2 vt in res) { insect.mHitGlobalPoint.mPointArray.Add(new Vector3(vt.x, vt.y, 0.0f)); } } return(insect.mIsIntersect); }
public static bool IsSegmentOverlapTriangle3(Vector3 seg1, Vector3 seg2, Vector3 p1, Vector3 p2, Vector3 p3, ref GeoInsectPointArrayInfo insect) { List <Vector3> tri = new List <Vector3>(); for (int i = 0; i < 3; ++i) { IsSegmentOverlapSegment3(seg1, seg2, tri[i], tri[(i + 1) % 3], ref insect); } return(insect.mIsIntersect); }
public static bool IsAABBInsectCirclePlane2(Vector3 min, Vector3 max, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointArrayInfo insect) { Vector3 min1 = plane.TransformToLocal(min); Vector3 max1 = plane.TransformToLocal(max); Vector3 c1 = plane.TransformToLocal(center); bool isInsect = IsAABBInsectCircle2(min1, max1, c1, r, ref insect); if (isInsect) { insect.mHitGlobalPoint.mPointArray = GeoPlaneUtils.PlaneTransformGlobal(insect.mHitGlobalPoint.mPointArray, plane); } return(isInsect); }
public static bool IsAABBInsectAABB3(Vector3 min1, Vector3 max1, Vector3 min2, Vector3 max2, ref GeoInsectPointArrayInfo insect) { Vector3 min = Vector3.Max(min1, min2); Vector3 max = Vector3.Min(max1, max2); if (min.x > max.x || min.y > max.y || min.z > max.z) { return(false); } insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(min); insect.mHitGlobalPoint.mPointArray.Add(max); return(true); }
public static bool IsSegmentInsectSphere(Vector3 seg1, Vector3 seg2, Vector3 center, float r, ref GeoInsectPointArrayInfo insect) { // 389 公式存在问题, 按照代码来 Vector3 direction = seg2 - seg1; float a = Vector3.Dot(direction, direction); Vector3 c1 = seg1 - center; float b = 2 * Vector3.Dot(direction, c1); float c = Vector3.Dot(c1, c1) - r * r; float discrm = b * b - 4 * a * c; if (discrm < 0) { return(false); } discrm = Mathf.Sqrt(discrm); float t1 = -b + discrm; float t2 = -b - discrm; if ((t1 > 0 && t1 * t1 < a) || (t2 > 0 && t2 * t2 < a)) { insect.mIsIntersect = true; if (discrm == 0) { insect.mHitGlobalPoint.mPointArray.Add(seg1 + t1 * direction); } else { if (t1 > 0) { insect.mHitGlobalPoint.mPointArray.Add(seg1 + t1 * direction); } if (t2 > 0) { insect.mHitGlobalPoint.mPointArray.Add(seg1 + t2 * direction); } } } return(insect.mIsIntersect); }
public static bool IsPlaneInsectTriangle(Vector3 normal, float d, Vector3 p1, Vector3 p2, Vector3 p3, ref GeoInsectPointArrayInfo insect) { // 414 List <Vector3> tri = new List <Vector3>(); tri.Add(p1); tri.Add(p2); tri.Add(p3); List <Vector3> pPos = new List <Vector3>(); List <Vector3> pOn = new List <Vector3>(); foreach (Vector3 p in tri) { bool p1P = IsPointInPositiveHalf(normal, d, p); if (p1P) { pPos.Add(p); } else { p1P = IsPointOnPlane(normal, d, p); if (p1P) { pOn.Add(p); } } } if (pPos.Count == 3 && pOn.Count == 0) // 三点都在 一侧 { return(false); } if (pPos.Count == 2 && pOn.Count == 1) // 一点在上,另两点同侧 { insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(pOn[0]); return(true); } if (pPos.Count == 1 && pOn.Count == 2) { insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(pOn[0]); insect.mHitGlobalPoint.mPointArray.Add(pOn[1]); return(true); } if (pPos.Count == 0 && pOn.Count == 3) // 共面 { insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(pOn[0]); insect.mHitGlobalPoint.mPointArray.Add(pOn[1]); insect.mHitGlobalPoint.mPointArray.Add(pOn[2]); return(true); } insect.mIsIntersect = true; GeoInsectPointInfo temp = new GeoInsectPointInfo(); for (int i = 0; i < 3; ++i) { if (IsPlaneInsectSegment(normal, d, tri[i], tri[(i + 1) % 3], ref temp)) { insect.mHitGlobalPoint.mPointArray.Add(temp.mHitGlobalPoint); } } return(true); }
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 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 IsPlaneInsectPlane(Vector3 normal1, float d1, Vector3 normal2, float d2, ref GeoInsectPointArrayInfo insect) { // 410 所有的法向量必须先单位化 Vector3 lineDirection = Vector3.Cross(normal1, normal2); if (lineDirection.magnitude < 1e-5f) // 平行 { return(false); } float n1n2 = Vector3.Dot(normal1, normal2); float m = n1n2 * n1n2 - 1; float a = (-d2 * n1n2 + d1) / m; float b = (-d1 * n1n2 + d2) / m; Vector3 p = a * normal1 + b * normal2; insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(p); // 直线 上一点 insect.mHitGlobalPoint.mPointArray.Add(lineDirection); // 直线 方向 return(true); }
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 IsAABBInsectSphere(Vector3 min, Vector3 max, Vector3 center, float r, ref GeoInsectPointArrayInfo insect) { // to do return(false); }
public virtual bool IsIntersect(ref GeoRay3 dist, ref GeoInsectPointArrayInfo insect) { return(false); }
public static bool IsAABBInsectAABB2(Vector2 min1, Vector2 max1, Vector2 min2, Vector2 max2, ref GeoInsectPointArrayInfo insect) { /* * //若相交,求得为一个重叠的矩形区域 * minx = max(minx1, minx2) * miny = max(miny1, miny2) * maxx = min(maxx1, maxx2) * maxy = min(maxy1, maxy2) * minx > maxx 或者 miny > maxy */ Vector2 min = Vector2.Max(min1, min2); Vector2 max = Vector2.Min(max1, max2); if (min.x > max.x || min.y > max.y) { return(false); } insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(new Vector3(min.x, min.y, 0.0f)); insect.mHitGlobalPoint.mPointArray.Add(new Vector3(max.x, max.y, 0.0f)); return(true); }
public static bool IsSegmentOverlapSegment3(Vector3 seg1, Vector3 seg2, Vector3 seg3, Vector3 seg4, ref GeoInsectPointArrayInfo insect) { Vector3 seg12 = seg2 - seg1; Vector3 seg34 = seg4 - seg3; Vector3 seg13 = seg3 - seg1; float mag = Vector3.Cross(seg12, seg34).magnitude; if (mag > GeoUtils.PRECISION) // 不平行的 排除 { return(false); } mag = Vector3.Cross(seg13, seg34).magnitude; if (mag > GeoUtils.PRECISION) // 不共线的 排除 { return(false); } Vector3 p1 = new Vector3(); Vector3 p2 = new Vector3(); bool isOver = false; if (seg34.magnitude < seg12.magnitude) { isOver = IsSegmentOverlapSegment3(seg1, seg2, seg3, seg4, ref p1, ref p2); } else { isOver = IsSegmentOverlapSegment3(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); }
public static bool IsAABBInsectRay3(Vector3 min, Vector3 max, Vector3 rayOrigin, Vector3 rayDirection, ref GeoInsectPointArrayInfo insect) { return(GeoRayUtils.IsRayInsectAABB3(rayOrigin, rayDirection, min, max, ref insect)); }
public static bool IsPlaneInsectSphere(GeoPlane plane, Vector3 center, float r, ref GeoInsectPointArrayInfo insect) { Vector3 close = new Vector3(); float dist = PointClosestToPlaneAbs(plane.mNormal, plane.mD, center, ref close); if (dist > r) { return(false); } float rad = Mathf.Sqrt(r * r - dist * dist); insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(close); insect.mHitGlobalPoint.mPointArray.Add(Vector3.one * rad); // 相交为一个圆,所在平明为 plane return(true); }
public static bool IsAABBInsectCircle2(Vector2 min, Vector2 max, Vector2 center, float r, ref GeoInsectPointArrayInfo insect) { /* * rect : p(x, y) = p1 + u * d1 + v * d2 (0 < u < 1, 0 < v < 1) * (p - center).magnitude = r */ Vector2 d1 = new Vector2(max[0] - min[0], 0); Vector2 d2 = new Vector2(0, max[1] - min[1]); // float x = min[0] + u * d1[0]; // float y = min[1] + v * d2[1]; // (x - center[0]) * (x - center[0]) + (y - center[1]) * (y - center[1]) = r * r; List <Vector3> tmp = new List <Vector3>(); // x = minx u = 0 float d = r * r - (min[0] - center[0]) * (min[0] - center[0]); if (d >= 0) { d = Mathf.Sqrt(d); float y1 = center[1] + d; if (y1 >= min[1] && y1 <= max[1]) { tmp.Add(new Vector3(min[0], y1, 0.0f)); } if (d > 0) { float y2 = center[1] - d; if (y2 >= min[1] && y2 <= max[1]) { tmp.Add(new Vector3(min[0], y2, 0.0f)); } } } // x = maxx u = 1 d = r * r - (max[0] - center[0]) * (max[0] - center[0]); if (d >= 0) { d = Mathf.Sqrt(d); float y1 = center[1] + d; if (y1 >= min[1] && y1 <= max[1]) { tmp.Add(new Vector3(max[0], y1, 0.0f)); } if (d > 0) { float y2 = center[1] - d; if (y2 >= min[1] && y2 <= max[1]) { tmp.Add(new Vector3(max[0], y2, 0.0f)); } } } // y = miny v = 0 d = r * r - (min[1] - center[1]) * (min[1] - center[1]); if (d >= 0) { d = Mathf.Sqrt(d); float x1 = center[0] + d; if (x1 >= min[0] && x1 <= max[1]) { tmp.Add(new Vector3(x1, min[1], 0.0f)); } if (d > 0) { float x2 = center[0] - d; if (x2 >= min[0] && x2 <= max[1]) { tmp.Add(new Vector3(x2, min[1], 0.0f)); } } } // y = maxy v = 1 d = r * r - (max[1] - center[1]) * (max[1] - center[1]); if (d >= 0) { d = Mathf.Sqrt(d); float x1 = center[0] + d; if (x1 >= min[0] && x1 <= max[1]) { tmp.Add(new Vector3(x1, min[1], 0.0f)); } if (d > 0) { float x2 = center[0] - d; if (x2 >= min[0] && x2 <= max[1]) { tmp.Add(new Vector3(x2, max[1], 0.0f)); } } } insect.mIsIntersect = tmp.Count > 0; if (insect.mIsIntersect) { insect.mHitGlobalPoint.mPointArray = tmp; } return(insect.mIsIntersect); }
public static bool IsPlaneInsectAABB3(Vector3 normal, float d, Vector3 min, Vector3 max, ref GeoInsectPointArrayInfo insect) { return(false); }