protected override IEdge Generate() { for (int i = 0; i < a.Resolution; i++) { IEdge ea = a.GetEdge(i); for (int j = 0; j < b.Resolution; j++) { IEdge eb = b.GetEdge(j); if (ea.CompareLine(eb) && Vector3.Dot(ea.Direction(), eb.Direction()) < 0) { return(ea.GetIntersecting(eb)); } } } throw new IEdgeSplitException("Failed to find intersection.", a, b); }
public static IEdge[] RemoveIntersecting(this IEdge a, IEdge b) { IEdge[] output = new IEdge[2]; Vector3 direction = a.Direction(); Vector3[] points = new Vector3[] { a.A, a.B, b.A, b.B }; float[] keys = new float[] { 0f, Vector3.Dot(a.A - a.B, direction), Vector3.Dot(a.A - b.A, direction), Vector3.Dot(a.A - b.B, direction) }; System.Array.Sort(keys, points); if ((points[1] - points[0]).sqrMagnitude > 0.0001f * 0.0001f) { output[0] = a.Clone(points[0], points[1]); } if ((points[3] - points[2]).sqrMagnitude > 0.0001f * 0.0001f) { output[1] = a.Clone(points[3], points[2]); } return(output); }
public static bool HasIntersection(IPoly a, IPoly b) { //This logic is just wrong //Needs to be recoded throw new NotImplementedException(); for (int i = 0; i < a.Resolution; i++) { IEdge ea = a.GetEdge(i); for (int j = 0; j < b.Resolution; j++) { IEdge eb = b.GetEdge(j); if (ea.CompareLine(eb) && Vector3.Dot(ea.Direction(), eb.Direction()) < 0) { return(ea.GetIntersecting(eb) != null); } } } return(false); }
public static IEdge GetIntersecting(this IEdge a, IEdge b) { float aa = 0f; Vector3 direction = a.Direction().normalized; float ab = Vector3.Dot(a.B - a.A, direction); float ba = Vector3.Dot(direction, b.A - a.A); float bb = Vector3.Dot(direction, b.B - a.A); if (ba > ab && bb > ab) { return(null); } if (ba < 0 && bb < 0) { return(null); } float[] keys = new float[] { aa, ab, ba, bb }; System.Array.Sort(keys); return(new Edge(a.A + direction * keys[1], a.A + direction * keys[2])); }
public static bool CompareLine(this IEdge edge, IEdge other) { Vector3 a = edge.Direction().normalized; Vector3 b = other.Direction().normalized; float dot = Vector3.Dot(a, b); if (Mathf.Abs(dot) > 0.99f) { Vector3 offset = edge.A - Math3d.LinePlaneIntersection(other.A, b, edge.A, a); if (offset.sqrMagnitude < 0.0001f * 0.0001f) { return(true); } else { return(false); } } else { return(false); } }
public static float Length(this IEdge edge) { return(edge.Direction().magnitude); }
public static bool IsParallel(IEdge a, IEdge b, float threshold = 0.9999f) { float dot = Vector3.Dot(a.Direction().normalized, b.Direction().normalized); return(dot > threshold); }