用VBA编程,画一条曲线,如用三个点,怎么画?
用VBA编程,画一条曲线,是object.AddArc(Center, Radius, StartAngle, EndAngle)。如果确定的是三点,怎么编写,有没有相应的函数式? 其实知道了三个点就可以知道Center, Radius, StartAngle, EndAngle了
不过麻烦点罢了 不是麻烦一点,是很麻烦的啊!! 做四条辅助线求中点(用中垂线相交求出)
中点求出后Radius, StartAngle, EndAngle就出来了 lzh741206发表于2004-5-14 14:48:00static/image/common/back.gif做四条辅助线求中点(用中垂线相交求出)
中点求出后Radius, StartAngle, EndAngle就出来了
<BR> 这不就是村数学方法吗。楼主文的是vba方法吧,呵呵 VBA就不能使用纯数学的方法吗?只要能达到目的就行。 我说的本来就是VBA方法麽,用AddLine方法画四条辅助线,用IntersectWith方法求交点,再用AngleFromXAxis方法求角度
什么方法不重要,关键是编程思路 冤枉死了,我就是为达到目的不择手段的那种
只不过是替搂住就是一下,他的意思是有没有直接的方法。
再说让我做也是那么做的吗. 最简单的办法就是用SendCommand调用命令直接做,这才是为达到目的不择手段,哈哈 Sub Test()
Dim pt1 As Variant
Dim pt2 As Variant
Dim pt3 As Variant
pt1 = ThisDrawing.Utility.GetPoint(, "指定圆弧的起点: ")
pt2 = ThisDrawing.Utility.GetPoint(, "指定圆弧的第二个点: ")
pt3 = ThisDrawing.Utility.GetPoint(, "指定圆弧的端点:: ")
Const PI = 3.1415926
' 第一段角度
Dim ang As Double
ang = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)
' 第一段中点
Dim spt(0 To 2) As Double
spt(0) = (pt1(0) + pt2(0)) / 2
spt(1) = (pt1(1) + pt2(1)) / 2
Dim ept As Variant
ept = ThisDrawing.Utility.PolarPoint(spt, ang - PI / 2, 1000)
' 第一段垂直平分线
Dim LineObj1 As AcadLine
Set LineObj1 = ThisDrawing.ModelSpace.AddLine(spt, ept)
' 第二段角度
ang = ThisDrawing.Utility.AngleFromXAxis(pt3, pt2)
' 第二段中点
spt(0) = (pt3(0) + pt2(0)) / 2
spt(1) = (pt3(1) + pt2(1)) / 2
ept = ThisDrawing.Utility.PolarPoint(spt, ang + PI / 2, 1000)
' 第二段垂直平分线
Dim LineObj2 As AcadLine
Set LineObj2 = ThisDrawing.ModelSpace.AddLine(spt, ept)
' 求交点,即为圆心
Dim cpt As Variant
cpt = LineObj1.IntersectWith(LineObj2, acExtendBoth)
LineObj1.Delete
LineObj2.Delete
' 求圆心与端点的距离,即为半径
Dim r As Double
r = Sqr((cpt(0) - pt1(0)) ^ 2 + (cpt(1) - pt1(1)) ^ 2)
' 求起始角度和终止角度
Dim sang As Double
sang = ThisDrawing.Utility.AngleFromXAxis(cpt, pt1)
Dim eang As Double
eang = ThisDrawing.Utility.AngleFromXAxis(cpt, pt3)
If sang > eang Then
sang = ThisDrawing.Utility.AngleFromXAxis(cpt, pt3)
eang = ThisDrawing.Utility.AngleFromXAxis(cpt, pt1)
End If
ThisDrawing.ModelSpace.AddArc cpt, r, sang, eang
End Sub
页:
[1]
2