public static bool IsLineInsectSegment2(Vector2 line1, Vector2 line2, Vector2 seg1, Vector2 seg2, ref GeoInsectPointInfo insect) { Vector3 line11 = new Vector3(line1.x, line1.y, 0.0f); Vector3 line21 = new Vector3(line2.x, line2.y, 0.0f); Vector3 seg11 = new Vector3(seg1.x, seg1.y, 0.0f); Vector3 seg21 = new Vector3(seg2.x, seg2.y, 0.0f); return(IsLineInsectSegment3(line11, line21, seg11, seg21, ref insect)); }
public static bool IsLineInsectSegment3(Vector3 line1, Vector3 line2, Vector3 seg1, Vector3 seg2, ref GeoInsectPointInfo insect) { Vector3 closest1, closest2; bool issect = GeoUtils.LineSegmentClosestPoint(line1, line2, seg1, seg2, out closest1, out closest2); if (issect) { Vector3 t = closest1 - closest2; if (t.magnitude < 1e-5f) { insect.mHitGlobalPoint = closest1; insect.mIsIntersect = true; return(true); } } insect.mIsIntersect = false; return(false); }
// 线段 相交 和 重叠 分开 计算 (线段重叠 不认为 相交) public static bool IsSegmentInsectSegment2(Vector2 seg1, Vector2 seg2, Vector2 seg3, Vector2 seg4, ref GeoInsectPointInfo insect) { Vector3 seg11 = GeoUtils.ToVector2(seg1); Vector3 seg21 = GeoUtils.ToVector2(seg2); Vector3 seg31 = GeoUtils.ToVector2(seg3); Vector3 seg41 = GeoUtils.ToVector2(seg4); return(IsSegmentInsectSegment3(seg11, seg21, seg31, seg41, ref insect)); }
public static bool IsLineInsectTriangle3(Vector3 line1, Vector3 line2, Vector3 p1, Vector3 p2, Vector3 p3, ref GeoInsectPointInfo insect) { // 376 计算几何 Vector3 d = line2 - line1; Vector3 line1p1 = line1 - p1; Vector3 v2v1 = p2 - p1; Vector3 v3v1 = p3 - p1; Vector3 normal = Vector3.Cross(v2v1, v3v1); float dot = Vector3.Dot(normal, d.normalized); if (dot < 1e-5f && dot > -1e-5f) { // 平行或 共面 dot = Vector3.Dot(normal, line1p1); if (dot < 1e-5f && dot > -1e-5f) { // 共面 此处应该转化为 线与线段 相交 // 暂时处理为 false return(false); } else { // 平行 return(false); } } //Vector3 d31 = Vector3.Cross(d, v3v1); //float d31v2v1 = Vector3.Dot(d31, v2v1); float t = Vector3.Dot(Vector3.Cross(line1p1, v2v1), v3v1); float u = Vector3.Dot(Vector3.Cross(d, v3v1), line1p1); float v = Vector3.Dot(Vector3.Cross(line1p1, v2v1), d); if (u >= 0 && u <= 1 && v >= 0 && v <= 1 && (u + v) <= 1) { insect.mIsIntersect = true; insect.mHitGlobalPoint = line1p1 + t * d; return(true); } return(false); }
public static bool IsTriangleInsectRay3(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 rayOrigin, Vector3 rayDirection, ref GeoInsectPointInfo insect) { return(GeoRayUtils.IsRayInsectTriangle3(rayOrigin, rayDirection, p1, p2, p3, 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 IsSegmentInsectSegment3(Vector3 seg1, Vector3 seg2, Vector3 seg3, Vector3 seg4, ref GeoInsectPointInfo insect) { Vector3 close1, close2; bool isinsect = GeoUtils.SegmentSegmentClosestPoint(seg1, seg2, seg3, seg4, out close1, out close2); if (isinsect) { Vector3 t = close1 - close2; if (t.magnitude < 1e-5f) { insect.mIsIntersect = true; insect.mHitGlobalPoint = close1; return(true); } } insect.mIsIntersect = false; return(false); }
// 线 public static bool IsLineInsectLine2(Vector2 line1, Vector2 line2, Vector2 line3, Vector2 line4, ref GeoInsectPointInfo insect) { Vector3 line11 = new Vector3(line1.x, line1.y, 0.0f); Vector3 line12 = new Vector3(line2.x, line2.y, 0.0f); Vector3 line21 = new Vector3(line3.x, line3.y, 0.0f); Vector3 line22 = new Vector3(line4.x, line4.y, 0.0f); return(IsLineInsectLine3(line11, line12, line21, line22, ref insect)); }
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 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 bool IsRayInsectSegment2(Vector2 rayOrigin, Vector2 rayDirection, Vector2 seg1, Vector2 seg2, ref GeoInsectPointInfo insect) { return(GeoSegmentUtils.IsSegmentInsectRay2(seg1, seg2, rayOrigin, rayDirection, ref insect)); }
public static bool IsRayInsectRay3(Vector3 rayOrigin1, Vector3 rayDirection1, Vector3 rayOrigin2, Vector3 rayDirection2, ref GeoInsectPointInfo insect) { Vector3 close1, close2; bool isinsect = GeoUtils.RayRayClosestPoint(rayOrigin1, rayDirection1, rayOrigin2, rayDirection2, out close1, out close2); if (isinsect) { Vector3 t = close1 - close2; if (t.magnitude < 1e-5f) { insect.mIsIntersect = true; insect.mHitGlobalPoint = close1; return(true); } } return(false); }
public static bool IsRayInsectRay2(Vector2 rayOrigin1, Vector2 rayDirection1, Vector2 rayOrigin2, Vector2 rayDirection2, ref GeoInsectPointInfo insect) { Vector3 rayOrigin11 = GeoUtils.ToVector2(rayOrigin1); Vector3 rayDirection11 = GeoUtils.ToVector2(rayDirection1); Vector3 rayOrigin21 = GeoUtils.ToVector2(rayOrigin2); Vector3 rayDirection21 = GeoUtils.ToVector2(rayDirection2); return(IsRayInsectRay3(rayOrigin11, rayDirection11, rayOrigin21, rayDirection21, ref insect)); }
public static bool IsLineInsectRay2(Vector2 line1, Vector2 line2, Vector2 rayOrigin, Vector2 rayDirection, ref GeoInsectPointInfo insect) { Vector3 line11 = new Vector3(line1.x, line1.y, 0.0f); Vector3 line12 = new Vector3(line2.x, line2.y, 0.0f); Vector3 rayO = new Vector3(rayOrigin.x, rayOrigin.y, 0.0f); Vector3 rayD = new Vector3(rayDirection.x, rayDirection.y, 0.0f); return(IsLineInsectRay3(line11, line12, rayO, rayD, 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 IsLineInsectRay3(Vector3 line1, Vector3 line2, Vector3 rayOrigin, Vector3 rayDirection, ref GeoInsectPointInfo insect) { Vector3 close1, close2; bool issect = GeoUtils.RayLineClosestPoint(rayOrigin, rayDirection, line1, line2, out close1, out close2); if (issect) { Vector3 t = close1 - close2; if (t.magnitude < 1e-5f) { insect.mHitGlobalPoint = close1; insect.mIsIntersect = true; return(true); } } insect.mIsIntersect = false; return(false); }
public static bool IsSegmentInsectRay2(Vector2 seg1, Vector2 seg2, Vector2 rayOrigin, Vector2 rayDirection, ref GeoInsectPointInfo insect) { Vector3 seg11 = GeoUtils.ToVector2(seg1); Vector3 seg21 = GeoUtils.ToVector2(seg2); Vector3 rayOrigin1 = GeoUtils.ToVector2(rayOrigin); Vector3 rayDirection1 = GeoUtils.ToVector2(rayDirection); return(IsSegmentInsectRay3(seg11, seg21, rayOrigin1, rayDirection1, ref insect)); }
public static bool IsTriangleInsectRay2(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 rayOrigin, Vector2 rayDirection, ref GeoInsectPointInfo insect) { return(GeoRayUtils.IsRayInsectLine2(rayOrigin, rayDirection, rayOrigin, rayDirection, ref insect)); }
public static bool IsSegmentInsectRay3(Vector3 seg1, Vector3 seg2, Vector3 rayOrigin, Vector3 rayDirection, ref GeoInsectPointInfo insect) { Vector3 close1, close2; bool isinsect = GeoUtils.RaySegmentClosestPoint(rayOrigin, rayDirection, seg1, seg2, out close1, out close2); if (isinsect) { Vector3 t = close1 - close2; if (t.magnitude < 1e-5f) { insect.mIsIntersect = true; insect.mHitGlobalPoint = close1; insect.mLength = (rayOrigin - close1).magnitude; } } return(insect.mIsIntersect); }
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 IsRayInsectTriangle3(Vector3 rayOrigin, Vector3 rayDirection, Vector3 p1, Vector3 p2, Vector3 p3, ref GeoInsectPointInfo insect) { // 376 计算几何 Vector3 d = rayDirection; Vector3 line1p1 = rayOrigin - p1; Vector3 v2v1 = p2 - p1; Vector3 v3v1 = p3 - p1; Vector3 normal = Vector3.Cross(v2v1, v3v1); float dot = Vector3.Dot(normal, d.normalized); if (dot < 1e-5f && dot > -1e-5f) { // 平行或 共面 dot = Vector3.Dot(normal, line1p1); if (dot < 1e-5f && dot > -1e-5f) { // 共面 此处应该转化为 线与线段 相交 // 暂时处理为 false return(false); } else { // 平行 return(false); } } Vector3 d31 = Vector3.Cross(d, v3v1); float d31v2v1 = Vector3.Dot(d31, v2v1); float tmp = 1.0f / d31v2v1; float t = Vector3.Dot(Vector3.Cross(line1p1, v2v1), v3v1) * tmp; float u = Vector3.Dot(Vector3.Cross(d, v3v1), line1p1) * tmp; float v = Vector3.Dot(Vector3.Cross(line1p1, v2v1), d) * tmp; if (u >= 0 && u <= 1 && v >= 0 && v <= 1 && (u + v) <= 1 && t > 0) { insect.mIsIntersect = true; insect.mHitGlobalPoint = rayOrigin + t * d; return(true); } return(false); }