Exemplo n.º 1
0
        /// <summary>
        /// 点がポリゴンの範囲にあるかどうか判断
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="frame"></param>
        /// <returns></returns>
        public static bool IsPointInFrame_Polygon(PointD pt, FrameD frame)
        {
            //////////////////////
            // 座標系
            //    ↑Y
            //    |
            //    |
            //    |
            //  (0,0)-----→X
            ///////////////////
            pt.X = pt.X - frame.X;
            pt.Y = pt.Y - frame.Y;

            pt.Rotate_Clockwise(frame.Angle);

            int  i, j;
            bool bRet = false;

            int    nvert = frame.PolygonArray.Length;
            double testx = pt.X;
            double testy = pt.Y;

            PointD[] arrayP = frame.PolygonArray;

            for (i = 0, j = nvert - 1; i < nvert; j = i++)
            {
                if (((arrayP[i].Y > testy) != (arrayP[j].Y > testy)) &&
                    (testx < (arrayP[j].X - arrayP[i].X) * (testy - arrayP[i].Y) / (arrayP[j].Y - arrayP[i].Y) + arrayP[i].X))
                {
                    bRet = !bRet;
                }
            }
            return(bRet);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 点が円形の範囲にあるかどうか判断
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="frame"></param>
        /// <returns></returns>
        public static bool IsPointInFrame_Ellipse(PointD pt, FrameD frame)
        {
            //////////////////////
            // 座標系
            //    ↑Y
            //    |
            //    |
            //    |
            //  (0,0)-----→X
            ///////////////////
            pt.X = pt.X - frame.X;
            pt.Y = pt.Y - frame.Y;

            pt.Rotate_Clockwise(frame.Angle);

            double radius;

            if (!ToolMath.EqualsDouble(frame.Width, frame.Height))
            {
                double dScale;
                if (frame.Width > frame.Height)
                {
                    dScale = frame.Width / frame.Height;
                    pt.Y   = dScale * pt.Y;
                    radius = frame.Width / 2;
                }
                else
                {
                    dScale = frame.Height / frame.Width;
                    pt.X   = dScale * pt.X;
                    radius = frame.Height / 2;
                }
            }
            else
            {
                radius = frame.Width / 2;
            }

            if (Math.Sqrt(pt.X * pt.X + pt.Y * pt.Y) < radius)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 点が矩形枠の範囲にあるかどうか判断
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="frame"></param>
        /// <returns></returns>
        public static bool IsPointInFrame_Rectangle(PointD pt, FrameD frame)
        {
            //////////////////////
            // 座標系
            //    ↑Y
            //    |
            //    |
            //    |
            //  (0,0)-----→X
            ///////////////////
            pt.X = pt.X - frame.X;
            pt.Y = pt.Y - frame.Y;

            pt.Rotate_Clockwise(frame.Angle);

            if (pt.X > -frame.Width / 2 && pt.X < frame.Width / 2 && pt.Y > -frame.Height / 2 && pt.Y < frame.Height / 2)
            {
                return(true);
            }
            return(false);
        }