Jump to content
• ### What is your GameDev Story?

• Advertisement

# 2D Circle Grid

This topic is 4961 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

In my current project, an online 2D space sim, players are able to initiate a battle radius around their ship. Anything in this circle enters a turn-based movement and attack mode--all of this has already been implemented. My problem is something more aesthetic, but still important to the combat function of the game; I want the combat area (currently just a lightly alpha-blended circle of variable radius depending on size of initiatiing ship) to have an inner grid whos cell dimensions remain constant no matter what size the whole of the circle is. How would I go about finding the edges of the circle and filling in the grid to match? Thanks, cyric

#### Share this post

##### Share on other sites
Advertisement
A way I could think of would be to use a grid texture which you draw multiple times on a quad/sprite with the size of (the circles radius*2)*(the circles radius*2) so you've got the right sized grid and use an lightmap with an circle in it which fits to the borders. This light map is mapped on the quad/sprite not repeated but stretched so you've got an circle area visible and the corners are dark.

I don't know how you're rendering your stuff, but if you are working with texture quads this should be possible, I think actually.

Should just be an idea.

Hope it helps.

cheers,
Marcel

#### Share this post

##### Share on other sites
2 ways to get the circle edge.
The first one is to use Bresenham circle alogorithm, that is a quick algo to draw circles. Width that, you can get get all edges with only integers.
The second way use floating operations :

for an angle, x = CenterX+cos(angle) ; y = CenterY+sin(angle)
Maybe it should help you to find edges, and clip your grid in :)

Maybe you want, for a given y, have the x limit ?
Limits are, of course, -x and x.
(of course, add center position to match the correct coordinate)

from the given y, let Y = y/radius.
you know that tan(angle) = Y/radius
then angle = arctan(Y/radius)
after, x = cos(angle)

may it help you ?

#### Share this post

##### Share on other sites
Thanks for the suggestions. I will try your second suggestion, Fvirtman, as it seems to make the most sense to me. Will post the results when done.

#### Share this post

##### Share on other sites
Gamedev has it's very own article on the Bresenham Circle Algo.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 10
• 12
• 10
• 11
• 13
• Advertisement
• ### Forum Statistics

• Total Topics
634094
• Total Posts
3015476
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!