Drawing random circles

Drawing random circles

Anonymous
Not applicable
2,910 Views
15 Replies
Message 1 of 16

Drawing random circles

Anonymous
Not applicable

Is there a way of drawing a specific number of random circles inside a rectangle, without having any intersections between them?

0 Likes
Accepted solutions (1)
2,911 Views
15 Replies
Replies (15)
Message 2 of 16

pendean
Community Legend
Community Legend
Nothing automatically does that: are you trying to replicate something you've seen? Show us.

In the meantime why don't you start CIRCLE command and go for it manually while you wait for others to offer ideas.
0 Likes
Message 3 of 16

imadHabash
Mentor
Mentor

Hi,

does those circles have the same radius ? can we have a screenshot example ?

 

 

Imad Habash

EESignature

0 Likes
Message 4 of 16

Anonymous
Not applicable

I could it manually, but I want to draw about 120 circles, and doing so takes a lot of time. The purpose of these drawings are performing different numerical simulations with the parts created, so this should be a more a less quick procedure.

Below, there is an example of what it should look like

up201605813_0-1615827665130.png

 

0 Likes
Message 5 of 16

Anonymous
Not applicable

Yes, they need to have the same radius.

 

Here is an example below.

up201605813_0-1615827736288.png

 

0 Likes
Message 6 of 16

Anonymous
Not applicable

I could also use multiple arrays. However, that makes the circles' distribution more a less standardized, and I don't want that to happen.

0 Likes
Message 7 of 16

imadHabash
Mentor
Mentor

Hi,

You can make your own hatch ( circles ) then convert it ti block then use SUPERHATCH (Express Tool) . click on below image and see how it's work ... 🙂

 

Suoer.gif

 

 

Imad Habash

EESignature

0 Likes
Message 8 of 16

RobDraw
Mentor
Mentor

Computers have a hard time doing random.


Rob

Drafting is a breeze and Revit doesn't always work the way you think it should.
0 Likes
Message 9 of 16

Anonymous
Not applicable

Is it possible to do that with circles of the same size?

Also, I have developed a code that generates random coordinates within the rectangle. Is it possible to use those coordinates and input them somewhere in Autocad, and use them as the center points of the circles? 

0 Likes
Message 10 of 16

RobDraw
Mentor
Mentor

@Anonymous wrote:

I have developed a code that generates random coordinates within the rectangle.


Is it truly random or just random enough for this exercise?


Rob

Drafting is a breeze and Revit doesn't always work the way you think it should.
0 Likes
Message 11 of 16

pendean
Community Legend
Community Legend
If you want truly random, you'll have to recreate that manually. Sorry.

If you want a set pattern(see the start of your image) to be crated then you go in to ERASE some circles randomly (similar to the end on your posted image) then you indeed need to use ARRAY followed by ERASE done manually.
0 Likes
Message 12 of 16

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Is there a way of drawing a specific number of random circles inside a rectangle, without having any intersections between them?


Maybe WobblyPline.lsp with its WPL command, available >here<, can at least give you a start.  Draw a Line or Polyline down the middle of the area, and use WPL on it using the EXisting-object option, or you can create the Line from inside WPL.  Give it a really large percentage-of-randomization number, to get it really wackily wobbly.  Here, the blue Line is the original, and I asked for 251 segments [to get 250 intermediate vertices], and 400% randomization:

Kent1Cooper_0-1615842115950.png

If the result looks like the vertices would be random-enough locations for your purposes, putting Circles at all the vertices is a trivial coding exercise.

 

If you don't like the result, you can recall the command and use the Redo option to generate a new wobbliness.  After you've made Redo the current option, you can just hit Enter twice [once to recall the command, once to accept the default Redo option], over and over, to have it try again until you like one.  Some Redo's of the above:

Kent1Cooper_1-1615842558447.png

Kent1Cooper_2-1615842618174.png

You can also use the PRevious option to have it start over with the same path, but let you change any or all of the other choices [offering what you chose before for each as the default].

 

The tricky part would be to balance the number of segments and percentage of randomization with the width of the area you want to fill.  And there's the drawback that it can't ensure vertices far enough apart to prevent any of your Circles overlapping, but maybe you could use it as a start and then look through and reposition any that intersect.

 

Kent Cooper, AIA
0 Likes
Message 14 of 16

leeminardi
Mentor
Mentor
Accepted solution

I thought I would do some experimentation with an algorithm I was thinking about.  It is easier for me to work in Excel/VBA so I programmed it there with the output a list of circle commands that can be copy and pasted into AutoCAD.

The Excel file looks like this.

image.png

 

r = circle radius

h = the height of the channel that is to contain the circles

theta min = the minimum angl down from the last circle.  The first circle is centered in the channel. An angle of 0 is straight down.  180 is straight up.

theta max = the maximum angle to the next circle

Lmin, Lmax = the minimum and maximum distance to the next circle. the minimum should be at least 2 * r

number of circle = obvious!

 

The angle and distance to the next circle is calculated and then the result test to see if it is within the channel.  If it is not then another try is made.

When the computation is done you can copy and paste column (from cell F2 down) into AutoCAD.

 

For these values

image.png

here is one solution.

image.png

Here's another with the same values

image.png

 

Here's another set of values and results.

image.png

 

The program could be modified to meet additional requirements or rewritten in VLISP.

 

Here is the Excel/VBA code

Sub main()
' Creates randomw circles.
'LRM  3/15/2021
Range("D2:E1000").Select
Selection.ClearContents
Randomize
Range("b2").Select
r = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
h = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
thetamin = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
thetamax = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Lmin = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Lmax = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
n = ActiveCell.Value

Range("d2").Select
x = 0
y = h / 2#
dx = x
dy = y
ActiveCell.Value = x
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = y
ActiveCell.Offset(1, -1).Select
Pi = 3.1415926535
i = 0
While i < n
    L = Rnd * (Lmax - Lmin) + Lmin
    theta = Rnd * (thetamax - thetamin) + thetamin
    x = dx + L * Cos(theta * Pi / 180# - (Pi / 2))
    y = dy + L * Sin(theta * Pi / 180# - (Pi / 2))
    If i > 1000 Then i = 100
    If y > r And y < (h - r) Then
        dx = x
        ActiveCell.Value = x
        ActiveCell.Offset(0, 1).Select
        dy = y
        ActiveCell.Value = y
        ActiveCell.Offset(1, -1).Select
        i = i + 1
    End If
Wend

End Sub

 

 

lee.minardi
Message 15 of 16

leeminardi
Mentor
Mentor

@Anonymous   I'm glad you found my program acceptable. 

I made a few changes to it including:

  • the program generate a script file that can be run in AutoCAD.
  • fixes a bug that was intended to terminate the program if a solution was not found.
  • redefines the meaning of r such that rmin = 0 means circles may touch. 
  • cleans up data typing.

The program may generate circles that overlap. These would have to be manually deletes.  It currently only checks if the next  circle is below 0 or above h.  A lookback feature could be added to determine if the next circle to be added overlaps with a previous circle.  Let me know if you think it would be worthwhile to add this feature. 

 

Option Explicit

Sub main()
' Creates random circles.
'LRM  3/15/2021, revision 1 3/17/2021
'get file name
Dim fn_file As Variant
Dim x As Double, y As Double, r As Double, h As Double
Dim thetaMin As Double, thetaMax As Double, Theta As Double
Dim LMin As Double, LMax As Double, L As Double
Dim i As Integer, k As Integer, n As Integer
Dim dx As Double, dy As Double, Pi As Double
Dim msg As Variant

fn_file = InputBox("Enter file name: ", , "test")
fn_file = fn_file & ".scr"
Open fn_file For Output As #2
Randomize
Range("b2").Select
r = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
h = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
thetaMin = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
thetaMax = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
LMin = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
LMax = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
n = ActiveCell.Value

Range("d2").Select
x = 0
y = h / 2#
dx = x
dy = y
Pi = 3.1415926535
i = 0
k = 0
While i < n
k = k + 1
    L = Rnd * (LMax - LMin) + LMin + (2 * r)
    Theta = Rnd * (thetaMax - thetaMin) + thetaMin
    x = dx + L * Cos(Theta * Pi / 180# - (Pi / 2))
    y = dy + L * Sin(Theta * Pi / 180# - (Pi / 2))
    If k > 100 Then
    i = n + 1
    MsgBox "No solution found." & vbCrLf & "Try using different input values."
    
    End If
    If y > r And y < (h - r) Then
        dx = x
        dy = y
        i = i + 1
        msg = "_circle " & x & "," & y & " " & r
        Print #2, msg
        k = 0
    End If
Wend
Close #2
MsgBox ("File " & fn_file & " has been created.")
End Sub
lee.minardi
0 Likes
Message 16 of 16

Anonymous
Not applicable

@leeminardi Yes, it would be very useful. Also, it would be useful to be able to define the horizontal limits of the rectangle.

 

0 Likes