Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Determining whether grid coordinates lie within a circle

  1. Mar 30, 2013 #1
    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.
     
  2. jcsd
  3. Mar 30, 2013 #2

    micromass

    User Avatar
    Staff Emeritus
    Science Advisor
    Education Advisor
    2016 Award

    What is your definition of "within"? Surely that blue square in your picture has a part outside the circle.
     
  4. Mar 30, 2013 #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.
     
  5. Mar 30, 2013 #4

    jbriggs444

    User Avatar
    Science Advisor

    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.
     
  6. Mar 31, 2013 #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:
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Determining whether grid coordinates lie within a circle
Loading...