Option Explicit
Dim oMath As Object
Private Sub Command2_Click()
cAvax1.Command = Zoom_c
End Sub
Private Sub Command3_Click()
cAvax1.Command = Previous_c
End Sub
Private Sub Command1_Click()
Dim h() As Long
Dim lMax As Long
Dim lCnt As Long
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
Dim xc As Single, yc As Single, zc As Single
Dim R As Single
lMax = cAvax1.GetSelectedHandlesArr(h())
If lMax = 0 Then
MsgBox "Please, select an object first."
Else
For lCnt = 1 To lMax
If IsArc(h(lCnt), x1, y1, z1, x2, y2, z2, xc, yc, zc, R) = True Then
MsgBox "Yes, it is an Arc" & vbCrLf & x1 & "," & y1 & "," & z1 & vbCrLf & x2 & "," & y2 & "," & z2 & vbCrLf & xc & "," & yc & "," & zc & vbCrLf & "R=" & R, vbInformation, "(" & h(lCnt) & ")"
Else
MsgBox "No, it is not an Arc", vbInformation, "(" & h(lCnt) & ")"
End If
Next lCnt
End If
End Sub
Private Function IsArc(avHandle As Long, x1 As Single, y1 As Single, z1 As Single, x2 As Single, y2 As Single, z2 As Single, xArcC As Single, yArcC As Single, zArcC As Single, R As Single) As Boolean
Dim h() As Long, iType() As AvaxItemType, vProp() As Variant
Dim vData() As Variant, xyz() As Single, vCount As Long, v1 As Long
Dim xa1 As Single, ya1 As Single, za1 As Single
Dim xa2 As Single, ya2 As Single, za2 As Single
Dim xb1 As Single, yb1 As Single, zb1 As Single
Dim xb2 As Single, yb2 As Single, zb2 As Single
Dim xc As Single, yc As Single, zc As Single, dn As Integer
Dim xcOld As Single, ycOld As Single, zcOld As Single, Angle As Single
Dim xc11 As Single, yc11 As Single
Dim xc21 As Single, yc21 As Single
Dim xc12 As Single, yc12 As Single
Dim xc22 As Single, yc22 As Single
Dim R1 As Single
ReDim h(1) As Long
h(1) = avHandle
If cAvax1.GetProperties(h(), iType(), vProp(), vData()) = True Then
If iType(1) = Polyline_i Then
xyz() = vData(1)
vCount = UBound(xyz()) / 6
If vCount > 1 Then
If oMath.IsSamePoint(xyz(1), xyz(2), xyz((vCount - 1) * 6 + 4), xyz((vCount - 1) * 6 + 5)) = True Then Exit Function
For v1 = 1 To vCount - 1
xa1 = xyz((v1 - 1) * 6 + 1)
ya1 = xyz((v1 - 1) * 6 + 2)
za1 = xyz((v1 - 1) * 6 + 3)
xa2 = xyz((v1 - 1) * 6 + 4)
ya2 = xyz((v1 - 1) * 6 + 5)
za2 = xyz((v1 - 1) * 6 + 6)
Call oMath.LineCenter(xa1, ya1, xa2, ya2, xc11, yc11)
Call oMath.LineInclination(xa2, ya2, xa1, ya1, Angle)
Call oMath.PolarPoint(xc11, yc11, 5, Angle + 90, xc12, yc12)
xb1 = xyz(v1 * 6 + 1)
yb1 = xyz(v1 * 6 + 2)
zb1 = xyz(v1 * 6 + 3)
xb2 = xyz(v1 * 6 + 4)
yb2 = xyz(v1 * 6 + 5)
zb2 = xyz(v1 * 6 + 6)
Call oMath.LineCenter(xb1, yb1, xb2, yb2, xc21, yc21)
Call oMath.LineInclination(xb2, yb2, xb1, yb1, Angle)
Call oMath.PolarPoint(xc21, yc21, 5, Angle + 90, xc22, yc22)
dn = 0
Call oMath.InterSectLines(xc11, yc11, xc12, yc12, xc21, yc21, xc22, yc22, xc, yc, dn)
If dn = 0 Then Exit Function
If v1 = 1 Then
x1 = xa2
y1 = ya2
z1 = za2
xcOld = xc
ycOld = yc
zc = za1
Else
If oMath.IsSamePoint(xcOld, ycOld, xc, yc) = False Then
Exit Function
Else
Call oMath.Distance(xa1, ya1, xc, yc, R1)
If R1 > R Then R = R1: xcOld = xc: ycOld = yc
Call oMath.Distance(xb1, yb1, xc, yc, R1)
If R1 > R Then R = R1: xcOld = xc: ycOld = yc
x2 = xb1
y2 = yb1
z2 = zb1
End If
End If
Next v1
xArcC = xcOld
yArcC = ycOld
zArcC = zc
Call oMath.LineCenter(x1, y1, x2, y2, xc11, yc11)
Call oMath.LineInclination(x2, y2, x1, y1, Angle)
Call oMath.PolarPoint(xc11, yc11, 5, Angle + 90, xc12, yc12)
dn = 0
Call oMath.InterSectLines(x1, y1, xcOld, ycOld, xc11, yc11, xc12, yc12, xc, yc, dn)
If dn = 0 Then Exit Function
xArcC = xc
yArcC = yc
Call oMath.Distance(x1, y1, xc, yc, R)
IsArc = True
End If
End If
End If
End Function
Private Sub Form_Load()
Command1.Caption = "Is it an Arc ?"
Command2.Caption = "zoom"
Command3.Caption = "previous"
Set oMath = CreateObject("avMath.cAvaxMath")
cAvax1.StartAvax
Call cAvax1.Add_Arc(0, 1, 0, 1, 0, 0, 0, 0, 0, , 1)
Call cAvax1.Add_Arc(1, 0, 0, 0, 1, 0, 0, 0, 0, , 3)
Call cAvax1.Add_Line(0, 0, 0, 1, 0, 0)
Call cAvax1.Add_Line(0, 0, 0, 0, 1, 0)
Call cAvax1.Add_Rectangle(-1, -1, 2, 2)
cAvax1.Command = AutoLimits_c
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set oMath = Nothing
cAvax1.EndAvax
End Sub
Page 1 of 1
Arc recognition
#1
Posted 08 February 2008 - 02:02 PM
Athanasios Gardos
Avax-Software.com
Avax-Software.com
#2
Posted 11 February 2008 - 02:08 AM
Unfortunately, this code does not seem to work for us. Most of the arcs we see in the drawing (which have come from .DXF) are identified as polylines not as arcs. This is because for some reason, the point values returned by Avax for (Xcold,ycold) and (xc,yc) will vary in accuracy, sometimes being returned at 4 decimals, others at 8. Also, they may be equal to as little as the 2nd decimal place or as much as the 6th. This results in (xcold,ycold) rarely being equal to (xc,yc) so the test fails.
We see this point accuracy problem occur occasionally elsewhere as well but because it is so small a difference it is not usually a problem. For instance, we will draw a radius of 1" and when measured by points later it will come back as a number like .99974 . We are using Vb.Net and do have the most current version of Avax.
Is there any way to correct this without rounding to a very small number of places?
Thanks,
Chris
We see this point accuracy problem occur occasionally elsewhere as well but because it is so small a difference it is not usually a problem. For instance, we will draw a radius of 1" and when measured by points later it will come back as a number like .99974 . We are using Vb.Net and do have the most current version of Avax.
Is there any way to correct this without rounding to a very small number of places?
Thanks,
Chris
Page 1 of 1
Sign In
Register
Help
Add Reply
MultiQuote