Search code examples
algorithmmathlanguage-agnosticfunctional-programmingformula

Is there any formula that maps an int on the range [0..πR²] to the (x,y) coordinates inside the circle of radius R?


The formula:

index(i,w,h) = (i%w, (i/w)%h)

uniquely maps each integer i on the range [0..w*h] to a coordinate inside the rectangle of width w and height h. Is there any similar formula:

index(i,r) = ?

that uniquely maps each integer on the range [0..πR²] to a coordinate inside the circle of radius R?


Solution

  • Note that the most circles with radius R contain less than πR² integer points within the boundary, so usually that map doesn't exist.

    Reference: Gauss circle problem

    And I suspect that even for good R values there is no simple formula, only iterative aprroach (look at (1) formula in the linked page)