public static List <Vector3> PlaneTransformGlobal(List <Vector2> ps, GeoPlane plane) { List <Vector3> tmp = new List <Vector3>(); foreach (Vector3 p in ps) { Vector3 v = new Vector3(p.x, 0.0f, p.y); tmp.Add(plane.TransformToGlobal(v)); } return(tmp); }
public static List <Vector2> PlaneTransformLocal(List <Vector3> ps, GeoPlane plane) { List <Vector2> tmp = new List <Vector2>(); foreach (Vector3 p in ps) { Vector3 p1 = plane.TransformToLocal(p); tmp.Add(new Vector2(p.x, p.z)); } return(tmp); }
public static bool IsTriangleInsectSphere(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 center, float r, ref GeoInsectPointArrayInfo insect) { GeoPlane plane = GeoPlaneUtils.CreateFromTriangle(p1, p2, p3); bool isInsec = GeoPlaneUtils.IsPlaneInsectSphere(plane, center, r, ref insect); if (isInsec) { Vector3 c1 = insect.mHitGlobalPoint.mPointArray[0]; float rad = insect.mHitGlobalPoint.mPointArray[0][0]; insect.Clear(); return(IsTriangleInsectPlaneCircle2(p1, p2, p3, c1, rad, plane, ref insect)); } return(false); }
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 float PointClosest2Triangle3(Vector3 p1, Vector3 p2, Vector3 p3, ref Vector3 p, ref Vector3 close) { GeoPlane plane = new GeoPlane(p1, p2, p3); float d = GeoPlaneUtils.PointClosestToPlaneAbs(plane.mNormal, plane.mD, p, ref close); if (GeoTriangleUtils.IsPointInTriangle3(p1, p2, p3, ref close)) { return(d); } else { Vector3 close1 = new Vector3(); float dt = PointClosest2PlaneTriangle2(p1, p2, p3, plane, ref p, ref close1); return((float)Math.Sqrt(d * d + dt * dt)); } }
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 float PointClosest2PlaneAABB2(Vector3 min, Vector3 max, GeoPlane plane, ref Vector3 p, ref Vector3 close1) { Vector3 min1 = plane.TransformToLocal(min); Vector3 max1 = plane.TransformToLocal(max); Vector3 p1 = plane.TransformToLocal(p); Vector2 min2 = new Vector2(min1.x, min1.z); Vector2 max2 = new Vector2(max1.x, max1.z); Vector2 p2 = new Vector2(p1.x, p1.z); Vector2 close = new Vector2(); float temp = PointClosest2AABB2(min2, max2, ref p2, ref close); if (p1.y != 0) { temp = Mathf.Sqrt(temp * temp + p1.y * p1.y); } p1 = new Vector3(close.x, 0.0f, close.y); close1 = plane.TransformToGlobal(p1); return(temp); }
public static bool IsPointInAABB2Plane(Vector3 min, Vector3 max, GeoPlane plane, ref Vector3 p) { if (!GeoPlaneUtils.IsPointOnPlane(plane.mNormal, plane.mD, p)) { return(false); } Vector3 size = max - min; float sx = Vector3.Dot(size, plane.mAxisX); float sz = Vector3.Dot(size, plane.mAxisZ); Vector3 pc = p - min; float d1 = Vector3.Dot(pc, plane.mAxisX); float d2 = Vector3.Dot(pc, plane.mAxisZ); if (d1 < sx && d2 < sz) { return(true); } 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 float PointDistanceToPlane(GeoPlane plane, Vector3 p) { return(PointDistanceToPlane(plane.mNormal, plane.mD, p)); }
public static bool IsLineInsectAABBPlane2(Vector3 line1, Vector3 line2, Vector3 min, Vector3 max, GeoPlane plane, ref GeoInsectPointArrayInfo insect) { Vector3 min1 = plane.TransformToLocal(min); Vector3 max1 = plane.TransformToLocal(max); Vector3 l1 = plane.TransformToLocal(line1); Vector3 l2 = plane.TransformToLocal(line2); bool isInsect = IsLineInsectAABB2(new Vector2(l1.x, l1.z), new Vector2(l2.x, l2.z), new Vector2(min1.x, min1.z), new Vector2(max1.x, max1.z), ref insect); if (isInsect) { insect.mHitGlobalPoint.mPointArray = GeoPlaneUtils.PlaneTransformGlobal(insect.mHitGlobalPoint.mPointArray, plane); } return(isInsect); }
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 void PlaneTransformGlobaleTriangle(Vector3 p1, Vector3 p2, Vector3 p3, GeoPlane plane, out Vector2 p11, out Vector2 p21, out Vector2 p31) { Vector3 p1t = plane.TransformToGlobal(p1); Vector3 p2t = plane.TransformToGlobal(p2); Vector3 p3t = plane.TransformToGlobal(p3); p11 = new Vector2(p1t.x, p1t.z); p21 = new Vector2(p2t.x, p2t.z); p31 = new Vector2(p3t.x, p3t.z); }
public static void PlaneTransformGlobaleTriangle(Vector3 p1, Vector3 p2, Vector3 p3, GeoPlane plane, out Vector3 p11, out Vector3 p21, out Vector3 p31) { p11 = plane.TransformToGlobal(p1); p21 = plane.TransformToGlobal(p2); p31 = plane.TransformToGlobal(p3); }
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 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 IsLineInsectCircle3(Vector3 line1, Vector3 line2, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointArrayInfo insect) { if (GeoPlaneUtils.IsPointOnPlane(plane.mNormal, plane.mD, line1) && GeoPlaneUtils.IsPointOnPlane(plane.mNormal, plane.mD, line2)) { return(IsLineInsectCirclePlane2(line1, line2, center, r, plane, ref insect)); } GeoInsectPointInfo info = new GeoInsectPointInfo(); bool isInsect = GeoPlaneUtils.IsPlaneInsectLine(plane.mNormal, plane.mD, line1, line2, ref info); if (isInsect) { if (GeoCircleUtils.IsInSphere(center, r, info.mHitGlobalPoint)) { insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(info.mHitGlobalPoint); return(true); } insect.mIsIntersect = false; } return(false); }
// 3 维 共面 public static bool IsCircleInsectCirclePlane2(Vector3 center1, float r1, Vector3 center2, float r2, GeoPlane plane, ref GeoInsectPointArrayInfo insect) { Vector3 c1 = plane.TransformToLocal(center1); Vector3 c2 = plane.TransformToLocal(center2); bool isInsect = IsCircleInsectCircle2(new Vector2(c1.x, c1.z), r1, new Vector2(c2.x, c2.z), r2, ref insect); if (isInsect) { List <Vector3> t3 = new List <Vector3>(); foreach (Vector3 v in insect.mHitGlobalPoint.mPointArray) { Vector3 tmp = new Vector3(v.x, 0.0f, v.y); Vector3 glo = plane.TransformToGlobal(tmp); t3.Add(glo); } insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray = t3; } return(insect.mIsIntersect); }
public static bool IsRayInsectCircle3(Vector3 rayOrigin, Vector3 rayDirection, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointInfo insect) { if (GeoPlaneUtils.IsPlaneInsectRay(plane.mNormal, plane.mD, rayOrigin, rayDirection, ref insect)) { if (GeoCircleUtils.IsInSphere(center, r, insect.mHitGlobalPoint)) { return(true); } } return(false); }
public static bool IsPointInPositiveHalf(GeoPlane plane, Vector3 p) { float d = PointDistanceToPlane(plane, p); return(d > GeoUtils.PRECISION); }
public static bool IsPointInPositiveHalf(GeoPlane plane, Vector3 p) { float d = PointDistanceToPlane(plane, p); return(d > 1e-5f); }
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 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 IsSegmentInsectCircle3(Vector3 seg1, Vector3 seg2, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointInfo insect) { bool isInsect = GeoPlaneUtils.IsPlaneInsectSegment(plane.mNormal, plane.mD, seg1, seg2, ref insect); if (isInsect) { if (GeoCircleUtils.IsInSphere(center, r, insect.mHitGlobalPoint)) { return(true); } } insect.mIsIntersect = isInsect; return(isInsect); }
public static float PointClosest2PlaneTriangle2(Vector3 p1, Vector3 p2, Vector3 p3, GeoPlane plane, ref Vector3 p, ref Vector3 close) { Vector2 p11, p21, p31, pt; GeoPlaneUtils.PlaneTransformLocalTriangle(p1, p2, p3, plane, out p11, out p21, out p31); Vector3 pp = plane.TransformToLocal(p); pt = new Vector2(pp.x, pp.z); Vector2 close1 = new Vector2(); float d = PointClosest2Triangle2(p11, p21, p31, ref pt, ref close1); close.x = close1.x; close.y = 0; close.z = close1.y; close = plane.TransformToGlobal(close); return(d); }
public static bool IsSegmentInsectAABB2Plane(Vector3 seg1, Vector3 seg2, Vector3 min, Vector2 max, GeoPlane plane, ref GeoInsectPointArrayInfo insect) { Vector3 s1 = plane.TransformToLocal(seg1); Vector3 s2 = plane.TransformToLocal(seg2); Vector3 min1 = plane.TransformToLocal(min); Vector3 max1 = plane.TransformToLocal(max); bool isInsect = IsSegmentInsectAABB2(s1, s2, min1, max1, ref insect); if (isInsect) { insect.mHitGlobalPoint.mPointArray = GeoPlaneUtils.PlaneTransformGlobal(insect.mHitGlobalPoint.mPointArray, plane); } return(isInsect); }
public static bool IsLineInsectCirclePlane2(Vector3 line1, Vector3 line2, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointArrayInfo insect) { Vector3 l1 = plane.TransformToLocal(line1); Vector3 l2 = plane.TransformToLocal(line2); Vector3 c1 = plane.TransformToLocal(center); bool isInsect = IsLineInsectCircle2(new Vector2(l1.x, l1.z), new Vector2(l2.x, l2.z), new Vector2(c1.x, c1.z), r, ref insect); if (isInsect) { insect.mHitGlobalPoint.mPointArray = GeoPlaneUtils.PlaneTransformGlobal(insect.mHitGlobalPoint.mPointArray, plane); } return(insect.mIsIntersect); }