SuperShape formula working abruptly in processing

float n1, n2, n3;
float m;
float a, b;
float r;


float total;
float increment;

void setup() {
  size(900, 900);

  
  n1 = 60;
  n2 = 55;
  n3 = 30;
  m = 7;
  a=b=2;
  total=700;
  increment=TWO_PI/total;
 
}

float supershape(float theta) {
  float abs1 = abs(1/a * cos(m/4*theta));
  float abs2 = abs(1/b * sin(m/4*theta));
  float pow1 = pow(abs1,n2);
  float pow2 = pow(abs2,n3);
         r   = pow(pow1+pow2,-1/n1);
  return r;
}

void draw() {
  background(0);
  translate(width/2, height/2);
  beginShape();
  for (float t=0; t<(TWO_PI); t+=increment) {
    r = supershape(t);
    float x = 150 * r * cos(t);
    float y = 150 * r * sin(t);
    stroke(255);
    noFill();
    vertex(x, y);
  }
  endShape(CLOSE);
}

referred to this video.

The formula is the same but I have taken the formula from site below so instead of power 1/n1 ,I am using -1/n1. Rest all same.

http://frink.machighway.com/~dynamicm/super-ellipse.html

For values & shapes. See below link:

http://paulbourke.net/geometry/supershape/

The issue is the shape turns out very abruptly for m=1/6,2/6,3/6…& n1=n2=n3=0.3, I just get a circle.
And for the n1=60,n2=55,n3=30 & for odd m I get weird shapes. Somehow the end point & the first point are not matching together.
It works for some values but for many values of n1,n2,n3,m , it doesn’t produce the desired shape.
Checked the code & formula countless times! Don’t know whats the issue?
Thanks.

1 Like

yes, you need it to be symmetric

-a- not try to force it by the CLOSE if math not good
-b- show what you calculate
-c- check on the ?m?/4
actually use m/2 and it might work for all m ( untested )

float n1=60, n2=55, n3=30;
float m=10;//7;//_______________________________________ change
float a=2, b=2;
float r;

float zoom=100;//__________________________________________ add
float total=700;
float increment=TWO_PI/total;

void setup() {
  size(700, 700); //_______________________________________ change
}

float supershape(float theta) {
  float abs1 = abs(1/a * cos(m/4*theta));
  float abs2 = abs(1/b * sin(m/4*theta));
  float pow1 = pow(abs1, n2);
  float pow2 = pow(abs2, n3);
  r   = pow(pow1+pow2, -1/n1);
  return r;
}

void draw() {
  background(0);
  xr=-width/2; //___________________________________________ add
  translate(width/2, height/2);
  beginShape();
  for (float t=0; t <= TWO_PI ; t+=increment) {
    r = supershape(t);
    show_r(r); //___________________________________________ add
    float x = zoom * r * cos(t);//__________________________ change
    float y = zoom * r * sin(t);//__________________________ change
    stroke(255);
    noFill();
    vertex(x, y);
  }
//  endShape(CLOSE);
  endShape(); //___________________________________________ change
  
}

int xr=0; //_______________________________________________ add
void show_r(float r) {
  push();
  stroke(200,0,0);
  line(xr,height/2,xr,height/2-zoom*r);
  xr++;
  println(xr, r);
  pop();
}

1 Like

hi thanks. WIth the m/4 part, i am using the formula as it is. It just gives circle when m is changed to fraction. And for n1,n2,n3 with different values, it works for even m but not for odd m.
Though I looped it twice for m=7 & it gave me different result

1 Like

good, can you develop a math rule for the 3 settings to give a symmetric result?

Sorry I cant seem to understand. From what I can understand,the issue doesnt seem to be only assymetric. it shows different result for values of m. Check for fractions. it produces only circles.

can you please elaborate on the math rule you are suggesting based on 3points ?
thanks

i mean ‘a’ ‘b’ ‘m’ must be in a way that for
theta = 0 and theta = 2*PI
give same result for r
to give a symmetric shape ?correct? or better CLOSED shape?
( sorry wording )

Your suggestion might work but that would defeat the purpose of getting different shapes with changing these values.
I executed the p5 & processing coding in github too but it produces the same result. I tried the desmos & it works fine.
So the issue seems to be with abs & pow function probably.

I calculated the values (m1/4theta) when m=1/6 ,2/6,3/6…
Turns out it only produces 0.That makes r=1. That explains the circle.
So the issue is not with pow or abs but the way it calculates the fraction.
Its very strange since I haven’t encountered any such problem ever in processing with calculation.

1 Like

Don’t know if i am missing out on something but something as trivial as m=1/4 is giving me 0.0 value in processing. I have no clue why it’s happening. Any guidance would help. Thanks.

At least 1 of the operands needs to be a floating point: m = 1 / 4.0;

2 Likes

yes @GoToLoop Thanks.Sometimes a simple problem is hard to figure out.


Calculating m with varying n & d with 2dTWO_PI cycles gives interesting results but the asymmetric issue still persists with d=1 & n=odd numbers for just TWO_PI cycle.

@kll you were right. The issue lies in asymmetrical nature of shapes with odd numbers.Working on it.
here are some results:

The long straight line on the right side of shape which is mostly present in all designs is little annoying.

2 Likes