public override bool IsContaining(IPoint3D obj) { if (m_points.Count < 3) return false; Point2D p1, p2; bool inside = false; Point2D oldpt = new Point2D(m_points[m_points.Count - 1].X, m_points[m_points.Count - 1].Y); foreach (Point2D pt in m_points) { Point2D newpt = new Point2D(pt.X, pt.Y); if (newpt.X > oldpt.X) { p1 = oldpt; p2 = newpt; } else { p1 = newpt; p2 = oldpt; } if ((newpt.X < obj.X) == (obj.X <= oldpt.X) && (obj.Y - p1.Y) * (p2.X - p1.X) < (p2.Y - p1.Y) * (obj.X - p1.X)) inside = !inside; oldpt = newpt; } return inside; }
/// <summary> /// Get the point at the given heading and distance /// </summary> /// <param name="gameHeading">DOL Heading</param> /// <param name="distance">Distance to point</param> /// <returns>Point at the given heading and distance</returns> public Point2D GetPointFromHeading(ushort heading, int distance) { double angle = heading*HEADING_TO_RADIAN; double targetX = X - (Math.Sin(angle)*distance); double targetY = Y + (Math.Cos(angle)*distance); var point = new Point2D(); if (targetX > 0) point.X = (int) targetX; else point.X = 0; if (targetY > 0) point.Y = (int) targetY; else point.Y = 0; return point; }