/// <summary> /// Calculate the intersection point between the segment and line. /// </summary> /// <param name="sEq">The segment equation.</param> /// <param name="lEq">The line equation.</param> /// <returns>Returns the intersection point.</returns> public static Point GetIntersection(SegmentEquation sEq, LinearEquation lEq) { var pt = LinearEquation.GetIntersection(sEq, lEq); if (sEq.IsPointInRange(pt)) { return(pt); } return(null); }
/// <summary> /// Calculate the intersection point between the 2 segments. /// </summary> /// <param name="eq1">The first segment equation.</param> /// <param name="eq2">The second segment equation.</param> /// <returns>Returns the intersection point.</returns> public static Point GetIntersection(SegmentEquation eq1, SegmentEquation eq2) { var pt = LinearEquation.GetIntersection(eq1, eq2); if (eq1.IsPointInRange(pt) && eq2.IsPointInRange(pt)) { return(pt); } return(null); }
/// <summary> /// Calculate the intersection points when a line across many segments (Special). /// </summary> /// <param name="sEqs">The segment equations.</param> /// <param name="lEq">The line equation.</param> /// <returns>Returns the intersection points.</returns> public static List <Point> GetIntersectionSp(IEnumerable <SegmentEquation> sEqs, LinearEquation lEq) { var pts = new List <Point>(); foreach (var sEq in sEqs) { var pt = SegmentEquation.GetIntersectionSp(sEq, lEq); if (null != pt && sEq.IsPointInRange(pt)) { pts.Add(pt); } } return(pts); }
/// <summary> /// Calculate the intersection point between the segment and line (Special). /// </summary> /// <param name="sEq">The segment equation.</param> /// <param name="lEq">The line equation.</param> /// <returns>Returns the intersection points.</returns> public static Point GetIntersectionSp(SegmentEquation sEq, LinearEquation lEq) { var pt = SegmentEquation.GetIntersection(sEq, lEq); if (pt == sEq.endpoint1) { if (pt.Y <= sEq.endpoint2.Y) { pt = null; } } else if (pt == sEq.endpoint2) { if (pt.Y <= sEq.endpoint1.Y) { pt = null; } } return(pt); }
/// <summary> /// Judge wether the specified point lies within the interior or on the boundary of the specified polygon. /// </summary> /// <param name="pt">The specified point.</param> /// <returns>Return true if the specified point intersects the polygon, otherwise false.</returns> public bool IsIntersects(Point pt) { var line = new LinearEquation(pt, LinearType.ParallelXAxis); var pts = SegmentEquation.GetIntersectionSp(this.sides, line); int counter = 0; foreach (var point in pts) { if (point == pt) { return(true); } else { if (point.X < pt.X) { counter++; } } } return(counter % 2 == 1); }
/// <summary> /// Calculate the intersection point between the segment and line (Special). /// </summary> /// <param name="sEq">The segment equation.</param> /// <param name="lEq">The line equation.</param> /// <returns>Returns the intersection points.</returns> public static Point GetIntersectionSp(SegmentEquation sEq, LinearEquation lEq) { var pt = SegmentEquation.GetIntersection(sEq, lEq); if (pt == sEq.endpoint1) { if (pt.Y <= sEq.endpoint2.Y) { pt = null; } } else if (pt == sEq.endpoint2) { if (pt.Y <= sEq.endpoint1.Y) { pt = null; } } return pt; }
/// <summary> /// Calculate the intersection point between the segment and line. /// </summary> /// <param name="sEq">The segment equation.</param> /// <param name="lEq">The line equation.</param> /// <returns>Returns the intersection point.</returns> public static Point GetIntersection(SegmentEquation sEq, LinearEquation lEq) { var pt = LinearEquation.GetIntersection(sEq, lEq); if (sEq.IsPointInRange(pt)) { return pt; } return null; }
/// <summary> /// Calculate the intersection point between the 2 segments. /// </summary> /// <param name="eq1">The first segment equation.</param> /// <param name="eq2">The second segment equation.</param> /// <returns>Returns the intersection point.</returns> public static Point GetIntersection(SegmentEquation eq1, SegmentEquation eq2) { var pt = LinearEquation.GetIntersection(eq1, eq2); if (eq1.IsPointInRange(pt) && eq2.IsPointInRange(pt)) { return pt; } return null; }
/// <summary> /// Get the length of the line. /// </summary> /// <param name="propName">The property name indicates the line.</param> /// <param name="entity">An entity in the service.</param> /// <returns>Return the length of the line.</returns> private double GetLength(string propName, JObject entity) { var propVal = entity[propName]["coordinates"] as JArray; var pts = new List<Point>(); for (int i = 0; i < propVal.Count - 1; i += 2) { var pt = new Point(Convert.ToDouble(propVal[i]), Convert.ToDouble(propVal[i + 1])); pts.Add(pt); } var segs = new List<SegmentEquation>(); for (int i = 0; i < pts.Count - 1; i++) { var seg = new SegmentEquation(pts[i], pts[i + 1]); segs.Add(seg); } double len = 0.0; foreach (var seg in segs) { len += seg.Length; } return len; }