A
A
Aklaim2015-02-17 18:25:11
Mathematics
Aklaim, 2015-02-17 18:25:11

How to determine the planes on which the circle lies?

I do not know how to formulate the question correctly, so the image should help to understand the essence of the issue.
4d773248585545dab9763cc7471433e7.png
I will describe the functionality that I want to implement.
Given a rectangular map measuring M by N. Divided into rectangular areas. Everything is known about these rectangles. Point coordinates, center, etc.
Also given a circle. Its center and radius are known.
Based on these data, it is necessary to calculate which areas of the map the circle falls on.
As a result of calculations based on the figure, the following should be obtained.
The local event will affect areas 1, 2, 6, 7.
The global event will affect all areas except 1 and 6.
Why is this needed.
As can be understood from the figure, this is an event that all objects within its radius of action should recognize. At the same time, objects can be located in different areas, and in order not to check everything in a row, you need to reduce the number of objects by recognizing at least the areas that need to be checked.
PS Advise explanatory books about the mathematics necessary for 2D games.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
bobrovskyserg, 2015-02-17
@bobrovskyserg

Can you cross rectangles?
Then consider the square circumscribed around the circle as a first approximation.
In explanatory books they write that the error will be less than 1/3 of the area of ​​the circle :)

A
Andrew, 2015-02-17
@OLS

I would suggest checking for 4 vertices of the rectangle to hit inside the circle.
All that have at least one vertex hit are affected.
If none of the vertices hit inside, then the event MAY affect a maximum of 5 rectangles - the one in which its center is located + 4 adjacent to it (top, bottom, right, left) - just check.

D
Daniil Basmanov, 2015-02-18
@BasmanovDaniil

You can use rasterization algorithms, similar tasks are solved there.
en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
en.wikipedia.org/wiki/Midpoint_circle_algorithm
stackoverflow.com/questions/10878209/midpoint-circ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question