C#判断点和直线的位置关系

        /// <summary>
        /// 判断点和直线的位置关系
        /// </summary>
        /// <param name="LinePntA">直线上的一点</param>
        /// <param name="LinePntB">直线上的另一点</param>
        /// <param name="PntM">需要判断的点</param>
        /// <returns></returns>
        private int JudgePointToLine(Point3d LinePntA, Point3d LinePntB, Point3d PntM)
        {
            int nResult = 0;
            double ax = LinePntB.X - LinePntA.X;
            double ay = LinePntB.Y - LinePntA.Y;
            double bx = PntM.X - LinePntA.X;
            double by = PntM.Y - LinePntA.Y;
            double judge = ax * by - ay * bx;
            if (judge > 0)
            {
                nResult = 1;
            }
            else if (judge < 0)
            {
                nResult = -1;
            }
            else
            {
                nResult = 0;
            }
            return nResult;
        }

 

posted @ 2015-03-19 10:59  秋月的私语  阅读(2656)  评论(0编辑  收藏  举报