Determining whether grid coordinates lie within a circle

In summary, the conversation discusses determining whether a point is within or outside of a circle on a grid. The grid cells have integer coordinates and the circle's radius is also an integer value. The individual is struggling with understanding how to check if a grid cell lies within a circle and is seeking guidance. The discussion mentions using sin/cos values to describe the circle's border and processing x and y coordinates with two states per cell. The conversation also touches on avoiding using the square root function in the computation and provides a helpful hint.
  • #1
STENDEC
21
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
  • #2
What is your definition of "within"? Surely that blue square in your picture has a part outside the circle.
 
  • #3
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.
 
  • #4
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.
 
  • #5
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:
 

Related to Determining whether grid coordinates lie within a circle

1. How do you determine whether grid coordinates fall within a circle?

To determine whether grid coordinates fall within a circle, you can use the Pythagorean theorem. First, calculate the distance between the center of the circle and the given coordinates using the formula d = √((x2 - x1)² + (y2 - y1)²). If this distance is less than the radius of the circle, then the coordinates fall within the circle.

2. Can grid coordinates fall partially within a circle?

Yes, grid coordinates can fall partially within a circle. This means that the distance between the given coordinates and the center of the circle is less than the radius, but the coordinates do not fall exactly on the perimeter of the circle.

3. What if the circle is not centered at the origin?

If the circle is not centered at the origin, you will need to first translate the coordinates so that the center of the circle is at the origin. Then, you can use the Pythagorean theorem to determine whether the translated coordinates fall within the circle. Finally, you can translate the coordinates back to their original position.

4. What is the formula for calculating the distance between two points on a grid?

The formula for calculating the distance between two points on a grid is d = √((x2 - x1)² + (y2 - y1)²). This is known as the Pythagorean theorem, where x1 and y1 represent the coordinates of the first point and x2 and y2 represent the coordinates of the second point.

5. Can this method be used for determining whether coordinates fall within other shapes besides circles?

Yes, this method can be used for determining whether coordinates fall within other shapes besides circles. However, the formula used may differ depending on the shape. For example, to determine whether coordinates fall within a square, you would use the formula d = max(|x2 - x1|, |y2 - y1|), where d is the distance between the coordinates and the max function returns the larger of the two values in the parentheses.

Similar threads

Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Replies
20
Views
3K
Replies
1
Views
2K
  • Advanced Physics Homework Help
Replies
7
Views
1K
  • Special and General Relativity
2
Replies
40
Views
2K
  • Special and General Relativity
2
Replies
51
Views
2K
  • Differential Geometry
Replies
8
Views
3K
  • Calculus and Beyond Homework Help
Replies
6
Views
2K
  • Linear and Abstract Algebra
Replies
4
Views
4K
Back
Top