开发者

Get all Vector2 Points Within Radius

I开发者_如何学Python 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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜