retrieve perimeter points relative to center point in grid

六月ゝ 毕业季﹏ 提交于 2019-12-25 09:14:56

问题


Given p(0,0), how do I retrieve points{(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1)} which are the perimeter points relative to p offset by 1.


回答1:


for(x = p.x -1; x <= p.x + 1; x++) {
    for(y = p.y -1; y <= p.y + 1; y++) {
        // Do some stuff with each p
    }
}

Generic code here. Alter for your programming language and how you store the points.



来源:https://stackoverflow.com/questions/705091/retrieve-perimeter-points-relative-to-center-point-in-grid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!