random dot matrix

random dot matrix

Miguel.CarvajalS34Q6
Advocate Advocate
461 Views
2 Replies
Message 1 of 3

random dot matrix

Miguel.CarvajalS34Q6
Advocate
Advocate

It is possible to generate a matrix of points with a specific size, that is, if I need circular points of 0.2 mm in a random way in a specific area as well. The diameter can be variable, but in the order of tenths of a millimeter, the area can vary between 150mm x 300mm.

The points cannot overlap and the distance between them will depend on the number of points in the area provided.

0 Likes
Accepted solutions (1)
462 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

You can't draw circular point in Inventor. There is no geometry like this. But you can draw circles instead. Here is the sample how to draw randomly placed circles in given area in part sketch. Part must be open.

 

 

Sub Main()
    Dim part As PartDocument = ThisDoc.Document
    Dim sketch As PlanarSketch = 
            part.ComponentDefinition.Sketches.Add(part.ComponentDefinition.WorkPlanes(3))
    
    Dim width As Double = Double.Parse(InputBox("Input Width [cm]", "Draw points", "10"))
    Dim height As Double = Double.Parse(InputBox("Input Height [cm]", "Draw points", "30"))
    Dim distance As Double = Double.Parse(InputBox("Input Distance [cm]", "Draw points", "1"))
    Dim diameter As Double = Double.Parse(InputBox("Input Diameter [cm]", "Draw points", "0,1"))

    DrawPoints(sketch, width, height, distance, diameter)
End Sub

Private Sub DrawPoints(sketch As PlanarSketch, 
                       width As Double, 
                       height As Double, 
                       distance As Double, 
                       diameter As Double)
    sketch.Edit()
    sketch.DeferUpdates = True

    Dim origin As Point2d = ThisApplication.TransientGeometry.CreatePoint2d()
    Dim topRightPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(width, height)
    sketch.SketchLines.AddAsTwoPointRectangle(origin, topRightPoint)

    Dim x = distance
    Dim y = distance
    Dim diff = distance - diameter
    Dim random As Random = New Random
    While x < width
        While y < height
            Dim rndX = x + diff * (random.NextDouble() - 0.5)
            Dim rndY = y + diff * (random.NextDouble() - 0.5)
            Dim point As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(rndX, rndY)
            sketch.SketchCircles.AddByCenterRadius(point, diameter / 2)
            y += distance
        End While
        y = distance
        x += distance
    End While

    sketch.DeferUpdates = False
    sketch.ExitEdit()
End Sub

 

 

Message 3 of 3

Miguel.CarvajalS34Q6
Advocate
Advocate

excellent solution, the code worked very well

0 Likes