login1986 发表于 2006-8-31 10:19:00

用兩點坐標求線的角度!如果實現!

<P>用两点坐标求线的角度!如果实现!</P>

zhuxuhong 发表于 2006-9-1 08:03:00

你可以先将两点连成直线,再查询直线.angle属性

iq0050 发表于 2006-9-1 09:25:00

Public Function CalculateLineAngle(ByVal vStartPoint As Variant, ByVal vEndPoint As Variant) As Double<BR>&nbsp; On Error Resume Next<BR>&nbsp; <BR>&nbsp; Dim X As Double<BR>&nbsp; Dim Y As Double<BR>&nbsp; <BR>&nbsp; X = vEndPoint(0) - vStartPoint(0)<BR>&nbsp; Y = vEndPoint(1) - vStartPoint(1)<BR>&nbsp; If (X &gt; 0 And Y &gt; 0) Or (X &gt; 0 And Y &lt; 0) Then CalculateLineAngle = Atn(Y / X)<BR>&nbsp; If (X &lt; 0 And Y &gt; 0) Or (X &lt; 0 And Y &lt; 0) Then CalculateLineAngle = PI + Atn(Y / X)<BR>&nbsp; If X = 0 Then<BR>&nbsp;&nbsp;&nbsp; If Y &lt; 0 Then CalculateLineAngle = -PI / 2<BR>&nbsp;&nbsp;&nbsp; If Y &gt; 0 Then CalculateLineAngle = PI / 2<BR>&nbsp; End If<BR>&nbsp; If Y = 0 Then<BR>&nbsp;&nbsp;&nbsp; If X &lt; 0 Then CalculateLineAngle = PI<BR>&nbsp;&nbsp;&nbsp; If X &gt; 0 Then CalculateLineAngle = 0<BR>&nbsp; End If<BR>&nbsp; If Abs(CalculateLineAngle - 0) &lt; dbJudgeAngle Then CalculateLineAngle = 0<BR>&nbsp; If CalculateLineAngle &lt; 0 Then CalculateLineAngle = 2 * PI + CalculateLineAngle<BR>&nbsp; <BR>End Function

iq0050 发表于 2006-9-1 09:27:00

<P>还有dbJudgeAngle是我定义的常量</P>
<P>const dbJudgeAngle=0.001</P>

login1986 发表于 2006-9-1 12:51:00

<P>谢谢各位!!!呵~~</P>
<P>&nbsp;</P>

crazylsp 发表于 2013-4-24 10:44:50

二楼方法直接,三楼是求Y/X正切值再反正切

cqy 发表于 2013-4-24 19:54:52

这函数很有用!
页: [1]
查看完整版本: 用兩點坐標求線的角度!如果實現!