问题
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