arranging circles

arranging circles

Anonymous
Not applicable
328 Views
5 Replies
Message 1 of 6

arranging circles

Anonymous
Not applicable
For one of my appication i need to arrange small circles in a big circle.
the small circle dia and pitch are constant.
the inputs would be
1)small circle dia
2) type of pitch t = triangular or rectangular
3)pitch
4) number of circles.
please refer attached file for your reference
the aim of this is to find the minimum dia of the big circle to accomadate small circles.
can anyone please provide me a lisp or vba program to do this
thanks in advance

regards
Rayalla
0 Likes
329 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
I am not a math because of you need to check all
extensively
Change small radius

Hth

'~~~~~~~~~~~~~~~~~~~~~'
Option Explicit

Sub holes()
Dim s As Double, b As Double, st As Double
Dim mx1 As Double, mx2 As Double
Dim n As Integer, c As Integer
Dim oEnt As AcadEntity, rEnt As AcadEntity
Dim cent(2) As Double, npt(2) As Double
Dim upt(2) As Double, spt(2) As Double
Dim varpt As Variant, xpt As Variant, hpt As Variant
Dim bc As AcadCircle, sc As AcadCircle
Dim retObj1 As Variant, retObj2 As Variant
Dim ans As String
Dim pi As Double
pi = Atn(1) * 4

s = 20#

ans = InputBox("Enter arrange mode" & _
vbNewLine & "Rectangular or Polar" & _
vbNewLine & "case-nonsensitive (R or P) :", "Arrange mode", "R")

varpt = ThisDrawing.Utility.GetPoint(, "Pick center")
cent(0) = CDbl(varpt(0))
cent(1) = CDbl(varpt(1))
cent(2) = CDbl(varpt(2))

If UCase(ans) = "R" Then
b = 480#
st = 70#

c = (Fix(b / st) + 1) * 2
mx1 = c * st
npt(0) = cent(0) - mx1 / 2
npt(1) = cent(1) - mx1 / 2
npt(2) = cent(2)
upt(0) = cent(0) + mx1 / 2
upt(1) = cent(1) + mx1 / 2
upt(2) = cent(2)

ZoomWindow npt, upt

Set bc = ThisDrawing.ModelSpace.AddCircle(cent, b)
Set sc = ThisDrawing.ModelSpace.AddCircle(npt, s)

retObj1 = sc.ArrayRectangular(c, c, 1, st, st, 0)
For n = 0 To UBound(retObj1)
Set oEnt = retObj1(n)
xpt = oEnt.Center
If Distance(xpt, varpt) >= b - s Then
oEnt.Delete
End If
Next
sc.Delete

ElseIf UCase(ans) = "P" Then
b = 450#

st = 76#
Dim xi As Double, yi As Double
Dim c1 As Integer, c2 As Integer
xi = Sqr(st ^ 2 - (st / 2) ^ 2)
yi = st / 2
c1 = (Fix(b / xi * 2) + 1) * 2

mx1 = c1 * xi * 2
c2 = (Fix((b - yi) / st) + 1) * 2
mx2 = c2 * st - st
npt(0) = cent(0) - mx1 / 2
npt(1) = cent(1) - mx2 / 2
npt(2) = cent(2)
upt(0) = cent(0) + mx1 / 2
upt(1) = cent(1) + mx2 / 2
upt(2) = cent(2)

ZoomWindow npt, upt
Set bc = ThisDrawing.ModelSpace.AddCircle(cent, b)
Set sc = ThisDrawing.ModelSpace.AddCircle(npt, s)

retObj1 = sc.ArrayRectangular(c2, c1, 1, st, xi * 2, 0)
For n = 0 To UBound(retObj1)
Set oEnt = retObj1(n)
xpt = oEnt.Center
If Distance(xpt, varpt) >= b - s Then
oEnt.Delete

End If
Next
sc.Delete

spt(0) = npt(0) + xi
spt(1) = npt(1) + st / 2
spt(2) = npt(2)

Set sc = ThisDrawing.ModelSpace.AddCircle(spt, s)
retObj2 = sc.ArrayRectangular(c2, c1, 1, st, xi * 2, 0)

For n = 0 To UBound(retObj2)
Set oEnt = retObj2(n)
xpt = oEnt.Center
If Distance(xpt, varpt) >= b - s Then
oEnt.Delete
End If
Next
sc.Delete
Else
MsgBox "Wrong input"
Exit Sub
End If
ZoomAll
ThisDrawing.Regen acActiveViewport

End Sub
Public Function Distance(fPoint As Variant, sPoint As Variant) As Double

Dim x1, x2 As Double
Dim y1, y2 As Double
Dim z1, z2 As Double
Dim cDist As Double

x1 = fPoint(0): y1 = fPoint(1): z1 = fPoint(2)
x2 = sPoint(0): y2 = sPoint(1): z2 = sPoint(2)

cDist = Sqr(((x2 - x1) ^ 2) + ((y2 - y1) ^ 2) + ((z2 - z1) ^ 2))
Distance = cDist

End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'

Fatty

~'J'~ Message was edited by: Fatty
0 Likes
Message 3 of 6

Anonymous
Not applicable
Dear Fatty,
When i appload the code which you provided Autocad says error :Bad function : 2
could you help me out in this regard.

bye

Rayalla
0 Likes
Message 4 of 6

Anonymous
Not applicable
Hi Rayalla
I have copied right now this code which
I apploaded here and this works nice for me
I used A2005 only
I don't know where you got error message, sorry

Fatty

~'J'~
0 Likes
Message 5 of 6

Anonymous
Not applicable
Hi Fatty,

i am using A2002 for this does this code need to be changed???

rayalla
0 Likes
Message 6 of 6

Anonymous
Not applicable
Hi Rayalla
You need in VBEditior in the menu Tools->References to
change reference on your current AutoCAD 2002 Type Library
and nothing else I hope
You'll see there this line with "MISSED" word

~'J'~
0 Likes