Exemplo n.º 1
0
        //#endfor instanced to 'Vector2f'

        #endregion

        #region Private Members

        //#foreach instanced to 'Vector2d'


        /// <summary>
        /// Returns true, if p0 is upper point, p1, p2 are lower, false otherwise.
        /// </summary>
        static bool CalcPathIntersection(Vector2d a, Vector2d b, Vector2d c, double width,
                                         out Vector2d p0, out Vector2d p1, out Vector2d p2)
        {
            // We first generate two vectors.
            Vector2d dir1 = b - a;
            Vector2d dir2 = c - b;

            // We generate two perpendicular vectors.
            Vector2d grad1 = new Vector2d(-dir1.Y, dir1.X).Normal;
            Vector2d grad2 = new Vector2d(-dir2.Y, dir2.X).Normal;

            // We now generate 4 line segments.
            LineSegment2d seg1Up   = new LineSegment2d(a + grad1 * width, b + grad1 * width);
            LineSegment2d seg1Down = new LineSegment2d(a - grad1 * width, b - grad1 * width);
            LineSegment2d seg2Up   = new LineSegment2d(b + grad2 * width, c + grad2 * width);
            LineSegment2d seg2Down = new LineSegment2d(b - grad2 * width, c - grad2 * width);


            // We calculate intersections.
            double t1, t2;

            if (Intersection.Intersect(seg1Up, seg2Up, out t1, out t2))
            {
                // If they intersect, we have point 0.
                p0 = seg1Up.Sample(t1);

                p1 = seg1Down.B;
                p2 = seg2Down.A;

                return(true);
            }
            else if (Intersection.Intersect(seg1Down, seg2Down, out t1, out t2))
            {
                p0 = seg1Down.Sample(t1);

                p1 = seg1Up.B;
                p2 = seg2Up.A;

                return(false);
            }
            else
            {
                // If result is this, we have no intersections, numeric error. We use variables of one.
                p0 = seg1Up.B;

                p1 = p2 = seg1Down.B;

                return(true);
            }
        }