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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:27:03+00:00 2026-06-04T12:27:03+00:00

I currently have an algorithm that generates a point grid. It takes input from

  • 0

I currently have an algorithm that generates a point grid. It takes input from the user in the form of a length of x (lx) and a length of y (ly), and what increment, or delta, (dx and dy) to space the points by. I need the points to always start and finish on the edges of the bounding square defined by lx and ly. I’ve tried a few methods:

The start edge of the bounding square is defined as:

double startx = lx / -2.0, starty = ly / -2.0;

My first method determines the number of points and rounds:

int numintervalx = round(lx / dx), numintervaly = round(ly / dy);

My second method determines the number of points and uses the closest integer greater than the number of points:

int numintervalx = ceil(lx / dx), numintervaly = ceil(ly / dy);

My third method determines the number of points and uses the closest integer less than the number of points:

int numintervalx = floor(lx / dx), numintervaly = floor(ly / dy);

The delta is then recalculated to fit the bounding box:

dx = lx / double(numintervalx);
dy = ly / double(numintervaly);

These are then fed into a for loop that generates the points themselves:

for (int i = 0; i <= numintervaly; i++)
  for (int j = 0; j <= numintervalx; j++)
  {
    double point[3] = {startx + dx * j, starty + dy * i, 0};
  }

Is there another, more accurate, method that would make the actual grid closer to the user specified grid that still always starts and finishes on the edges?

  • 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-04T12:27:05+00:00Added an answer on June 4, 2026 at 12:27 pm

    Think of the integer conversion as adding error. In that case, the way to minimize the error added when converting to an integer is rounding. The worst case is if the user inputs values such that lx/dx is something.5, which means a rounding error of 0.5. Given your problem, this is the best you can do.

    Consider renaming numpoints to numintervals or something, as you actually create one more point than numpoints, which is strange.

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

Sidebar

Related Questions

We have our own data streaming algorithm that include some metadata+records+fields values. Currently we
I currently have a MySQL database that I am accessing using PHP. You search
I currently have the below code, but obviously I am not that skilled on
From my experience I have learn that using an surrogate INT data type column
i have a problem with breadth first algorithm, my script generates curves in maya,
I have an application that serves artifacts from files (pages from PDF files as
I am currently upgrading an application that generates OpenPGP messages to be FIPS 140-2
I have a weighted choice algorithm that works, but I'd like to improve it
I have a question regarding a search algorithm. I currently have 2 files in
I have to write an algorithm based on current random generation standards. I mean,

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.