开发者

Get positional data from index on a 2D-field

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜