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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:56:55+00:00 2026-05-14T08:56:55+00:00

Greetings, I’m working on a game project that uses a 3D variant of hexagonal

  • 0

Greetings,

I’m working on a game project that uses a 3D variant of hexagonal tile maps. Tiles are actually cubes, not hexes, but are laid out just like hexes (because a square can be turned to a cube to extrapolate from 2D to 3D, but there is no 3D version of a hex). Rather than a verbose description, here goes an example of a 4x4x4 map:

(I have highlighted an arbitrary tile (green) and its adjacent tiles (yellow) to help describe how the whole thing is supposed to work; but the adjacency functions are not the issue, that’s already solved.)

I have a struct type to represent tiles, and maps are represented as a 3D array of tiles (wrapped in a Map class to add some utility methods, but that’s not very relevant).
Each tile is supposed to represent a perfectly cubic space, and they are all exactly the same size. Also, the offset between adjacent “rows” is exactly half the size of a tile.

That’s enough context; my question is:
Given the coordinates of two points A and B, how can I generate a list of the tiles (or, rather, their coordinates) that a straight line between A and B would cross?

That would later be used for a variety of purposes, such as determining Line-of-sight, charge path legality, and so on.

BTW, this may be useful: my maps use the (0,0,0) as a reference position. The ‘jagging’ of the map can be defined as offsetting each tile ((y+z) mod 2) * tileSize/2.0 to the right from the position it’d have on a “sane” cartesian system. For the non-jagged rows, that yields 0; for rows where (y+z) mod 2 is 1, it yields 0.5 tiles.

I’m working on C#4 targeting the .Net Framework 4.0; but I don’t really need specific code, just the algorithm to solve the weird geometric/mathematical problem. I have been trying for several days to solve this at no avail; and trying to draw the whole thing on paper to “visualize” it didn’t help either 🙁 .

Thanks in advance for any answer

  • 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-14T08:56:55+00:00Added an answer on May 14, 2026 at 8:56 am

    Until one of the clever SOers turns up, here’s my dumb solution. I’ll explain it in 2D ‘cos that makes it easier to explain, but it will generalise to 3D easily enough. I think any attempt to try to work this entirely in cell index space is doomed to failure (though I’ll admit it’s just what I think and I look forward to being proved wrong).

    So you need to define a function to map from cartesian coordinates to cell indices. This is straightforward, if a little tricky. First, decide whether point(0,0) is the bottom left corner of cell(0,0) or the centre, or some other point. Since it makes the explanations easier, I’ll go with bottom-left corner. Observe that any point(x,floor(y)==0) maps to cell(floor(x),0). Indeed, any point(x,even(floor(y))) maps to cell(floor(x),floor(y)).

    Here, I invent the boolean function even which returns True if its argument is an even integer. I’ll use odd next: any point point(x,odd(floor(y)) maps to cell(floor(x-0.5),floor(y)).

    Now you have the basics of the recipe for determining lines-of-sight.

    You will also need a function to map from cell(m,n) back to a point in cartesian space. That should be straightforward once you have decided where the origin lies.

    Now, unless I’ve misplaced some brackets, I think you are on your way. You’ll need to:

    • decide where in cell(0,0) you position point(0,0); and adjust the function accordingly;
    • decide where points along the cell boundaries fall; and
    • generalise this into 3 dimensions.

    Depending on the size of the playing field you could store the cartesian coordinates of the cell boundaries in a lookup table (or other data structure), which would probably speed things up.

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

Sidebar

Related Questions

Greetings! I am working on an AS2 website with MovieClips for pages that swap
Greetings, I have a jqueryui autocomplete input that uses an ajax call to populate
Greetings, I'm working on an application inspired by the ZoomingPDFViewer example that comes with
Greetings fellow enthusiasts! I am working on a project and I am utilizing python
Greetings! I have a Repeater control that's using an XmlDataSource control. <asp:FormView id=myFormView runat=server
Greetings Friends, I am trying to overlay the simple 2D game I am developing
Greetings, I have an asp.net mvc application. I have some links that corresponds to
Greetings I've been working on a homework in which I must create a linked
Greetings Stack Overflow community. I'm trying to make a function that can pop all
Greetings to all! I'm not a native English speaker, so excuse me for my

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.