Superformula

The superformula is a generalization of the superellipse and was first proposed by Johan Gielis.

Gielis suggested that the formula can be used to describe many complex shapes and curves that are found in nature. Others point out that the same can be said about many formulas with a sufficient number of parameters.

In polar coordinates, with r the radius and \varphi the angle, the superformula is:

r\left(\varphi\right) =
\left[
        \left|
                \frac{\cos\left(\frac{m\varphi}{4}\right)}{a}
        \right| ^{n_{2}}
%2B
        \left|
                \frac{\sin\left(\frac{m\varphi}{4}\right)}{b}
        \right| ^{n_{3}}
\right] ^{-\frac{1}{n_{1}}}

The formula appeared in a work by Gielis. It was obtained by generalizing the superellipse, named and popularized by Piet Hein, a Danish mathematician.

Contents

Plots

GNU_Octave program

A GNU Octave program for generating these figures:

  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

PHP script

A PHP script for generating these figures:

<?php
	header("Content-type: image/png");
	set_time_limit(120);
	$img = imagecreatetruecolor(800, 800);
	$black = imagecolorallocate($img, 0, 0, 0);
	imagefilledrectangle($img, 0, 0, 800, 800, $black);
 
	$center = 400;
	$PI = 2 * pi();
 
	$a = 1;
	$b = 1;
	$m = 12;
	$n1 = 5;
	$n2 = 6;
	$n3 = 48;
 
	for($f = 0; $f <= $PI; $f += 0.0001) {
		$r= pow((pow(abs(cos($m*$f/4)/$a),$n2) + pow(abs(sin($m*$f/4)/$b), $n3)), -(1/$n1));
		$x = $center + $r * cos ($f) * 100;
		$y = $center + $r * sin ($f) * 100;
		$col = imagecolorallocate($img, 255, 255, 255);
		imagesetpixel($img, $x, $y, $col);
	}
 
	print imagepng($img);
	imagedestroy($img);
?>

Extension to higher dimensions

It is possible to extend the formula to 3, 4, or n dimensions, by means of spherical product of superformulas. For example, the 3D parametric surface is obtained multiplying two superformulas r1 and r2. The coordinates are defined by the relations:

 x \,=\, r_1(\theta)\cos(\theta)r_2(\phi)\cos(\phi)
 y \,=\, r_1(\theta)\sin(\theta)r_2(\phi)\cos(\phi)
 z \,=\, r_2(\phi)\sin(\phi)

where \phi varies between -π/2 and π/2 (latitude) and θ between and π (longitude).

Plots

GNU_Octave program

A GNU Octave program for generating these figures:

 function sf3d(n, a)
  u=[-pi:.05:pi];
  v=[-pi/2:.05:pi/2];
  nu=length(u);
  nv=length(v);
    for i=1:nu
    for j=1:nv
      raux1=abs(1/a(1)*abs(cos(n(1).*u(i)/4))).^n(3)+abs(1/a(2)*abs(sin(n(1)*u(i)/4))).^n(4);
      r1=abs(raux1).^(-1/n(2));
      raux2=abs(1/a(1)*abs(cos(n(1)*v(j)/4))).^n(3)+abs(1/a(2)*abs(sin(n(1)*v(j)/4))).^n(4);
      r2=abs(raux2).^(-1/n(2));
      x(i,j)=r1*cos(u(i))*r2*cos(v(j));
      y(i,j)=r1*sin(u(i))*r2*cos(v(j));
      z(i,j)=r2*sin(v(j));
    endfor;
  endfor;
  mesh(x,y,z);
 endfunction;

References

External links