- 积分
- 590
- 明经币
- 个
- 注册时间
- 2004-3-8
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2005-2-23 08:36:00
|
显示全部楼层
Public Function GetCenOf3Pt(pt1 As Variant, pt2 As Variant, pt3 As Variant, _ ByRef radius As Double) As Variant Dim xysm, xyse, xy As Double Dim ptCen(2) As Double xy = pt1(0) ^ 2 + pt1(1) ^ 2 xyse = xy - pt3(0) ^ 2 - pt3(1) ^ 2 xysm = xy - pt2(0) ^ 2 - pt2(1) ^ 2 xy = (pt1(0) - pt2(0)) * (pt1(1) - pt3(1)) - (pt1(0) - pt3(0)) * (pt1(1) - pt2(1)) '判断参数有效性 If Abs(xy) < 0.000001 Then MsgBox "所输入的参数无法创建圆形!" Exit Function End If '获得圆心和半径 ptCen(0) = (xysm * (pt1(1) - pt3(1)) - xyse * (pt1(1) - pt2(1))) / (2 * xy) ptCen(1) = (xyse * (pt1(0) - pt2(0)) - xysm * (pt1(0) - pt3(0))) / (2 * xy) ptCen(2) = 0 radius = Sqr((pt1(0) - ptCen(0)) * (pt1(0) - ptCen(0)) + (pt1(1) - ptCen(1)) * (pt1(1) - ptCen(1))) If radius < 0.000001 Then MsgBox "半径过小!" Exit Function End If '函数返回圆心的位置,而半径则在参数中通过引用方式返回 GetCenOf3Pt = ptCen End Function |
|