Author Topic: Fun Shapes with Pedal Equation  (Read 4618 times)

B+

  • Guest
Fun Shapes with Pedal Equation
« on: March 30, 2017, 07:17:39 PM »
Beautiful! Rick, this is art!  ;D

SdlBasic version:
Code: [Select]
' Fun Shapes with Pedal Equation.sdlbas [B+=MGA] 2017-03-30
' from Fun shapes from Pedal Eq.bas  SmallBASIC 0.12.8 [B+=MGA] 2017-03-30
' inpired by Andy Amaya's screen shots and reference to Superformula
' Here is some experimenting with the pedal equation

const xmax = 800
const ymax = 600
setdisplay(xmax, ymax, 32, 1)
setcaption("Fun Shapes with the Pedal Equation")
autoback(-2)

const pi = acos(-1)
randomize(timer)

function fx(ra, mx, my, e)
'ra = radian angle
'mx, my multipliers of angle
'e exponent of pedal
'mx, my simple multipliers of the ra
fx = ( ( cos(mx * ra) )  ^  e + ( sin(my * ra) ) ^ e) ^ .5
end function

sub polarPlotter(x, y, ra, rdist, fillTF)
'x, y think of as the origin of the plot
'ra = radian angle
'rdist = radial distance from the "origin"
x1 = x + rdist * cos(ra)
y1 = y + rdist * sin(ra)
if fillTF then : line(x, y, x1, y1) : else : circle(x1, y1, 2) : end if
end sub

scale = 200 : fillTF = 0 : cn = 1
for e = 2 to 10
for m1 = 1 to 10
for m2 = 1 to 10
if m1 <> m2 then
cls
ink(0x00bbee)
'circle xmax/2, ymax/2, scale color 12  'for frame of reference red circle with radius 100
text(10, 10, 18, "e = " + str(e) + "  m1 = " + str(m1) + "  m2 = " + str(m2) )
if rnd(11) = 1 then
r = (rnd(10001)/10000) ^ 2 : g =  (rnd(10001)/10000)  ^ 2 : b = (rnd(10001)/10000)  ^ 2
for s = 200 to 0 step -1
ink(rgb( 127+127 * sin(r * cn), 127 + 127 * sin(g * cn), 127 + 127 * sin(b * cn) ) )
cn += .1
for a = 0 to 2 * pi  step .001
d = fx(a, m1, m2, e)
polarPlotter(xmax/2, ymax/2, a, s * d, 0)
next
screenswap
next
else
for a = 0 to 2 * pi  step .001
d = fx(a, m1, m2, e)
polarPlotter(xmax/2, ymax/2, a, scale * d, fillTF)
next
screenswap
end if
wait(400)
end if
next
next
next

SmallBASIC version:
Code: [Select]
' Fun shapes from Pedal Eq.bas  SmallBASIC 0.12.8 [B+=MGA] 2017-03-30
' inpired by Andy Amaya's screen shots and reference to Superformula
' Here is some experimenting with the pedal equation

randomize timer

func fx(ra, mx, my, e)
  'ra = radian angle
  'mx, my multipliers of angle
  'e exponent of pedal
  'mx, my simple multipliers of the ra
  fx = ( ( cos(mx * ra) ) ^ e + ( sin(my * ra) ) ^ e) ^ .5
end

sub polarPlotter(x, y, ra, rdist, fillTF)
  'x, y think of as the origin of the plot
  'ra = radian angle
  'rdist = radial distance from the "origin"
  local l
  l.x1 = x + rdist * cos(ra)
  l.y1 = y + rdist * sin(ra)
  if fillTF then line x, y, l.x1, l.y1 else circle l.x1, l.y1, 1 filled
end

scale = 200 : fillTF = 0
for e = 2 to 10
  for m1 = 1 to 10
    for m2 = 1 to 10
      if m1 <> m2 then
        cls
        color 11
        'circle xmax/2, ymax/2, scale color 12  'for frame of reference red circle with radius 100
        locate 1, 1 : ? "e = ";e;"  m1 = ";m1;"  m2 = ";m2
        if rnd < .1 then
          r = rnd ^ 2 : g = rnd ^ 2 : b = rnd ^ 2
          for s = 200 to 0 step -1
            cc = rgb(127+127*sin(r+cn), 127+127*sin(g*cn), 127+127*sin(b*cn))
            cn += .1
            color cc
            for a = 0 to 2 * pi  step .001
              d = fx(a, m1, m2, e)
              polarPlotter xmax/2, ymax/2, a, s * d, 0
            next
            showpage
          next
        else
          for a = 0 to 2 * pi  step .001
            d = fx(a, m1, m2, e)
            polarPlotter xmax/2, ymax/2, a, scale * d, fillTF
          next
          showpage
        end if
        delay 200
      end if
    next
  next 
next

Rick3137

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #1 on: March 30, 2017, 10:14:45 PM »
   Nice Work. :)

Peter

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #2 on: April 01, 2017, 07:02:33 PM »
Very nice indeed! My port to BaCon, as usual I tried to stay as close to the original code as possible, though I had to rename 'y1' because this is a C function (Bessel calculation). Also, I changed 'fx' to a 'def fn', as this function only contained one line.

Code: [Select]
' Fun Shapes with Pedal Equation.sdlbas [B+=MGA] 2017-03-30
' from Fun shapes from Pedal Eq.bas  SmallBASIC 0.12.8 [B+=MGA] 2017-03-30
' inpired by Andy Amaya's screen shots and reference to Superformula
' Here is some experimenting with the pedal equation
' Port to BaCon by PvE - April 2017 - compile using the '-j' option.

include canvas.bac

option vartype float

const xmax = 800
const ymax = 600
window("Fun Shapes with the Pedal Equation", xmax, ymax)

'ra = radian angle
'mx, my multipliers of angle
'e exponent of pedal
'mx, my simple multipliers of the ra
def fn fx(ra, mx, my, e) = pow(( pow(( cos(mx * ra) ), e) + pow(( sin(my * ra) ), e) ), .5)

sub polarPlotter(x, y, ra, rdist, fillTF)
'x, y think of as the origin of the plot
'ra = radian angle
'rdist = radial distance from the "origin"
x1 = x + rdist * cos(ra)
y_1 = y + rdist * sin(ra)
if fillTF then : line(x, y, x1, y_1) : else : circle(x1, y_1, 2, 2, 0) : end if
end sub

thescale = 200 : fillTF = 0 : cn = 1
for e = 2 to 10
for m1 = 1 to 10
for m2 = 1 to 10
if m1 <> m2 then
ink(0,0,0,255)
cls
ink(0x00,0xbb,0xee,0xff)
'circle xmax/2, ymax/2, scale color 12  'for frame of reference red circle with radius 100
text("e = " & str$(e) & "  m 1 = " & str$(m1) & "  m 2 = " & str$(m2) , 10, 18)
if random(11) = 1 then
r = pow((random(10001)/10000), 2) : g =  pow((random(10001)/10000), 2) : b = pow((random(10001)/10000), 2)
for s = 200 to 0 step -1
ink(127+127 * sin(r * cn), 127 + 127 * sin(g * cn), 127 + 127 * sin(b * cn), 255 )
incr cn, .1
for a = 0 to 2 * pi step .001
d = fx(a, m1, m2, e)
polarPlotter(xmax/2, ymax/2, a, s * d, 0)
next
sync
next
else
for a = 0 to 2 * pi step .001
d = fx(a, m1, m2, e)
polarPlotter(xmax/2, ymax/2, a, thescale * d, fillTF)
next
sync
end if
sleep 400
end if
next
next
next


B+

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #3 on: April 06, 2017, 09:04:34 PM »
Code: [Select]
' Fun shapes from Pedal Eq 2.bas  SmallBASIC 0.12.8 [B+=MGA] 2017-04-06
' inpired by Andy Amaya's screen shots and reference to Superformula
' Here is some experimenting with the pedal equation

'2017-04-06 now using lightning fast thick line and
' 2nd color fill method, midInk along with Plasma method

randomize(timer)
const cx = 350
const cy = 350

func rand(n1, n2)
  local hi, lo 
  if n1 > n2 then hi = n1 : lo = n2 else hi = n2 : lo = n1
  rand = (rnd * (hi - lo + 1)) \ 1 + lo
end

'ink the color that is percent between the first color and 2nd color
sub midInk(r1, g1, b1, r2, g2, b2, percent)
  dr = (r2 - r1) / 100 : dg = (g2 - g1) / 100 : db = (b2 - b1) / 100
  color rgb(r1 + dr * percent, g1 + dg * percent, b1 + db * percent)
end

'new kick butt fast tline!!!
sub tline(x1, y1, x2, y2, thick) 'this draws a little rectangle
  local arr, r, dx, dy, perpA1, perpA2
  dim arr()
  r = thick/2
  dx = x2 - x1
  dy = y2 - y1
  perpA1 = atan2(dy, dx) + pi/2
  perpA2 = perpA1 - pi
  arr << x1 + r * cos(perpA1) 'corner 1
  arr << y1 + r * sin(perpA1)
  arr << x2 + r * cos(perpA1) 'corner 2
  arr << y2 + r * sin(perpA1)
  arr << x2 + r * cos(perpA2) 'corner 3
  arr << y2 + r * sin(perpA2)
  arr << x1 + r * cos(perpA2) 'corner 4
  arr << y1 + r * sin(perpA2)
  arr << x1 + r * cos(perpA1) 'back to first corner
  arr << y1 + r * sin(perpA1)
  drawpoly arr filled
end

func fx(ra, mx, my, e)
  'ra = radian angle
  'mx, my multipliers of angle
  'e exponent of pedal
  'mx, my simple multipliers of the ra
  fx = ( ( cos(mx * ra) ) ^ e + ( sin(my * ra) ) ^ e) ^ .5
end

locate 1, 1 : ? "A moment..."
showpage
scale = 200 : fillTF = 0
while 1
  e = rand(1, 15) : m1 = rand(1, 15) : m2 = rand(1, 15)
  if m1 <> m2 then
    cls
    if rnd < .5 then 'randomly select fill method
      cmode = 1 'plasma mode
      r = rnd ^ 2 : g = rnd ^ 2 : b = rnd ^ 2 : cn = .1
      ms = "Plasma"
    else
      cmode = 0 'midInk mode
      r1 = rand(0, 255) : g1 = rand(0, 255) : b1 = rand(0, 255)
      r2 = rand(0, 255) : g2= rand(0, 255) : b2 = rand(0, 255)
      ms = "midInk"
    end if
    color 11 'label drawing
    locate 1, 1 : ? "e = ";e;"  m1 = ";m1;"  m2 = ";m2;"  Fill Method: ";ms
    for s = 200 to 0 step -1
      if cmode then
        cc = rgb(127+127*sin(r*cn), 127+127*sin(g*cn), 127+127*sin(b*cn))
        cn += .1
        color cc
      else
        midInk r1, g1, b1, r2, g2, b2, s/2
      end if
      for a = 0 to 2 * pi+.011  step .01
        d = fx(a, m1, m2, e)
        x = int(cx + d * s * cos(a))
        y = int(cy + d * s * sin(a))
        if a = 0 then
          lastx = x : lasty = y
        else
          tline lastx, lasty, x, y, 3  'gets most holes
          lastx = x: lasty = y
        end if
        'showpage 'watch shapes being formed, very s l o w l y           
      next
    next
    showpage
    'delay 200  'not needed
  end if
wend

Hard to beat Plasma fill method!
« Last Edit: April 06, 2017, 09:06:18 PM by B+ »

Mike Lobanovsky

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #4 on: April 11, 2017, 10:33:48 PM »
Isn't it supposed to be called "peTal", not "pedal", equation?  ;)

B+

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #5 on: April 12, 2017, 01:13:29 AM »
Isn't it supposed to be called "peTal", not "pedal", equation?  ;)

I was checking out Andy's Superformula reference
https://en.wikipedia.org/wiki/Superformula

and linked to
superellipse

but no not that ???

somewhere I ran into a description of Superformula that called the main exponent n/(n+1) Pedal equations.

funny I don't remember these:
https://en.wikipedia.org/wiki/Pedal_equation

https://en.wikipedia.org/wiki/Pedal_curve

So this code might just be special cases of Superformula, not Pedal, though Superformula has -1/n1 as main exponent.

« Last Edit: April 12, 2017, 02:03:16 AM by B+ »

Aurel

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #6 on: May 02, 2019, 01:51:16 PM »
wait a moment ...
I don't know how i miss this topic  :-X
It looks to me that this superformula can draw patterns ..right?
based on given shape

i have a look on wikipedia and found this :

function sf2d(n, a)
  u = [0:.001:2 * pi];
  raux = abs(1 / a(1) .* abs(cos(n(1) * u / 4))) .^ n(3) + abs(1 / a(2) .* abs(sin(n(1) * u / 4))) .^ n(4);
  r = abs(raux) .^ (- 1 / n(2));
  x = r .* cos(u);
  y = r .* sin(u);
  plot(x, y);
end

I don't know GNU octave ..so what should be blue part with varible u  ::)
u
« Last Edit: May 03, 2019, 01:06:33 PM by Aurel »

ZXDunny

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #7 on: May 02, 2019, 02:45:06 PM »

Aurel

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #8 on: May 02, 2019, 05:10:10 PM »
Hi Paul
.so this is array with 3 element
or array with 3 dimension ... i am confused  ::) or am I too rusty  ;D
by the way on link you give me it is represented as ranges ??
i don't know any BASIC which have ranges  ???

ok so far i get this polarPlott
with just circles it looks little bit ...like antenna polar plot

« Last Edit: May 02, 2019, 05:13:09 PM by Aurel »

Tomaaz

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #9 on: May 03, 2019, 12:12:00 PM »
.so this is array with 3 element
or array with 3 dimension ... i am confused  ::) or am I too rusty  ;D

I don't know Octave, but it looks like it represents all numbers between 0 and 2 * pi step 0.01.

Aurel

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #10 on: May 03, 2019, 01:06:07 PM »
Quote
but it looks like it represents all numbers between 0 and 2 * pi step 0.01.

Yes ..it looks that is range for some sort of ...let say loop
for example like this:

u=0
while u < (2*pi)
  'call function
  sf2d(n,a)
  u = u + 0.01 'incr u  / step
wend

function sf2d(n, a)
  'u = [0:.001:2 * pi];
  raux = abs(1 / a(1) .* abs(cos(n(1) * u / 4))) .^ n(3) + abs(1 / a(2) .* abs(sin(n(1) * u / 4))) .^ n(4);
  r = abs(raux) .^ (- 1 / n(2));
  x = r .* cos(u);
  y = r .* sin(u);
  plot(x, y);
end


..so i think that should be like above  ?
i must try..

But there is a problem with function arguments which are  what ?
it looks like array n(1) , a(1) ...
it seems to me like are sizes or dimensions of specific shape ?
hmm

 
« Last Edit: May 03, 2019, 01:13:39 PM by Aurel »

Aurel

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #11 on: May 03, 2019, 01:44:42 PM »
ok i made 2 arrays for round rectangle shape

but compiler (o2) complain about abnormal error in abs(raux) ^
what loks strange to me ..hmmm

Code: [Select]
float u , pi = 3.14592
int x,y,r
int a[2] , n[4]   ' set array sizes

'round rectangle shape ;
a[] = { 30 , 30 }   ' size 30 x 30 i guess...?
n[] = { 4, 12 , 15 ,15 }

while u < (2*pi)
  'call function for 2d plotting
  sf2d(n,a)
  u = u + 0.01 'incr u  / step
wend


function sf2d(n[], a[])
 
  raux = abs(1 / a[1] * abs(cos(n[1] * u / 4))) ^ n[3] + abs(1 / a[2] * abs(sin(n[1] * u / 4))) ^ n[4]
  r = abs(raux) ^ (- 1 / n[2])
  x = r * cos(u)
  y = r * sin(u)
  pset(win,x, y)
end function

ZXDunny

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #12 on: May 03, 2019, 03:09:12 PM »
Given that ABS() should just return the argument with its sign stripped, it's hard to see what it could complain about :)

Aurel

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #13 on: May 03, 2019, 04:21:24 PM »
complain about power of abs() function

r = abs(raux) * (-1 / n[2]) - this work

but this one not:

r = abs(raux) ^ (-1 / n[2])

anyway this one draw something:
Code: [Select]
function sf2d(int sfx, sfy)
   u = u + 0.01
   pset(win, sfx, sfy)
  raux = abs(a[1] * abs(cos(n[1] * u / 4)))* n[3]  +  abs(a[2] * abs(sin(n[1] * u / 4)))*n[4]
  r = abs(raux) * (-1 / n[2]) 
  x = sfx + r * cos(u)
  y = sfy + r * sin(u)
  pset(win, x, y)
 'circle(win , x, y, r+100)
end function

Paul
I am looking fora mehod how to plot electric current density on metal surface...
Google throw me some images created in gnuOctave ,mathworks ,mathlab..etc
and one in python but that one plot using matlab ..so no directly in python using tcl/tk or pyPy
or something more closer to basic or C or pascal
so that i was trying all posible examples..around  ::)
« Last Edit: May 03, 2019, 04:27:42 PM by Aurel »

Aurel

  • Guest
Re: Fun Shapes with Pedal Equation
« Reply #14 on: May 03, 2019, 04:39:01 PM »
This is what i want to plot
rectangular shape with sizes W,L
and current density  on specific frequency...