コード例 #1
0
        /// <summary>
        /// Calculates the angle of the line segment in degrees
        /// </summary>
        /// <param name="segment"></param>
        /// <returns></returns>
        public static double CalculateAngle(this LineSegment2D segment)
        {
            double   angle;
            Vector2D wallUnitVector = segment.CalculateUnitVector();

            if (wallUnitVector.X == 0)
            {
                if (wallUnitVector.Y > 0)
                {
                    angle = 90;
                }
                else
                {
                    angle = -90;
                }
            }
            else
            {
                angle = Math.Atan(wallUnitVector.Y / wallUnitVector.X) * 180 / Math.PI;
            }

            return(angle);
        }