Determining whether grid coordinates lie within a circle

Click For Summary

Discussion Overview

The discussion revolves around determining whether grid coordinates lie within a circle, focusing on the mathematical and programming aspects of the problem. Participants explore definitions of "within," methods for calculating distances, and potential computational optimizations.

Discussion Character

  • Exploratory, Technical explanation, Debate/contested, Mathematical reasoning

Main Points Raised

  • One participant seeks guidance on checking if grid cells with integer coordinates lie within a circle of a known radius.
  • Another participant questions the definition of "within," pointing out that parts of grid cells may extend outside the circle.
  • A suggestion is made to consider the border of the circle as derived from sin/cos values, leading to a blocky representation rather than a precise circular one.
  • A method is proposed involving the calculation of the distance from the grid point to the circle's center, comparing it to the radius, while also hinting at avoiding the square root calculation.
  • A participant expresses appreciation for the hint and acknowledges their uncertainty in mathematical concepts.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the definition of "within" and the best approach to solve the problem, indicating multiple competing views and unresolved aspects of the discussion.

Contextual Notes

There are limitations regarding the assumptions about the definition of "within" and the potential ambiguity in representing the circle with grid cells. The discussion also touches on the computational aspects of distance calculation without resolving the mathematical steps involved.

STENDEC
Messages
21
Reaction score
0
I have a grid and want to determine whether a point lies within (our outside of) a circle.

asXctUw.png


The grid cells simply have integer coordinates, e.g. x = 5, y = 7. The circle's radius is known, and also an integer value.

I wrote a program that can place points in a (quantized) circle using sin/cos, but I can't seem to wrap my head around how to check whether a grid cell lies within a circle of a given radius. Maybe someone can guide me into the right direction. Thanks.
 
Mathematics news on Phys.org
What is your definition of "within"? Surely that blue square in your picture has a part outside the circle.
 
If you think of the border being derived from the sin/cos values describing the circle, rounded to the nearest integer; A blocky ring if you will.

It doesn't have to be accurate to the single cell if there's some ambiguity about that. X and Y coordinates and 2 states per cell (on/off) is all that's being processed.
 
Do you know the x and y coordinates of the center of the circle, the x and y coordinates of your point and the radius of the circle? If so, compute the distance from the point to the center of the circle and compare that to the radius.

Naively, that computation requires evaluating a square root. Can you think of a way to avoid that?

Hint: The square root function is strictly monotone increasing.
 
That's the help I needed. I'll think about your hint on whether/how sqrt can be avoided in this scenario. I'm not solid in math as is evident I think :shy:
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 40 ·
2
Replies
40
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 61 ·
3
Replies
61
Views
10K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
8K