/// <summary> /// Computes an intersection of the line and the segment /// </summary> public static bool LineSegment(Line2 line, Segment2 segment, out IntersectionLineSegment2 intersection) { return(LineSegment(line.origin, line.direction, segment.a, segment.b, out intersection)); }
/// <summary> /// Computes an intersection of the ray and the segment /// </summary> public static bool RaySegment(Ray2D ray, Segment2 segment, out IntersectionRaySegment2 intersection) { return(RaySegment(ray.origin, ray.direction, segment.a, segment.b, out intersection)); }
public static void DrawSegment(Segment2 segment, Color color, float duration, bool depthTest) { Debug.DrawLine((Vector3)segment.a, (Vector3)segment.b, color, duration, depthTest); }
/// <summary> /// Tests if the point lies on the segment /// </summary> /// <param name="side"> /// -1 if the point is to the left of the segment, /// 0 if it is on the line, /// 1 if it is to the right of the segment /// </param> public static bool PointSegment(Vector2 point, Segment2 segment, out int side) { return(PointSegment(point, segment.a, segment.b, out side)); }
public static bool SegmentToSegment(float start0x, float start0y, float end0x, float end0y, float start1x, float start1y, float end1x, float end1y, out Segment2 intersection, bool testBoundingBox = false) { return(SegmentToSegmentE(start0x, start0y, end0x, end0y, start1x, start1y, end1x, end1y, out intersection, testBoundingBox) != IntersectionType.None); }
public static IntersectionType SegmentToSegmentE(Segment2 segment0, Segment2 segment1, out Segment2 intersection, bool testBoundingBox = false) { return(SegmentToSegmentE(segment0.a, segment0.b, segment1.a, segment1.b, out intersection, testBoundingBox)); }
/// <summary> /// Draws a segment /// </summary> public static void DrawSegment2(Segment2 segment) { Draw.Segment2(drawLine, segment); }
public static bool SegmentToPoint(Segment2 segment, Vertex2 point) { return(SegmentToPoint(segment.a, segment.b, point)); }
public Segment2(Segment2 segment) { a = segment.a; b = segment.b; }
public bool Intersects(Segment2 segment, out Segment2 intersection, bool testBoundingBox = false) { return(Intersection.SegmentToSegment(this, segment, out intersection, testBoundingBox)); }
public static void DrawSegment(Segment2 segment, Color color, float duration) { DrawSegment(segment, color, duration, true); }
public static void DrawSegment(Segment2 segment, Color color) { DrawSegment(segment, color, 0f, true); }
public static void DrawSegment(Segment2 segment) { DrawSegment(segment, Color.white, 0f, true); }
/// <summary> /// Computes an intersection of the segments /// </summary> public static bool SegmentSegment(Segment2 segment1, Segment2 segment2, out IntersectionSegmentSegment2 intersection) { return(SegmentSegment(segment1.a, segment1.b, segment2.a, segment2.b, out intersection)); }
public static float LineSegmentToLineSegment(Segment2 S1, Segment2 S2) { Vertex2 u = S1.b - S1.a; Vertex2 v = S2.b - S2.a; Vertex2 w = S1.a - S2.a; float a = Vertex2.Dot(u, u); // always >= 0 float b = Vertex2.Dot(u, v); float c = Vertex2.Dot(v, v); // always >= 0 float d = Vertex2.Dot(u, w); float e = Vertex2.Dot(v, w); float D = a * c - b * b; // always >= 0 float sN, sD = D; // sc = sN / sD, default sD = D >= 0 float tN, tD = D; // tc = tN / tD, default tD = D >= 0 // compute the line parameters of the two closest points if (D < Mathf.Epsilon) { // the lines are almost parallel sN = 0; // force using point P0 on segment S1 sD = 1; // to prevent possible division by 0.0 later tN = e; tD = c; } else { // get the closest points on the infinite lines sN = (b * e - c * d); tN = (a * e - b * d); if (sN < 0) { // sc < 0 => the s=0 edge is visible sN = 0; tN = e; tD = c; } else if (sN > sD) { // sc > 1 => the s=1 edge is visible sN = sD; tN = e + b; tD = c; } } if (tN < 0) { // tc < 0 => the t=0 edge is visible tN = 0; // recompute sc for this edge if (-d < 0) { sN = 0; } else if (-d > a) { sN = sD; } else { sN = -d; sD = a; } } else if (tN > tD) { // tc > 1 => the t=1 edge is visible tN = tD; // recompute sc for this edge if ((-d + b) < 0) { sN = 0; } else if ((-d + b) > a) { sN = sD; } else { sN = (-d + b); sD = a; } } // finally do the division to get sc and tc float sc = (Mathf.Abs(sN) < Mathf.Epsilon ? 0 : sN / sD); float tc = (Mathf.Abs(tN) < Mathf.Epsilon ? 0 : tN / tD); // get the difference of the two closest points Vertex2 dP = w + (sc * u) - (tc * v); // = S1(sc) - S2(tc) return(dP.magnitude); // return the closest distance }
/// <summary> /// Returns a random point on a segment /// </summary> public static Vector2 PointOnSegment(Segment2 segment) { return(PointOnSegment(segment.a, segment.b)); }
public static float PointToLine(Vertex2 point, Segment2 segment) { return(PointToLine(point, segment.a, segment.b)); }
public static bool SegmentToRay(Segment2 segment, Ray2D ray) { Vertex2 intersection; return(SegmentToRay(segment.a, segment.b, ray.origin, ray.origin + ray.direction, out intersection)); }
public bool Intersects(Segment2 segment) { return(Intersection.PolygonToSegment(this, segment)); }
public static bool SegmentToRay(Segment2 segment, Vertex2 rayStart, Vertex2 rayEnd) { Vertex2 intersection; return(SegmentToRay(segment.a, segment.b, rayStart, rayEnd, out intersection)); }
/// <summary> /// Tests if the point lies on the segment /// </summary> public static bool PointSegment(Vector2 point, Segment2 segment) { return(PointSegment(point, segment.a, segment.b)); }
public static IntersectionType SegmentToSegmentE(Vertex2 start0, Vertex2 end0, Vertex2 start1, Vertex2 end1, out Segment2 intersection, bool testBoundingBox = false) { return(SegmentToSegmentE(start0.x, start0.y, end0.x, end0.y, start1.x, start1.y, end1.x, end1.y, out intersection, testBoundingBox)); }
/// <summary> /// Draws a segment /// </summary> public static void DrawSegment2(Segment2 segment) { DrawLine((Vector3)segment.a, (Vector3)segment.b); }