Exemplo n.º 1
0
        /// <summary>
        /// Computes the y-values of intersection points with a vertical line. If the line does
        /// not intersect the stadium, then both output x-values are set to float.NaN.
        /// </summary>
        public void VLineIntersection(float xValue, out float miny, out float maxy)
        {
            List <float> yList = new List <float>(6);

            float y1, y2;

            // Check the first circle for intersections
            (new Circle2D(m_p1, m_r)).VLineIntersection(xValue, out y1, out y2);
            if (!float.IsNaN(y1) && !float.IsNaN(y2))
            {
                // Add intersections to the list
                yList.Add(y1);
                yList.Add(y2);
            }

            // Now check the second circle
            (new Circle2D(m_p2, m_r)).VLineIntersection(xValue, out y1, out y2);
            if (!float.IsNaN(y1) && !float.IsNaN(y2))
            {
                // Add intersections to the list
                yList.Add(y1);
                yList.Add(y2);
            }

            // Now check the first line segment edge
            Vector2D perp = Vector2D.Normalize(m_p2 - m_p1).GetPerpendicular();
            Vector2D pt   = new Vector2D();

            if ((new LineSegment2D(m_p1 + (perp * m_r), m_p2 + (perp * m_r))).GetPointWithXValue(xValue, ref pt))
            {
                yList.Add(pt.Y);
            }

            // Build the second edge and see if we intersect that too
            if ((new LineSegment2D(m_p1 - (perp * m_r), m_p2 - (perp * m_r))).GetPointWithXValue(xValue, ref pt))
            {
                yList.Add(pt.Y);
            }

            // If we don't have at least 2 values in the list then we have no intersection
            if (yList.Count < 2)
            {
                miny = float.NaN;
                maxy = float.NaN;
                return;
            }

            // Sort the list of intersections so that the first item in the list will be the minimum and the last
            // item will be the maximum.
            yList.Sort();

            // Set intersection x-values
            miny = yList[0];
            maxy = yList[yList.Count - 1];
        }
Exemplo n.º 2
0
        /// <summary>
        /// Computes the x-values of intersection points with a horizontal line. If the line does
        /// not intersect the stadium, then both output x-values are set to float.NaN.
        /// </summary>
        public void HLineIntersection(float yValue, out float minx, out float maxx)
        {
            List <float> xList = new List <float>(6);

            float x1, x2;

            (new Circle2D(m_p1, m_r)).HLineIntersection(yValue, out x1, out x2);
            if (!float.IsNaN(x1) && !float.IsNaN(x2))
            {
                // Add intersections to the list
                xList.Add(x1);
                xList.Add(x2);
            }

            // Now check the second circle
            (new Circle2D(m_p2, m_r)).HLineIntersection(yValue, out x1, out x2);
            if (!float.IsNaN(x1) && !float.IsNaN(x2))
            {
                // Add intersections to the list
                xList.Add(x1);
                xList.Add(x2);
            }

            // Now check the first line segment edge
            Vector2D perp = Vector2D.Normalize(m_p2 - m_p1).GetPerpendicular();
            Vector2D pt   = new Vector2D();

            if ((new LineSegment2D(m_p1 + (perp * m_r), m_p2 + (perp * m_r))).GetPointWithYValue(yValue, ref pt))
            {
                xList.Add(pt.X);
            }

            // Build the second edge and see if we intersect that too
            if ((new LineSegment2D(m_p1 - (perp * m_r), m_p2 - (perp * m_r))).GetPointWithYValue(yValue, ref pt))
            {
                xList.Add(pt.X);
            }

            // If we don't have at least 2 values in the list then we have no intersection
            if (xList.Count < 2)
            {
                minx = float.NaN;
                maxx = float.NaN;
                return;
            }

            // Sort the list of intersections so that the first item in the list will be the minimum and the last
            // item will be the maximum.
            xList.Sort();

            // Set intersection x-values
            minx = xList[0];
            maxx = xList[xList.Count - 1];
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs the line from general-form equation coefficients. The line will be normalized
        /// internally.
        /// </summary>
        /// <param name="a">"A" value in the equation Ax+By+C=0</param>
        /// <param name="b">"B" value in the equation Ax+By+C=0</param>
        /// <param name="c">"C" value in the equation Ax+By+C=0</param>
        public NormalizedGeneralLine2D(float a, float b, float c)
        {
            Vector2D norm = new Vector2D(a, b);

            c /= norm.Length;
            norm.Normalize();

            m_a = norm.X;
            m_b = norm.Y;
            m_c = c;
        }
Exemplo n.º 4
0
 public Vector2D GetUnitNormal()
 {
     return(Vector2D.Normalize(new EOFC.Vector2D(m_p1.Y - m_p2.Y, m_p2.X - m_p1.X)));
 }