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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:24:24+00:00 2026-06-03T23:24:24+00:00

I need to equally distribute N points on a rectangle with a certain width

  • 0

I need to equally distribute N points on a rectangle with a certain width and height.

Ex. given a 10×10 box and 100 points, the points would be set as:

(1,1)  (1,2)  (1,3)  (1,4)  (1,5)  (1,6)  (1,7)  (1,8)  (1,9)  (1,10)
(2,1)  (2,2)  (2,3)  (2,4)  (2,5)  (2,6)  (2,7)  (2,8)  (2,9)  (2,10)
(3,1)  (3,2)  (3,3)  (3,4)  (3,5)  (3,6)  (3,7)  (3,8)  (3,9)  (3,10)
...
...

How can I generalize this for any N points, width and height combination?

Note: It doesn’t needs to be perfect, but close, I’m going to randomize this a little bit anyway (move the point +/- x pixels from this “starting point” on X and Y axis), so having a leftover of a few points to randomly add at the end could be just fine.

I’m looking for something like this (quasirandom):

quasirandom

  • 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-06-03T23:24:25+00:00Added an answer on June 3, 2026 at 11:24 pm

    I managed to make this, if anybody else is looking to accomplish this here’s how:

    First you calculate the total area of the rectangle, then you calculate the area every point should use, and then calculate its own pointWidth and pointHeight (length), then iterate to make cols and rows, here’s an example.

    PHP code:

    $width = 800;
    $height = 300;
    $nPoints = 50;
    
    $totalArea = $width*$height;
    $pointArea = $totalArea/$nPoints;
    $length = sqrt($pointArea);
    
    $im = imagecreatetruecolor($width,$height);
    $red = imagecolorallocate($im,255,0,0);
    
    for($i=$length/2; $i<$width; $i+=$length)
    {
        for($j=$length/2; $j<$height; $j+=$length)
        {
            imageellipse($im,$i,$j,5,5,$im,$red);
        }
    }
    

    I also needed to randomize the position of the dot a little bit, I made this by placing this in the 2nd “for” instead of the code above.

    {
        $x = $i+((rand(0,$length)-$length/2)*$rand);
        $y = $j+((rand(0,$length)-$length/2)*$rand);
        imageellipse($im,$x,$y,5,5,$im,$red);
    
        // $rand is a parameter of the function, which can take a value higher than 0 when using something like 0.001 the points are "NOT RANDOM", while a value of 1 makes the distribution of the points look random but well distributed, high values produced results unwanted for me, but might be useful for other applications.
    }
    

    Hope this helps somebody out there.

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

Sidebar

Related Questions

I need to have a grid (created by program, not by xml) of equally
I am working on a set partitioning problem and need a way to define
I need to substitute a list of words with with an equally long list
Example Given a number of different task types that need to be completed over
I need to validate if my list of list has equally sized lists in
As the title says, I need two divs to be equally high. They should
Need to insert selected text on the page into textarea. There must be some
Need to call a filter function on some options based on a radio selected
need to add a 2nd css stylesheet to a page. do i add a
Need some help, please. I have a line of horizontal thumbnails loaded as ONE

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.