首页  编辑  

计算两点间的角度

Tags: /C#/算法/   Date Created:

/// <summary>

///

/// </summary>

/// <param name="AOrigin"> </param>

/// <param name="APoint"> </param>

/// <param name="APoint"> </param>

/// <returns> </returns>

private double PointToAngle( Point AOrigin, Point APoint, double AEccentricity)

{

    if (APoint . X == AOrigin . X)

        if (APoint . Y > AOrigin . Y)

            return Math . PI * 0.5 ;

        else return Math . PI * 1.5 ;

    else if (APoint . Y == AOrigin . Y)

        if (APoint . X > AOrigin . X)

            return 0 ;

        else return Math . PI;

    else

   {

        double Result = Math . Atan((AOrigin . Y - APoint . Y) /

           (AOrigin . X - APoint . X) * AEccentricity);

        if ((APoint . X < AOrigin . X) && (APoint . Y > AOrigin . Y))

            return Result + Math . PI;

        else if ((APoint . X < AOrigin . X) && (APoint . Y < AOrigin . Y))

            return Result + Math . PI;

        else if ((APoint . X > AOrigin . X) && (APoint . Y < AOrigin . Y))

            return Result + 2 * Math . PI;

        else return Result;

   }

} /* PointToAngle */