丝雨南竹
花朵
共回答了25个问题采纳率:80% 举报
'新建工程,粘贴进去看效果
Private a As Single,b As Single,r As Single
Private Sub Form_Paint()
a = 2000:b = 2000:r = 1000 '圆参数
Me.Circle (a,b),r,vbRed
'外点
Dim x As Single,y As Single
x = 3000:y = 3000
Me.Circle (x,y),20,vbRed '
Cir x,y
End Sub
'求两点距离
Private Function GetLen(px1 As Single,py1 As Single,px2 As Single,py2 As Single) As Single
GetLen = Sqr((px1 - px2) ^ 2 + (py1 - py2) ^ 2)
End Function
'画切线,x,y为圆外点纵横坐标,
Private Sub Cir(x As Single,y As Single)
Dim i As Single,j As Single,L As Single,s As Single
s = 2 '误差
L = Sqr(GetLen(x,y,a,b) + r ^ 2) '切点与外点距离
For i = a - r To a + r '横坐标
j = b + Sqr(r ^ 2 - (i - a) ^ 2) '上纵坐标
If Abs(GetLen(i,j,x,y) - L) < s And Abs(i - a) > 1 Then
Me.Line (i,j)-(x,y),vbRed:Print i,j '切点坐标
End If
j = b - Sqr(r ^ 2 - (i - a) ^ 2) '下纵坐标
If Abs(GetLen(i,j,x,y) - L) < s And Abs(i - a) > 1 Then
Me.Line (i,j)-(x,y),vbRed:Print i,j '切点坐标
End If
Next i
End Sub
’求切点坐标,画线.
’求切点的方法是遍历圆上点的坐标,如果某些坐标画出来少线了,你可以把误差调大一点.
方案当然有很多,这个函数只是一种思路.
1年前
7