Magic "Integer" Circles

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Magic "Integer" Circles

hh via use-livecode
Some of you may be interested in the following "mathy beauty".

Under all circles with integer radius 0 < r <= 10000 there
are four "magic" ones with radius 5, 25, 65 and 325.
These four have relatively many points of *integers* (x,y)
such that x^2 + y^2 = r^2.
(These points are NOT rounded values that only approximate
the circle value but integer values that are *on* the circle).

Clearly there are at least four such points:
(-r,0),(0,r),(r,0),(0,-r) -- if the origin is (0,0).

Now the relation of radius and number of such points may be such
that we can visually accept a polygon of these points as circles.

To comfort you (script for an option button):

on mouseDown
  put 5 &cr& 25 &cr& 65 &cr& 325 into me
end mouseDown

on mouseUp
  put the label of me into R -- the radius = one of 5, 25, 65, 325
  if there is no grc "poly" then create grc "poly"
  set style of grc "poly" to "polygon"
  set opaque of grc "poly" to "true"
  set backColor of grc "poly" to "255,128,0"
  set markerDrawn of grc "poly" to "true"
  set markerPoints of grc "poly" to "0,0"
  set markerLineSize of grc "poly" to "3"
  set points of grc "poly" to integerPoints(R)
  set loc of grc "poly" to the loc of this card
end mouseUp

-- the circle origin is (0,0), so set the loc of the polygon later on!
function integerPoints rds
  switch rds
    case 5
      -- a circle with radius r=5 contains these 12 points of integers:
      put (4,-3)&cr&(3,-4)&cr&(0,-5)&cr&(-3,-4)&cr&(-4,-3)&cr&(-5,0)&cr& \
          (-4,3)&cr&(-3,4)&cr&(0,5)&cr&(3,4)&cr&(4,3)&cr&(5,0) into p
    case 25
      -- a circle with radius r=25 contains these 20 points of integers:
      put (24,-7)&cr&(20,-15)&cr&(15,-20)&cr&(7,-24)&cr&(0,-25)&cr& \
          (-7,-24)&cr&(-15,-20)&cr&(-20,-15)&cr&(-24,-7)&cr&(-25,0)&cr& \
          (-24,7)&cr&(-20,15)&cr&(-15,20)&cr&(-7,24)&cr&(0,25)&cr& \
          (7,24)&cr&(15,20)&cr&(20,15)&cr&(24,7)&cr&(25,0) into p
    case 65
      -- a circle with radius r=65 contains these 36 points of integers:
      put (63,-16)&cr&(60,-25)&cr&(56,-33)&cr&(52,-39)&cr&(39,-52)&cr& \
          (33,-56)&cr&(25,-60)&cr&(16,-63)&cr&(0,-65)&cr&(-16,-63)&cr& \
          (-25,-60)&cr&(-33,-56)&cr&(-39,-52)&cr&(-52,-39)&cr& \
          (-56,-33)&cr&(-60,-25)&cr&(-63,-16)&cr&(-65,0)&cr&(-63,16)&cr& \
          (-60,25)&cr&(-56,33)&cr&(-52,39)&cr&(-39,52)&cr&(-33,56)&cr& \
          (-25,60)&cr&(-16,63)&cr&(0,65)&cr&(16,63)&cr&(25,60)&cr& \
          (33,56)&cr&(39,52)&cr&(52,39)&cr&(56,33)&cr&(60,25)&cr& \
          (63,16)&cr&(65,0) into p
    case 325
      -- a circle with radius r=325 contains these 60 points of integers:
      put (323,-36)&cr&(315,-80)&cr&(312,-91)&cr&(300,-125)&cr& \
          (280,-165)&cr&(260,-195)&cr&(253,-204)&cr&(204,-253)&cr& \
          (195,-260)&cr&(165,-280)&cr&(125,-300)&cr&(91,-312)&cr& \
          (80,-315)&cr&(36,-323)&cr&(0,-325)&cr&(-36,-323)&cr& \
          (-80,-315)&cr&(-91,-312)&cr&(-125,-300)&cr&(-165,-280)&cr& \
          (-195,-260)&cr&(-204,-253)&cr&(-253,-204)&cr&(-260,-195)&cr& \
          (-280,-165)&cr&(-300,-125)&cr&(-312,-91)&cr&(-315,-80)&cr& \
          (-323,-36)&cr&(-325,0)&cr&(-323,36)&cr&(-315,80)&cr& \
          (-312,91)&cr&(-300,125)&cr&(-280,165)&cr&(-260,195)&cr& \
          (-253,204)&cr&(-204,253)&cr&(-195,260)&cr&(-165,280)&cr& \
          (-125,300)&cr&(-91,312)&cr&(-80,315)&cr&(-36,323)&cr& \
          (0,325)&cr&(36,323)&cr&(80,315)&cr&(91,312)&cr&(125,300)&cr& \
          (165,280)&cr&(195,260)&cr&(204,253)&cr&(253,204)&cr& \
          (260,195)&cr&(280,165)&cr&(300,125)&cr&(312,91)&cr& \
          (315,80)&cr&(323,36)&cr&(325,0) into p
  end switch
  return p &cr& line 1 of p -- close polygon
end integerPoints

Below are the possible number of integer points for all integers radius
values r with 0 < r <= 10000. Each of these numbers is followed by the two
smallest radii where these numbers occur.
TMHO, of these the 12:5, 20:25, 36:65 and 60:325 are acceptable to serve
alone as points of a polygon approximating a circle of radius r (see above).

[number of integer points:radius1,radius2]

For the math behind that last computation see

use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences: