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 void PlaneTransformLocalTriangle(Vector3 p1, Vector3 p2, Vector3 p3, GeoPlane plane, out Vector2 p11, out Vector2 p21, out Vector2 p31) { Vector3 p1t = plane.TransformToLocal(p1); Vector3 p2t = plane.TransformToLocal(p2); Vector3 p3t = plane.TransformToLocal(p3); p11 = new Vector2(p1t.x, p1t.z); p21 = new Vector2(p2t.x, p2t.z); p31 = new Vector2(p3t.x, p3t.z); }
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 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); }
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 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 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 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 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); }
// 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 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); }