Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3670842
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:24:52+00:00 2026-05-19T02:24:52+00:00

I’m interested in a way (algorithm) of distributing a predefined number of points over

  • 0

I’m interested in a way (algorithm) of distributing a predefined number of points over a 4 sided surface like a square.

The main issue is that each point has got to have a minimum and maximum proximity to each other (random between two predefined values). Basically the distance of any two points should not be closer than let’s say 2, and a further than 3.

My code will be implemented in ruby (the points are locations, the surface is a map), but any ideas or snippets are definitely welcomed as all my ideas include a fair amount of brute force.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:24:53+00:00Added an answer on May 19, 2026 at 2:24 am

    Try this paper. It has a nice, intuitive algorithm that does what you need.

    In our modelization, we adopted another model: we consider each center to be related to all its neighbours by a repulsive string.

    At the beginning of the simulation, the centers are randomly distributed, as well as the strengths of the
    strings. We choose randomly to move one center; then we calculate the resulting force caused by all
    neighbours of the given center, and we calculate the displacement which is proportional and oriented
    in the sense of the resulting force.

    After a certain number of iterations (which depends on the number of
    centers and the degree of initial randomness) the system becomes stable.

    In case it is not clear from the figures, this approach generates uniformly distributed points. You may use instead a force that is zero inside your bounds (between 2 and 3, for example) and non-zero otherwise (repulsive if the points are too close, attractive if too far).

    This is my Python implementation (sorry, I don´t know ruby). Just import this and call uniform() to get a list of points.

    import numpy as np
    from numpy.linalg import norm
    import pylab as pl
    
    # find the nearest neighbors (brute force)
    def neighbors(x, X, n=10):
      dX = X - x
      d = dX[:,0]**2 + dX[:,1]**2
      idx = np.argsort(d)
      return X[idx[1:11]]
    
    # repulsion force, normalized to 1 when d == rmin
    def repulsion(neib, x, d, rmin):
      if d == 0:
        return np.array([1,-1])
    
      return 2*(x - neib)*rmin/(d*(d + rmin))
    
    def attraction(neib, x, d, rmax):
      return rmax*(neib - x)/(d**2)
    
    def uniform(n=25, rmin=0.1, rmax=0.15):
      # Generate randomly distributed points
      X = np.random.random_sample( (n, 2) )
    
      # Constants
      # step is how much each point is allowed to move
      #   set to a lower value when you have more points
      step = 1./50.
    
      # maxk is the maximum number of iterations
      #   if step is too low, then maxk will need to increase
      maxk = 100
    
      k = 0
    
      # Force applied to the points
      F = np.zeros(X.shape)
    
      # Repeat for maxk iterations or until all forces are zero
      maxf = 1.
      while maxf > 0 and k < maxk:
        maxf = 0
        for i in xrange(n):
          # Force calculation for the i-th point
          x = X[i]
          f = np.zeros(x.shape)
    
          # Interact with at most 10 neighbors
          Neib = neighbors(x, X, 10)
    
          # dmin is the distance to the nearest neighbor
          dmin = norm(Neib[0] - x)
    
          for neib in Neib:
            d = norm(neib - x)
            if d < rmin:
              # feel repulsion from points that are too near
              f += repulsion(neib, x, d, rmin)
            elif dmin > rmax:
              # feel attraction if there are no neighbors closer than rmax
              f += attraction(neib, x, d, rmax)
    
          # save all forces and the maximum force to normalize later
          F[i] = f
          if norm(f) <> 0:
            maxf = max(maxf, norm(f))
    
        # update all positions using the forces
        if maxf > 0:
          X += (F/maxf)*step
    
        k += 1
    
      if k == maxk:
        print "warning: iteration limit reached"
    
      return X
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.