private PointInfo FindCrossPointOnWholePath(Vector3 vx, Vector3 vx1, Vector3 vx2, List <int> excludesIndex = null) { PointInfo info = null; for (int i = 0; i < movePoints.Length - 1; i++) { if (null != excludesIndex && excludesIndex.Contains(i)) { continue; } Vector3 p1 = movePoints[i]; Vector3 p2 = movePoints [i + 1]; Vector3 pInter = Vector3.zero; bool cross = Vector2DUtils.LineLineIntersection(out pInter, p1, p2 - p1, vx, vx1 - vx); if (!cross) { cross = Vector2DUtils.LineLineIntersection(out pInter, p1, p2 - p1, vx, vx2 - vx); } if (!cross) { continue; } if (0 != Vector2DUtils.PointOnWhichSideOfLineSegment(p1, p2, pInter)) { continue; } info = new PointInfo(); info.position = pInter; info.startIndex = i; break; } return(info); }
public static void LineLineIntersection() { Vector3 pInter = Vector3.zero; Vector3 p1 = new Vector3(0, 0); Vector3 p2 = new Vector3(10, 10); Vector3 vx = new Vector3(p1.x, 10); Vector3 vx1 = new Vector3(p1.x, -10); DebugUtils.DrawPoint(p1); DebugUtils.DrawPoint(p2); Debug.DrawLine(p1, p2); Debug.DrawLine(vx, vx1); // DebugUtils.DrawPoint (vx); // DebugUtils.DrawPoint (vx1); bool cross = Vector2DUtils.LineLineIntersection(out pInter, p1, p2, vx, vx1); if (cross) { Log.Debug("has {0}", pInter); Debug.DrawLine(Vector3.zero, pInter); } else { Log.Debug("null....."); } }