[求助]四边形或者六变形的面积式子
<FONT face=宋体 size=2>On Error GoTo ErrHandle<BR> Dim pnt<BR> Dim picked As Boolean<BR> Dim px() As Double<BR> Dim py() As Double<BR> Dim i, k As Integer<BR> Dim pcenter() As Double<BR> Dim insertdistance() As Double<BR> Me.Hide<BR>Do While 1<BR> pnt = ThisDrawing.Utility.GetPoint<BR> ThisDrawing.SendCommand "-boundary" & vbCr & "a" & vbCr & "b" & vbCr & "e" & vbCr & vbCr & pnt(0) & "," & pnt(1) & vbCr & vbCr<BR> Set pr = ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1)<BR> Dim retCoord As Variant<BR> retCoord = pr.Coordinates<BR> k = (UBound(retCoord) + 1) / 2 '记录新绘制pline顶点个数<BR> MsgBox "这是一个" & k & "边形"<BR> ReDim px(UBound(retCoord)) As Double<BR> ReDim py(UBound(retCoord)) As Double<BR> For i = 0 To UBound(retCoord) Step 2<BR> px(i / 2) = retCoord(i)<BR> py(i / 2) = retCoord(i + 1)<BR> Next i<BR> ReDim insertdistance(k) As Double<BR> For i = 0 To k - 2 '用点选的方法获得点坐标,然后判断图形形状,计算形状面积,累加所有点选图形面积计算式。结果如图所示: A*B + C*D + E*F<BR> insertdistance(i) = Sqr((px(i) - px(i + 1)) * (px(i) - px(i + 1)) + (py(i) - py(i + 1)) * (py(i) - py(i + 1)))<BR> Next i '因为我只要求出四边形和六边形,并且还差一个判断,所有的角度是直角<BR> If k = 4 Then<BR> ssss = insertdistance(0) & "*" & insertdistance(1)<BR> Else '还有一种情况是六边形<BR> ssss = insertdistance(0) & "*" & insertdistance(1) & "+" & insertdistance(3) & "*" & insertdistance(4) '此处得到了是面积的式子,而且要求每次点击六边形或者四边行要把前面得到的式子再追加上来。……………………………………………………<BR> End If<BR> MsgBox ssss '这里其实应该显示的结果如图所示<BR> picked = True<BR>Loop<BR>ErrHandle:<BR> Me.Show<BR><BR>头疼的地方就在省略号的地方,我不知道如何将第一次选择图形所得到的公式继续追加起来,而且六边形的形状有四种,我的程序中只要考虑这四种情况,如何解决求面积公式,真是不知道如何是好,请多多指教,谢谢</FONT>
前几天的贴子就有,是求多边形的 本帖最后由 作者 于 2004-11-18 0:01:35 编辑
求多边形的公式的那个是用
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">Σ,数学方法求面积。。
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">现在问题是我想做到连续点击若干个长方形,或者是上面所示的六边形,输出的是公式,而不是最后面积的值
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">上面程序中我用ssss求出来的不是面积实数值,而是公式。
另外请问如何统计我开始点击了多少次。 你要公式,他们贴的也是公式,不懂你的意思 <FONT size=2>On Error GoTo ErrHandle<BR> Dim pnt<BR> Dim picked As Boolean<BR> Dim px() As Double<BR> Dim py() As Double<BR> Dim i, k As Integer<BR> Dim pcenter() As Double<BR> Dim insertdistance() As Double<BR> Me.Hide<BR>Do While 1<BR> pnt = ThisDrawing.Utility.GetPoint<BR> ThisDrawing.SendCommand "-boundary" & vbCr & "a" & vbCr & "b" & vbCr & "e" & vbCr & vbCr & pnt(0) & "," & pnt(1) & vbCr & vbCr<BR> Set pr = ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1)<BR> Dim retCoord As Variant<BR> retCoord = pr.Coordinates<BR> k = (UBound(retCoord) + 1) / 2 <BR></FONT><FONT size=2><BR> ReDim px(UBound(retCoord)) As Double<BR> ReDim py(UBound(retCoord)) As Double<BR> For i = 0 To UBound(retCoord) Step 2<BR> px(i / 2) = retCoord(i)<BR> py(i / 2) = retCoord(i + 1)<BR> Next i<BR> ReDim insertdistance(k) As Double<BR> For i = 0 To k - 2 '用点选的方法获得点坐标,然后判断图形形状,计算形状面积,累加所有点选图形面积计算式。结果如图所示: A*B + C*D + E*F<BR> insertdistance(i) = Sqr((px(i) - px(i + 1)) * (px(i) - px(i + 1)) + (py(i) - py(i + 1)) * (py(i) - py(i + 1)))</FONT>
ReDim pcenter(k) As Double<BR> ReDim insertdistance(k) As Double<BR> For i = 0 To k - 2 '此处要解决最后一个点和起始点的距离测定问题<BR> pcenter(i) = (px(i) + px(i + 1)) / 2 <BR> pcenter(i + 1) = (py(i) + py(i + 1)) / 2 + 0.2<BR> insertdistance(i) = Sqr((px(i) - px(i + 1)) * (px(i) - px(i + 1)) + (py(i) - py(i + 1)) * (py(i) - py(i + 1)))<BR> ThisDrawing.ModelSpace.AddText insertdistance(i), pcenter, 0.65%%%%%%%%%%当此语句存在时,程序就会出错,
<FONT size=2> Next i <BR> If k = 4 Then '这是四边形的情况<BR> ssss = insertdistance(0) & "*" & insertdistance(1)<BR> Else '还有一种情况是六边形<BR> ssss = insertdistance(0) & "*" & insertdistance(1) & "+" & insertdistance(3) & "*" & insertdistance(4) '此处得到了是面积的式子,而且要求每次点击六边形或者四边行要把前面得到的式子再追加上来。……………………………………………………<BR> End If<BR> MsgBox ssss '这里其实应该显示的结果如图所示<BR> picked = True<BR>Loop<BR>ErrHandle:<BR> Me.Show</FONT><BR>
这种滴论坛没一种一定是特高难度哈哈
页:
[1]