/// <summary> /// определить тип пересечения 2-ч отрезков /// </summary> /// <param name="xa">начало отрезка 1</param> /// <param name="ya">начало отрезка 1</param> /// <param name="xb">конец отрезка 1</param> /// <param name="yb">конец отрезка 1</param> /// <param name="xc">начало отрезка 2</param> /// <param name="yc">начало отрезка 2</param> /// <param name="xd">конец отрезка 2</param> /// <param name="yd">конец отрезка 2</param> /// <param name="tab">относительная координата пер-ия на 1 отрезке</param> /// <param name="tcd">относительная координата пер-ия на 2 отрезке</param> /// <returns></returns> public static IntersectType Cross(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd, ref double tab, ref double tcd) { IntersectType type = Intersect(xa, ya, xb, yb, xc, yc, xd, yd, ref tab); if (type == IntersectType.PARALLEL || type == IntersectType.COLLINEAR) { return(type); } if (tab < 0 || tab > 1) { return(IntersectType.SKEW_NO_CROSS); } Intersect(xc, yc, xd, yd, xa, ya, xb, yb, ref tcd); if (tcd < 0 || tcd > 1) { return(IntersectType.SKEW_NO_CROSS); } return(IntersectType.SKEW_CROSS); }
public LineSegmentCircleIntersect(LineSegment segment, Vector3 circleCenter, float circleRadius) { Vector3 a = segment.A; Vector3 b = segment.B; Vector3 c = circleCenter; // Compute a normal perpendicular to the line and pointing to the point Vector3 up = Vector3.Cross(segment.A - circleCenter, segment.A - segment.B); // This points up from the line Vector3 normal = Vector3.Cross(up, segment.A - segment.B); float distanceToLine = 0.0f; if (normal.Length > 0.0f) { distanceToLine = Math.Abs(new Plane(normal, segment.A).Distance(circleCenter)); } if (distanceToLine >= circleRadius) { intersectType = IntersectType.None; return; } if (distanceToLine == float.NaN) { } float along = (float)Math.Sqrt(Math.Pow(circleRadius, 2) - Math.Pow(distanceToLine, 2)); Plane plane = new Plane(b - a, a); float toA = 0.0f; float toB = plane.Distance(b); float toC = plane.Distance(c); float toP1 = toC - along; float toP2 = toC + along; if (toP2 < toA || toP1 > toB) { intersectType = IntersectType.None; return; } if (toP1 > toA) { beginNoIntersect = new LineSegment(a, a + toA * plane.Normal); } if (toP2 < toB) { endNoIntersect = new LineSegment(a + toP2 * plane.Normal, a + toB * plane.Normal); } toP1 = Math.Min(Math.Max(toP1, toA), toB); toP2 = Math.Min(Math.Max(toP2, toA), toB); intersectType = IntersectType.Segment; intersectSegment = new LineSegment(a + plane.Normal * toP1, a + plane.Normal * toP2); }
public static bool Intersects(this BoundingBox boxA, BoundingBox boxB, IntersectType intersectType = IntersectType.AxisAligned) { switch (intersectType) { case IntersectType.AxisAligned: return(AxisAligned(boxA, boxB)); case IntersectType.SquareIntersect: return(SquareIntersect(boxA, boxB)); default: return(false); } }
protected void Page_Load(object sender, EventArgs e) { try { if (Request.QueryString["typeID"] != null) { Byte[] bytes = new IntersectType().LoadPhoto(int.Parse(Request.QueryString["typeID"])); Response.Buffer = true; Response.Charset = ""; Response.ContentType = @"image/gif"; Response.BinaryWrite(bytes); Response.Flush(); Response.End(); } } catch (Exception) { } }