Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3802812
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:15:59+00:00 2026-05-19T14:15:59+00:00

I would like to draw a 3D Superformula mesh but not sure how I

  • 0

I would like to draw a 3D Superformula mesh but not sure how I should organize the faces(be them triangles or quads).

I’ve installed octave and tried the sample code. I have no clue how Gnuplot’s mesh() function works, but I imagine I would need something similar.

The Wikipedia entry has a link to a Processing demo.
I had a look at the source and noticed it only draws points.
I tried to wrap that segment of code within beginShape()/endShape()
calls but work the way I hoped.

I also tried to check if the number of points is divisible by 3
or 4 and used TRIANGLES or QUADS, but this is not the right way to do this,
as you can see below:
SuperShape Processing

How can I draw a SuperShape3D using triangles/quads ?
I imagine the vertices are in the right positions, but they
need to be sorted to calls that would draw the faces using
the vertex indices.

I’m not fixed to a particular language at the moment, but
my goal would be to have the vertices in an array, then
push faces(3 or 4 points) using vertex indices.

Any hints ?

Update:

Here is the function used to get the points in the Processing sample code:

import toxi.geom.*;
import controlP5.*;

ControlP5 controlP5;
ArrayList points = new ArrayList();
ArrayList faces = new ArrayList();

float a1=1,a2=1,b=1,xx,step = 0.05,yy,zz,n1=4,n2=12,n3=15,n4=15,r,raux1,r1,raux2,r2;
int N_X = int(2*PI/step);
int N_Y = int(PI/step);


void setup() {
  size(800,800,P3D);
  //hint(ENABLE_DEPTH_SORT);

  controlP5 = new ControlP5(this);

  controlP5.addSlider("a1value",0,3,1,20,0,200,10);
  controlP5.addSlider("a2value",0,3,1,20,20,200,10);
  controlP5.addSlider("bvalue",0,3,1,20,40,200,10);
  controlP5.addSlider("n1value",0,20,8,20,60,200,10);
  controlP5.addSlider("n2value",0,5,0.5,20,80,200,10);
  controlP5.addSlider("n3value",0,5,0.5,20,100,200,10);
  controlP5.addSlider("n4value",0,20,8,20,120,200,10);
  controlP5.addSlider("stepvalue",0.02,0.9,0.05,20,140,200,10);
  controlP5.setAutoDraw(false);
  draw_super_formula();
}

void draw() {
  background(0);
  fill(255);
  controlP5.draw();
  lights();
  translate(width / 2, height / 2, 0);
  rotateX(mouseY * 0.01f);
  rotateY(mouseX * 0.01f);
  // connect 4 points into quads:
  Vec3D pt;
  for(int x=0;x<N_X-1;x++)
  {
    for(int y=0;y<N_Y-1;y++)
    {
      beginShape(QUADS);
      pt = (Vec3D)points.get( x*N_Y + y );
      vertex(pt.x,pt.y,pt.z);
      pt = (Vec3D)points.get( x*N_Y + y+1 );
      vertex(pt.x,pt.y,pt.z);
      pt = (Vec3D)points.get( (x+1)*N_Y + y+1 );
      vertex(pt.x,pt.y,pt.z);
      pt = (Vec3D)points.get( (x+1)*N_Y + y);
      vertex(pt.x,pt.y,pt.z);
      endShape();
    }
  }
}

void vertex(Vec3D v) {
  vertex(v.x,v.y,v.z);
}

void draw_super_formula() {
  for(int i = points.size()-1; i>0;i--){
    points.remove(i);
  }

  for(int x=0;x<N_X;x++)
  {
    float i = -PI + x*step;
    for(int y=0;y<N_Y;y++)
    {
      float j = -PI/2.0 + y*step;
      raux1=pow(abs(1/a1*abs(cos(n1*i/4))),n3)+pow(abs(1/a2*abs(sin(n1*i/4))),n4);
      r1=pow(abs(raux1),(-1/n2));
      raux2=pow(abs(1/a1*abs(cos(n1*j/4))),n3)+pow(abs(1/a2*abs(sin(n1*j/4))),n4);
      r2=pow(abs(raux2),(-1/n2));
      xx=r1*cos(i)*r2*cos(j)*100;
      yy=r1*sin(i)*r2*cos(j)*100;
      zz=r2*sin(j)*100;

      Vec3D test1 = new Vec3D(xx,yy,zz);
      points.add(test1);
    }
  }
}

void bvalue(float new_value){
  b = new_value;
  draw_super_formula();
}
void a1value(float new_value){
  a1 = new_value;
  draw_super_formula();
}
void a2value(float new_value){
  a2 = new_value;
  draw_super_formula();
}
void n1value(float new_value){
  n1 = new_value;
  draw_super_formula();
}
void n2value(float new_value){
  n2 = new_value;
  draw_super_formula();
}
void n3value(float new_value){
  n3 = new_value;
  draw_super_formula();
}
void n4value(float new_value){
  n4 = new_value;
  draw_super_formula();
}

void stepvalue(float new_value){
  step = new_value;
  draw_super_formula();
  println("% 3: "+(points.size()%3));
  println("% 4: "+(points.size()%4));
}
class F4{
  int a,b,c,d;
  F4(int a,int b,int c,int d){
    this.a = a;
    this.b = b;
    this.c = c;
    this.d = d;
  }
}

@tim_hutton’s solution is great, but it looks an index off, trying to figure out where that is.

superformula issue

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:15:59+00:00Added an answer on May 19, 2026 at 2:15 pm

    The superformula gives you a radius for each angle sampled. In 3D you need two angles: theta and phi. By keeping theta fixed and varying phi (or vice versa) you will sample along a great circle.

    One way to make a surface is to make quads by sampling four points based on the angles a and b: (a,b), (a+da,b), (a+da,b+db), (a,b+db). Do this for a: 0,da,2*da… and for b: 0,db,2*db… until the whole surface is covered. Use a small da and db to get small quads.

    (The alternative is to use a generic surface reconstruction algorithm (1,2) but this is overkill for a problem like this.)

    Update:

    I think the code below is something like what you want:

    
    import toxi.geom.*;
    import controlP5.*;
    
    ControlP5 controlP5;
    ArrayList points = new ArrayList();
    ArrayList faces = new ArrayList();
    
    float a1=1,a2=1,b=1,xx,step = 0.05,yy,zz,n1=4,n2=12,n3=15,n4=15,r,raux1,r1,raux2,r2;
    int N_X = int(2*PI/step);
    int N_Y = int(PI/step);
    
    
    void setup() {
      size(800,800,P3D);
      //hint(ENABLE_DEPTH_SORT);
    
      controlP5 = new ControlP5(this);
    
      controlP5.addSlider("a1value",0,3,1,20,0,200,10);
      controlP5.addSlider("a2value",0,3,1,20,20,200,10);
      controlP5.addSlider("bvalue",0,3,1,20,40,200,10);
      controlP5.addSlider("n1value",0,20,8,20,60,200,10);
      controlP5.addSlider("n2value",0,5,0.5,20,80,200,10);
      controlP5.addSlider("n3value",0,5,0.5,20,100,200,10);
      controlP5.addSlider("n4value",0,20,8,20,120,200,10);
      controlP5.addSlider("stepvalue",0.02,0.9,0.05,20,140,200,10);
      controlP5.setAutoDraw(false);
      draw_super_formula();
    }
    
    void draw() {
      background(0);
      fill(255);
    
      controlP5.draw();
    
      translate(width / 2, height / 2, 0);
      rotateX(mouseY * 0.01f);
      rotateY(mouseX * 0.01f);
      drawAxes(300);
      beginShape(POINTS);
      for(int i = 0; i < points.size();i++){
        Vec3D k = (Vec3D)points.get(i); 
        stroke(color(k.x+110,k.y+110,k.z+110));
        vertex(k.x,k.y,k.z);
      }
      endShape();
    
      // connect 4 points into quads:
      Vec3D pt;
      noFill();
      for(int x=0;x<N_X-1;x++)
      {
        for(int y=0;y<N_Y-1;y++)
        {
          beginShape();
          pt = (Vec3D)points.get( x*N_Y + y );
          vertex(pt.x,pt.y,pt.z);
          pt = (Vec3D)points.get( x*N_Y + y+1 );
          vertex(pt.x,pt.y,pt.z);
          pt = (Vec3D)points.get( (x+1)*N_Y + y+1 );
          vertex(pt.x,pt.y,pt.z);
          pt = (Vec3D)points.get( (x+1)*N_Y + y);
          vertex(pt.x,pt.y,pt.z);
          endShape();
        }
      }
    }
    
    void vertex(Vec3D v) {
      vertex(v.x,v.y,v.z);
    }
    
    void draw_super_formula() {
      for(int i = points.size()-1; i>0;i--){
        points.remove(i);
      }
    
      for(int x=0;x<N_X;x++)
      {
        float i = -PI + x*step;
        for(int y=0;y<N_Y;y++)
        {
          float j = -PI/2.0 + y*step;
          raux1=pow(abs(1/a1*abs(cos(n1*i/4))),n3)+pow(abs(1/a2*abs(sin(n1*i/4))),n4);
          r1=pow(abs(raux1),(-1/n2));
          raux2=pow(abs(1/a1*abs(cos(n1*j/4))),n3)+pow(abs(1/a2*abs(sin(n1*j/4))),n4);
          r2=pow(abs(raux2),(-1/n2));
          xx=r1*cos(i)*r2*cos(j)*100;
          yy=r1*sin(i)*r2*cos(j)*100;
          zz=r2*sin(j)*100;
    
          Vec3D test1 = new Vec3D(xx,yy,zz);
          points.add(test1);
        }
      }
    }
    
    void drawAxes(float l) {
      stroke(255, 0, 0);
      line(0, 0, 0, l, 0, 0);
      line(l, 0, 0, l-10, 10, 0);
      line(l, 0, 0, l-10, -10, 0);
    
      stroke(0, 255, 0);
      line(0, 0, 0, 0, l, 0);
      line(0, l, 0, 10, l-10, 0);
      line(0, l, 0, -10, l-10, 0);
    
      stroke(0, 0, 255);
    
      line(0, 0, 0, 0, 0, l);
      line(0, 0, l, 0, 10, l-10);
      line(0, 0, l, 0, -10, l-10);
    
    }
    
    void bvalue(float new_value){
      b = new_value;
      draw_super_formula();
    }
    void a1value(float new_value){
      a1 = new_value;
      draw_super_formula();
    }
    void a2value(float new_value){
      a2 = new_value;
      draw_super_formula();
    }
    void n1value(float new_value){
      n1 = new_value;
      draw_super_formula();
    }
    void n2value(float new_value){
      n2 = new_value;
      draw_super_formula();
    }
    void n3value(float new_value){
      n3 = new_value;
      draw_super_formula();
    }
    void n4value(float new_value){
      n4 = new_value;
      draw_super_formula();
    }
    
    void stepvalue(float new_value){
      step = new_value;
      draw_super_formula();
      println("% 3: "+(points.size()%3));
      println("% 4: "+(points.size()%4));
    }
    class F4{
      int a,b,c,d;
      F4(int a,int b,int c,int d){
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I would like to draw a 2D point in OpenGL, but not in
I have 3d mesh and I would like to draw each face a 2d
I have 2 CGPoints and a would like to draw straight line between them,
I would like to draw triangles, and polygons To draw a triangle I use
I would like to draw a random number from the interval 1,49 but I
I need to draw a load of cubes and would like them to be
I would like to draw text on a canvas using the Canvas.drawText call for
I would like to draw some shapes on a JPanel by overriding paintComponent .
I would like to draw a chart in OpenGL similar to the donut graph
I would like to draw a line or bar graph using HTML5 canvas. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.