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 6746971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:23:09+00:00 2026-05-26T12:23:09+00:00

I am trying to generate a set of points that do not fall within

  • 0

I am trying to generate a set of points that do not fall within the range of each other in a fixed area. My approach is given below:

import collections
from random import uniform

X = 100.0
Y = 100.0
points = 10
radius = 10

def in_circle(c_x, c_y, radius, x, y):
    dist_squared = (c_x - x)**2 + (c_y - y)**2
    return dist_squared <= radius ** 2

current = collections.defaultdict(lambda: [])

threshold = 0    

for point in range(1, points+1):
    cX = uniform(1.0, X)
    cY = uniform(1.0, Y)

    for cur in current:
        while in_circle(current[cur][0], current[cur][1], 2*radius, cX, cY):
          cX = uniform(1.0, X)
          cY = uniform(1.0, X)

          threshold += 1
          if threshold >= 1e+05:
              print "Cannot satisfy constraints"
              sys.exit(1)

    threshold = 0

    current[point] = [cX, cY]
    print cX, cY

Is there a good way to terminate this algorithm without making it enter an infinite loop? I do have a threshold check but are there better ways to do this?

  • 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-26T12:23:10+00:00Added an answer on May 26, 2026 at 12:23 pm

    This article about poisson disk sampling may be interesting to you. The author explains a strategy for selecting points that aren’t too close to each other, and even provides sample code in a few languages, including Python.

    The problem with the strategy you outlined is, as you noted, that if you want to select a lot of points, or you want the points to be quite far apart, the performance can become atrocious. The poisson disk scheme has better performance characteristics, I believe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to generate a set of points (represented by a Vector struct) that
I am trying to generate equivalent MD5 hashes in both JavaScript and .Net. Not
I've been trying to set my application up so that I can unit test
I'm trying to implement a class that will generate all possible unordered n-tuples or
I am trying to set a user name to a label, but not sure
I'm trying to generate a data set, and I think recursion is required, but
I am currently trying to use Babel to generate a set of static html
I am trying to generate a large data set which includes time datatype in
I'm trying to generate a KML file to display a set of features scattered
I'm trying to model bind a set of dynamically generated checkboxes so as to

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.