Esempio n. 1
0
        /// <summary>
        /// computes orientation of three vectors with a common source
        /// (compare polar angles of v1 and v2 with respect to v0)
        /// </summary>
        /// <returns>
        ///  -1 if the orientation is v0 v1 v2
        ///   1 if the orientation is v0 v2 v1
        ///   0  if v1 and v2 are collinear and codirectinal
        /// </returns>
        static public int GetOrientationOf3Vectors(Point vector0, Point vector1, Point vector2)
        {
            const double multiplier = 1000; //TODO, need to fix it?

            vector0 *= multiplier;
            vector1 *= multiplier;
            vector2 *= multiplier;

            double xp2   = Point.CrossProduct(vector0, vector2);
            double dotp2 = vector0 * vector2;
            double xp1   = Point.CrossProduct(vector0, vector1);
            double dotp1 = vector0 * vector1;

            // v1 is collinear with v0
            if (ApproximateComparer.Close(xp1, 0.0) && ApproximateComparer.GreaterOrEqual(dotp1, 0.0))
            {
                if (ApproximateComparer.Close(xp2, 0.0) && ApproximateComparer.GreaterOrEqual(dotp2, 0.0))
                {
                    return(0);
                }
                return(1);
            }

            // v2 is collinear with v0
            if (ApproximateComparer.Close(xp2, 0.0) && ApproximateComparer.GreaterOrEqual(dotp2, 0.0))
            {
                return(-1);
            }

            if (ApproximateComparer.Close(xp1, 0.0) || ApproximateComparer.Close(xp2, 0.0) || xp1 * xp2 > 0.0)
            {
                // both on same side of v0, compare to each other
                return(ApproximateComparer.Compare(Point.CrossProduct(vector2, vector1), 0.0));
            }

            // vectors "less than" zero degrees are actually large, near 2 pi
            return(-ApproximateComparer.Compare(Math.Sign(xp1), 0.0));
        }
Esempio n. 2
0
 /// <summary>
 /// returns true if the rectangle contains the point
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public bool Contains(Point point)
 {
     return((ApproximateComparer.Compare(left, point.X) <= 0) && (ApproximateComparer.Compare(right, point.X) >= 0) &&
            (ApproximateComparer.Compare(top, point.Y) >= 0) && (ApproximateComparer.Compare(bottom, point.Y) <= 0));
 }