public SkeletonLineSegment ConnectPoint2Line2(Vector2 p, SkeletonLineSegment l) { var d = SqrMagnitude(l.V); //assert d != 0; var u = ((p.X - l.P.X) * l.V.X + (p.Y - l.P.Y) * l.V.Y) / d; if (l._u_in(u)) { u = (float)Math.Max(Math.Min(u, 1.0), 0.0); } return(new SkeletonLineSegment(P, l.P + u * l.V)); }
public Vector2 Intersect(SkeletonLineSegment other, bool rayline = false) { var d = Helpers.MathHelper.Cross(other.V, this.V); if (d == 0) { return(Vector2.Zero); } var d2 = other.P - this.P; var ua = Helpers.MathHelper.Cross(this.V, d2) / d; if (rayline) { if (!other._u_in(ua)) { return(Vector2.Zero); } } var ub = Helpers.MathHelper.Cross(other.V, d2) / d; return(other.P + ua * other.V); }