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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:21:34+00:00 2026-05-25T22:21:34+00:00

I’d like to have a function that accepts a geo location (Latitude, Longitude) and

  • 0

I’d like to have a function that accepts a geo location (Latitude, Longitude) and generates random sets of coordinates around it but also takes these parameters as a part of the calculation:

  • Number Of Random Coordinates To Make
  • Radius to generate in
  • Min distance between the random coordinates in meters
  • The root coordinates to generate the locations around it.

Example of how the generation would be:

Example

What’s a good approach to achieve 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-25T22:21:34+00:00Added an answer on May 25, 2026 at 10:21 pm

    A brute force method should be good enough.

    for each point to generate "n"
      find a random angle
      get the x and y from the angle * a random radius up to max radius
      for each point already generated "p"
         calculate the distance between "n" and "p"
      if "n" satisfies the min distance
         add new point "n"
    

    In PHP, generating a new point is easy

    $angle = deg2rad(mt_rand(0, 359));
    $pointRadius = mt_rand(0, $radius);
    $point = array(
       'x' => sin($angle) * $pointRadius,
       'y' => cos($angle) * $pointRadius
    );
    

    Then calculating the distance between two points

    $distance = sqrt(pow($n['x'] - $p['x'], 2) + pow($n['y'] - $p['y'], 2));
    

    ** Edit **

    For the sake of clarifying what others have said, and after doing some further research (I’m not a mathematician, but the comments did make me wonder), here the most simple definition of a gaussian distribution :

    If you were in 1 dimension, then $pointRadius = $x * mt_rand(0,
    $radius); would be OK since there is no distinction between
    $radius and $x when $x has a gaussian distribution.

    In 2 or more dimensions, however, if the coordinates ($x,$y,…) have
    gaussian distributions then the radius $radius does not have a
    gaussian distribution.

    In fact the distribution of $radius^2 in 2 dimensions [or k
    dimensions] is what is called the “chi-squared distribution with 2 [or
    k] degrees of freedom”, provided the ($x,$y,…) are independent and
    have zero means and equal variances.

    Therefore, to have a normal distribution, you’d have to change the line of the generated radius to

    $pointRadius = sqrt(mt_rand(0, $radius*$radius));
    

    as others have suggested.

    • 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’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I have some data like this: 1 2 3 4 5 9 2 6
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.