My question is quite similar to this one. But what would be the solution in case of a rectangle with width W and length L??
Q1
I would like to find the average shortest distance between randomly distributed n points in a rectangle L xW. I would like to take each point the Euclidean distance to its nearest neighbor,and calculate the average distance over all points?
I was hoping if I could do the same simulation similar to @Henry's answer but I am not quite familiar to computing languages.
Q2
The second part of my question is if I could assign the coordinates of some points in the rectangle. For example, I would like to add some conditions that points cannot be distributed in the grey shaded area in this rectangle. Image here Thus the points can be distributed randomly over the area of the rectangle except for the shaded gray area. What would be the average shortest distance between randomly distributed n number of points ?
I would sincerely appreciate some help.
Approximate solution to Q1 for a large amount of points
If you have N, a large amount of points, then the shape you use becomes irrelevant. In that case you can assume a Poisson distribution of points and consult the literature for the nearest neighbor distribution ( starting point: https://en.wikipedia.org/wiki/Nearest_neighbour_distribution).
In order to decide what "large amount" means, you need to have enough points to ignore the circumference of the shape. This means you need to have a lot more points "inside" the shape than "on the edges". To find out if this holds, lets assume we know $l$, the typical distance between points (we'll estimate the value in a moment). If the total circumference of the shape is $S$, there are approximately $N_{edge} \sim {S\over l}$ points near the edge, so as long as $N>>N_{edge}$ you can use the Poisson approximation.
To estimate $l$ note that the mean area a point "occupies" is $A_{mean} = {W*L\over N}$. Then the typical distance between points is $l=\sqrt{A_{mean}}$. If instead of a rectangle you have some other shape, replace $W*L$ with the area of the shape.