本帖最后由 作者 于 2006-3-23 13:18:30 编辑
Public Function AddArc3Pt(ByVal ptSt As Variant, ByVal ptSc As Variant, ByVal ptEn As Variant) As AcadArc ''''三点法创建圆弧 Dim objArc As AcadArc Dim ptCen As Variant Dim radius As Double ptCen = GetCenOf3Pt(ptSt, ptSc, ptEn, radius) If isClockWise(ptCen, ptSt, ptSc, ptEn) Then Set objArc = AddArcCSEP(ptCen, ptSt, ptEn) Else Set objArc = AddArcCSEP(ptCen, ptEn, ptSt) End If objArc.Update Set AddArc3Pt = objArc End Function
Private Function AddArcCSEP(ByVal ptCen As Variant, ByVal ptSt As Variant, ByVal ptEn As Variant) As AcadArc Dim objArc As AcadArc Dim radius As Double Dim stAng, enAng As Double ''计算半径 radius = GetDistance(ptCen, ptSt) ''计算起点角度和终点角度 stAng = ThisDrawing.Utility.AngleFromXAxis(ptCen, ptSt) enAng = ThisDrawing.Utility.AngleFromXAxis(ptCen, ptEn)
Set objArc = ThisDrawing.ModelSpace.AddArc(ptCen, radius, stAng, enAng) objArc.Update Set AddArcCSEP = objArc End Function
'判断三点的方向 Function isClockWise(ptCen, ptSt, ptSc, ptEn) As Boolean a1 = ThisDrawing.Utility.AngleFromXAxis(ptCen, ptSt) a2 = ThisDrawing.Utility.AngleFromXAxis(ptCen, ptSc) a3 = ThisDrawing.Utility.AngleFromXAxis(ptCen, ptEn) isClockWise = (a1 < a2) Xor (a2 < a3) Xor (a1 < a3) End Function
'说明,逆时针的三种情况如下,其余为顺时针 |