/// <summary> /// /// </summary> /// <param name="u"></param> /// <param name="v"></param> /// <param name="w"></param> /// <param name="tu"></param> /// <param name="tv"></param> private static bool LineLineIntersection(Vector2d u, Vector2d v, Vector2d w, out double tu, out double tv) { // impl ref // https://www.codeproject.com/Tips/862988/Find-the-Intersection-Point-of-Two-Line-Segments var c = Vector2d.Cross(u, v); if (Math.Abs(c) > 0.0) { c = 1.0 / c; tu = Vector2d.Cross(w, v) * c; tv = Vector2d.Cross(w, u) * c; return(true); } // lines are parallel, no solution tu = tv = 0.0; return(false); }
/// <summary> /// /// </summary> /// <param name="points"></param> /// <returns></returns> public static double GetPolygonArea(IEnumerable <Vector2d> points) { var itr = points.GetEnumerator(); itr.MoveNext(); var first = itr.Current; var p0 = first; var sum = 0.0; while (itr.MoveNext()) { var p1 = itr.Current; sum += Vector2d.Cross(p0, p1); p0 = p1; } sum += Vector2d.Cross(p0, first); return(sum * 0.5); }