PointsToAngle


Description:
This function calculates the angle of rotation that one point is around a given center point. This probably isn't the most efficient formula possible, but I've found it quite useful.
 
Code:
Option Explicit

Public Const PI = 3.14159265358979

Public Function PointsToAngle(ByVal xOne As Double, ByVal yOne As _
       Double, ByVal X As Double, ByVal Y As Double) As Double

    If xOne = X And Y = yOne Then
        Exit Function
    End If

    X = X - xOne
    Y = Y - yOne
    
    Dim nRatio As Double
    Dim nASin As Double
    nRatio = X / Sqr(Y ^ 2 + X ^ 2)
    
    
    If Abs(nRatio) = 1 Then
        nASin = 90 * nRatio
    Else
        nASin = Atn(nRatio / Sqr(-nRatio * nRatio + 1)) * (180 / PI)
    End If

    If Y < 0 Then
        nASin = 90 - nASin + 90
    ElseIf X < 0 Then
        nASin = nASin + 360
    End If

    PointsToAngle = nASin

End Function
 
Sample Usage:
 
Debug.Print PointsToAngle(1, 1, 9, 9)