yoyo520125 发表于 2009-5-24 22:20:00

帮忙看下这个程序哪里有问题

目的是选取任意两点计算方位角,代码如下:<br/>Sub calculateangel()<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim point1 As Variant<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim point2 As Variant<br/>&nbsp;&nbsp;&nbsp;&nbsp;p1 = ThisDrawing.Utility.GetPoint(, vbCrLf &amp; "第一点:")<br/>&nbsp;&nbsp;&nbsp;&nbsp;p2 = ThisDrawing.Utility.GetPoint(, vbCrLf &amp; "第二点:")<br/>&nbsp;&nbsp;&nbsp;&nbsp;Const pi As Single = 3.14<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim x As Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim y As Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim z As Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim ang1to2 As Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;x = point1(0) - point2(0)<br/>&nbsp;&nbsp;&nbsp;&nbsp;y = point1(1) - point2(1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;z = point1(2) - point2(2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;ang1to2 = pi - Sgn(y) * pi / 2 - Atn(y / x)<br/>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox "两点之间的方位角为:" &amp; ang1to2, , "个计算单位"<br/>End Sub<br/>希望高手尽快给个解答!

mccad 发表于 2009-5-24 23:12:00

point1,point2这两个变量与p1,p2是什么关系。<br/>pi精度太低了吧,这样出来的角度偏差有点大。<br/>如果只是求点选的两个点的角度,可以直接调用GetAngle方法。
页: [1]
查看完整版本: 帮忙看下这个程序哪里有问题