A superellipse is a geometric figure defined as the set of all points (x, y) with



 





|


x
a


|


n



+


|


y
b


|


n



=
1
,


{\displaystyle \left|{\frac {x}{a}}\right|^{n}\!+\left|{\frac {y}{b}}\right|^{n}\!=1,}




where n, a, and b are positive numbers.



Task
Draw a superellipse with n = 2.5, and a = b = 200




my $a = 200;
my $b = 200;
my $n = 2.5;
 
# y in terms of x
sub y_from_x {
    my($x) = @_;
    int $b * abs(1 - ($x / $a) ** $n ) ** (1/$n)
}
 
# find point pairs for one quadrant
push @q, $_, y_from_x($_) for 0..200;
 
# Generate an SVG image
open  $fh, '>', 'superellipse.svg';
print $fh
  qq|<svg height="@{[2*$b]}" width="@{[2*$a]}" xmlns="http://www.w3.org/2000/svg">\n|,
  pline( 1, 1, @q ),
  pline( 1,-1, @q ), # flip and mirror
  pline(-1,-1, @q ), # for the other
  pline(-1, 1, @q ), # three quadrants
  '</svg>';
 
sub pline {
  my($sx,$sy,@q) = @_;
 
  for (0..$#q/2) {
    $q[  2*$_] *= $sx;
    $q[1+2*$_] *= $sy;
  }
 
  qq|<polyline points="@{[join ' ',@q]}"
  style="fill:none;stroke:black;stroke-width:3"
  transform="translate($a, $b)" />\n|
}