views:

23

answers:

1

I am looking for a formula that will give me all of the Vector2 Points within a certain radius given the center.

Essentially what I am trying to do is change the color of each pixel in a 256 x 256 texture that is within a certain radius from a specific pixel (Using the Unity3d Game Engine). Programming Language doesn't really matter, as I can probably convert it to something I can use.

A: 

Let cx and cy be center x and center y, and r be the radius.

r2 = r * r;
for each dy = 0 ... r
    dx = 0
    while (dx*dx + dy*dy <= r2)
        within(cx+dx, cy+dy)
        within(cx-dx, cy+dy)
        within(cx+dx, cy-dy)
        within(cx-dx, cy-dy)
        dx++

An optimization would be, not to reset dx to 0 in each iteration, but to some closer value right away.

aioobe