|
Function LineLen(x1, y1, x2, y2)
'This Function will simply give you the length 'of a line using the coordinates of its two 'endpoints. Dim A, B As Single A = Abs(x2 - x1) B = Abs(y2 - y1) LineLen = Sqr(A ^ 2 + B ^ 2) End Function Function Arccos(X As Single) If X = 1 Then Arccos = 0: Exit Function Arccos = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1) End Function Public Function CalcAnAngle(CenterX, CenterY, x2, y2, x3, y3) 'This Function will take three coordinates and 'automagically turn them into an angle. 'The angle is the one located at CenterX, CenterY 'For example: '/ X2,Y2 '/ ' / ' < CenterX,CenterY ' \ '\ '\ X3,Y3 'CalcAnAngle will return the angle, In degrees, 'of the center vertex. On Error Resume Next Dim SideA, SideB, SideC As Single SideC = lineLen(CenterX, CenterY, x2, y2) SideB = lineLen(CenterX, CenterY, x3, y3) SideA = lineLen(x3, y3, x2, y2) a = Arccos((SideA ^ 2 - SideB ^ 2 - SideC ^ 2) / (SideB * SideC * -2)) CalcAnAngle = a * (180 / 3.141) 'VB seems To like to work In confusing units 'called Radians instead of good ol' degrees. 'Multiplying by (180 / 3.141) converts radians 'to degrees. End Function |