/// <summary> /// Checks whether the specified circle intersects the passed line. /// </summary> /// <param name="circle"> /// Circle to check. /// </param> /// <param name="line"> /// Line to check. /// </param> /// <param name="first"> /// First intersection point, if found. /// </param> /// <param name="second"> /// Second intersection point, if found. /// </param> /// <returns> /// <c>true</c>, if circle and line intersect each other, and <c>false</c> otherwise. /// </returns> public static bool Intersects( this CircleF circle, LineSegment2F line, out Vector2F?first, out Vector2F?second) { return(line.Intersects(circle, out first, out second)); }
/// <summary> /// Checks whether this polygon fully contains the passed line segment. /// </summary> /// <param name="lineSegment">Line segment to check.</param> /// <returns> /// <c>true</c>, if this polygon fully contains <paramref name="lineSegment" />, and /// <c>false</c> otherwise. /// </returns> public bool Contains(LineSegment2F lineSegment) { // Check whether any of the edges intersect with the line. if (this.Edges.Any(edge => lineSegment.Intersects(edge))) { return(false); } // Check whether the line endpoints are inside the polygon. return(this.Contains(lineSegment.P) && this.Contains(lineSegment.Q)); }
/// <summary> /// Checks whether the specified rectangle intersects the passed circle. /// </summary> /// <param name="rectangle"> /// Rectangle to check. /// </param> /// <param name="circle"> /// Circle to check. /// </param> /// <returns> /// <c>true</c>, if rectangle and circle intersect each other, and <c>false</c> otherwise. /// </returns> public static bool Intersects(this RectangleF rectangle, CircleF circle) { // Check if rectangle contains center. if (rectangle.Contains(circle.Center)) { return(true); } // Check each edge. var topLeft = new Vector2F(rectangle.X, rectangle.Y); var bottomLeft = new Vector2F(rectangle.X, rectangle.MaxY); var topRight = new Vector2F(rectangle.MaxX, rectangle.Y); var bottomRight = new Vector2F(rectangle.MaxX, rectangle.MaxY); var left = new LineSegment2F(topLeft, bottomLeft); var right = new LineSegment2F(topRight, bottomRight); var top = new LineSegment2F(topLeft, topRight); var bottom = new LineSegment2F(bottomLeft, bottomRight); return(left.Intersects(circle) || right.Intersects(circle) || top.Intersects(circle) || bottom.Intersects(circle)); }
/// <summary> /// Checks whether the specified circle intersects the passed line. /// </summary> /// <param name="circle"> /// Circle to check. /// </param> /// <param name="line"> /// Line to check. /// </param> /// <returns> /// <c>true</c>, if circle and line intersect each other, and <c>false</c> otherwise. /// </returns> public static bool Intersects(this CircleF circle, LineSegment2F line) { return(line.Intersects(circle)); }