Author Topic: Joining the points of regular polygons  (Read 5917 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Joining the points of regular polygons
« Reply #15 on: February 05, 2020, 04:12:27 pm »
Cool! So they are called Steiner trees.

It looks like all the angles out from the Steiner points are 120 degrees of each other. This reminds me of soap bubbles and didn't Steve say something about going around in a C like figure but I was thinking it couldn't be curved so a C shape in straight line segments.

Would it increase code performance if you know in advance the lines out from Steiner points are going to be 120 degrees from each other?

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Joining the points of regular polygons
« Reply #16 on: February 05, 2020, 05:50:46 pm »
I almost said this last night but backspaced it, but I think a solution can come about intuitively this way: Consider the set of given points as fixed (of course). Now surround the entire thing in a soap bubble (dont hold your breath bolus, this isnt Steve's idea)... Gve the soap bubble a few properties:

1) It cannot cross itself or intersect, but it can lay flat on itself in 2 layers or more
2) its infinitely flexible
3) you can define an energy in terms of how much surface area (so just line length) of soap there is
4) *important* the solution will minimize the energy

If all that's true, then you surround the points in this membrane and hit "go". When it's done cooking, the problem is solved. A solution will look like all points basically circled, but with two layers of the membrane becoming what we will call lines or roads coming from each point.. nodes will automatically form, the 120 degree rule will hold for symmetric clusters and obviously bend for ugly ones.

If this hasn't been worked on by a real mathematician I maaaaaay do it.

Anyone need a picture? (Driving now, itll have to come later.) Oh and if you know math terms, this soap film is *almost* but not really a Gaussian surface.
« Last Edit: February 05, 2020, 05:52:18 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Joining the points of regular polygons
« Reply #17 on: February 09, 2020, 02:09:06 pm »
Code: [Select]
deflng a-z
const sw = 800
const sh = 600
dim shared pi as double
pi = 4*atn(1)
declare sub circlef(x, y, r, c)

n = 8
dim x(n), y(n)

'for i=0 to n-1
' x(i) = 200*cos(2*pi*i/n)
' y(i) = 200*sin(2*pi*i/n)
'next

x(0) = 0: y(0) = -200
x(1) = -30: y(1) = -30
x(2) = -200: y(2) = 0
x(3) = -30: y(3) = 30
x(4) = 0: y(4) = 200
x(5) = 30: y(5) = 30
x(6) = 200: y(6) = 0
x(7) = 30: y(7) = -30
x(n) = x(0)
y(n) = y(0)

'screenres sw, sh, 32
screen _newimage(sw, sh, 32)
redraw = -1
drag = 0
do
'm = getmouse(mx, my, mw, mb)
do
mx = _mousex
my = _mousey
mb = -_mousebutton(1)
loop while _mouseinput

if drag then
if mb = 1 then
x(ii) = mx - sw/2
y(ii) = sh/2 - my
else
drag = 0
end if
else
dmin = 1e10
for i=0 to n - 1
dx = (mx - sw/2) - x(i)
dy = (sh/2 - my) - y(i)
d = (dx*dx + dy*dy)
if d < dmin then
dmin = d
ii = i
end if
next

if mb = 1 then
omx = mx
omy = my
drag = -1
end if
end if

redraw = -1

a = 0
cx = 0
cy = 0
for i=0 to n-1
d = x(i)*y(i + 1) - x(i + 1)*y(i)
cx = cx + (x(i) + y(i + 1))*d
cy = cy + (y(i) + y(i + 1))*d
a = a + d
next
cx = cx/(3*a)
cy = cy/(3*a)

if redraw then
'screenlock

line (0,0)-(sw,sh),_rgb(0,0,0),bf
locate 1,1: ? m, mx, my, mw, mb

x(n) = x(0)
y(n) = y(0)
x0 = sw/2 + x(0)
y0 = sh/2 - y(0)
for i=1 to n
x1 = sw/2 + x(i)
y1 = sh/2 - y(i)
line (x0, y0)-(x1, y1)
line -(sw/2 + cx, sh/2 - cy)
circlef x1, y1, 8, _rgb(255,255,255)
x0 = x1
y0 = y1
next
circlef sw/2 + x(ii), sh/2 - y(ii), 8, _rgb(255,0,0)

'screenunlock
'screensync

redraw = 0

_display
end if
loop until _keyhit = 27
system


sub circlef(x, y, r, c)
x0 = r
y0 = 0
e = -r

do while y0 < x0
if e <=0 then
y0 = y0 + 1
line (x - x0, y + y0)-(x + x0, y + y0), c, bf
line (x - x0, y - y0)-(x + x0, y - y0), c, bf
e = e + 2*y0
else
line (x - y0, y - x0)-(x + y0, y - x0), c, bf
line (x - y0, y + x0)-(x + y0, y + x0), c, bf
x0 = x0 - 1
e = e - 2*x0
end if
loop
line (x - r, y)-(x + r, y), c, bf
end sub

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Joining the points of regular polygons
« Reply #18 on: February 10, 2020, 09:18:14 am »
Hi Vince

Cool!
Is it a porting from Freebasic?
Programming isn't difficult, only it's  consuming time and coffee