In the last week I tried to calculate angle between three points -
first I needed to get the points = easy than to calculate the angle (not relatively) = easy tooand now I need to get the angle relative to the graph - the problem is that I dont know how (I am sure this is easy too).
PI = 3.141592654
A(2004,227) B(2005,18) C(2006,25)Here's the function/formula to calculate the Angle >
arctan((Xb - Xa)/(Ya - Yb)) * (180/PI) + arctan((Xc - Xb)/(Yc - Yb)) * (180/PI)
What do I need to add to the formula so it 开发者_JS百科will be relatively to the graph? (I want an explanation too please)
Here's the graph:
Thank you very much!
Edit : Here is the full code of my sub to compute it.
Public Sub Question()
Dim Pi As Double
Pi = 3.141592654
Dim myChart As ChartObject
For Each myChart In ActiveSheet.ChartObjects
Dim xLength As Double
Dim yLength As Double
xLength = myChart.Chart.Axes(1).MaximumScale - myChart.Chart.Axes(1).MinimumScale
yLength = myChart.Chart.Axes(2).MaximumScale - myChart.Chart.Axes(2).MinimumScale
xLength = xLength / myChart.Chart.PlotArea.Width
yLength = yLength / myChart.Chart.PlotArea.Height
Dim goodScale As Double
goodScale = xLength / yLength
Dim v1x As Double
Dim v1y As Double
Dim v2x As Double
Dim v2y As Double
Dim Angle As Double
v1x = 2005 - 2004
v1y = 18 - 227
v2x = 2006 - 2005
v2y = 25 - 18
v1y = v1y * goodScale
v2y = v2y * goodScale
Angle = (Atn(v2x / v2y) - Atn(v1x / v1y)) * (180 / Pi)
Next
End Sub
You'll notice I hardcoded the points in the sub, but that's just to have a small self-sufficient code.
精彩评论