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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:45:17+00:00 2026-06-12T05:45:17+00:00

Given that $c = 2; // number of columns $r = 3; // number

  • 0

Given that

$c = 2; // number of columns
$r = 3; // number of rows

I need to find the x,y grid coordinate of the value of $i which is the index of a particular cell (left->right, top->bottom order).

Usually, one would work this out using two loops; a loop for rows and another one for columns, but in my case, I need to do this mathematically.

So with the above case, I would have something like:

$grid = new Grid(2, 3);
                                         // i x y
list($x, $y) = $grid->getCoordOfCell(0); // 0 0 0
list($x, $y) = $grid->getCoordOfCell(1); // 1 1 0
list($x, $y) = $grid->getCoordOfCell(2); // 2 0 1
list($x, $y) = $grid->getCoordOfCell(3); // 3 1 1
list($x, $y) = $grid->getCoordOfCell(4); // 4 0 2
list($x, $y) = $grid->getCoordOfCell(5); // 5 1 2

Hypothetically, getCoordOfCell() would return an array of x,y coordinates for grid cell $i.

Don’t know if I missed something here, but I think this is pretty much it.

I guess the resulting mathematical formula would be based on divs or mods, but I just don’t have the mental strength to think this over myself. Plus, I’m sure that as a question this should be useful to others in the future. Oh, although I’m talking PHP here, this is probably language agnostic…

  • 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-12T05:45:18+00:00Added an answer on June 12, 2026 at 5:45 am

    To get right column you have:

     $i % NUMBER_ITEMS_IN_ROW
    

    And to get right row:

     $i / NUMBER_ITEMS_IN_ROW
    

    In your example, there are 3 rows and 2 columns (== items in a row), so:

     $i    $x ($i%2)    $y ($i/2)
     0     0            0
     1     1            0
     2     0            1
     3     1            1
     4     0            2
     5     1            2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume you are given a large number of variables that need to be initialized
How to write multithread windows application that runs a program in given number of
I am looking for a sound algorithm that would randomly place a given number
I have a method connection(int n) which gives me all the cells number that
i need an sms service that can gives me a phone number and then
Given a table that represents a hierarchical tree structure and has three columns ID
I have a large number of rows in a table within which I wish
I have a table structure that looks like this: Columns: Account Number Service Code
Given a large sparse matrix (say 10k+ by 1M+) I need to find a
Suppose that we are given an m x n grid of zeros and ones

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.