开发者

Get positional data from index on a 2D-field

开发者 https://www.devze.com 2023-02-11 13:45 出处:网络
Say I had three variables (On a 2D-field): NumSquares, WindowSize (Both X and Y has this value), Index So if, for example, NumSquares were 8, WindowSize 256 and Index was at 64; How would the algori

Say I had three variables (On a 2D-field):

NumSquares, WindowSize (Both X and Y has this value), Index

So if, for example, NumSquares were 8, WindowSize 256 and Index was at 64; How would the algorithm to get positional data 开发者_运维知识库out of these variables look?


I assume that by "positional data" you mean coordinates on the grid. And index means position of the tile in linearized array calculated with formula X + width * Y. Then:

X = index % width
Y = index / width

I'm not sure what language you are working in, so just to be sure: % is modulo, / is in this context integer division.

0

精彩评论

暂无评论...
验证码 换一张
取 消