How to resolve the algorithm Superellipse step by step in the Delphi programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Superellipse step by step in the Delphi programming language
Table of Contents
Problem Statement
A superellipse is a geometric figure defined as the set of all points (x, y) with
where n, a, and b are positive numbers.
Draw a superellipse with n = 2.5, and a = b = 200
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Superellipse step by step in the Delphi programming language
Source code in the delphi programming language
procedure DrawSuperElipse(Image: TImage);
var Points: array of double;
const N = 2.5;
const Border = 10;
var A: integer;
var X: integer;
var W2,H2: integer;
begin
{Make elipse size and position based on window size}
W2:=Image.Width div 2;
H2:=Image.Height div 2;
A:=Min(W2,H2)-Border;
{Fill array with points}
SetLength(Points,A);
for X:=0 to High(Points) do
Points[X]:=Power(Power(A, N) - Power(X, N), 1 / N);
Image.Canvas.Pen.Color:=clRed;
Image.Canvas.Pen.Width:=2;
{Starting point}
Image.Canvas.MoveTo(W2+High(Points),trunc(H2-Points[High(Points)]));
{Draw Upper right}
for X:=High(Points) downto 0 do
begin
Image.Canvas.LineTo(W2+x, trunc(H2-Points[X]))
end;
{Draw Upper left}
for X:=0 to High(Points) do
begin
Image.Canvas.LineTo(W2-X, trunc(H2-Points[X]))
end;
{Draw Lower left}
for X:=High(Points) downto 0 do
begin
Image.Canvas.LineTo(W2-X, trunc(H2+Points[X]))
end;
{Draw Lower right}
for X:=0 to High(Points) do
begin
Image.Canvas.LineTo(W2+X, trunc(H2+Points[X]))
end;
{Connect back to beginning}
Image.Canvas.LineTo(W2+High(Points),trunc(H2-Points[High(Points)]));
Image.Repaint;
end;
You may also check:How to resolve the algorithm Combinations with repetitions step by step in the Stata programming language
You may also check:How to resolve the algorithm First perfect square in base n with n unique digits step by step in the Wren programming language
You may also check:How to resolve the algorithm Abundant odd numbers step by step in the MiniScript programming language
You may also check:How to resolve the algorithm Make directory path step by step in the Tcl programming language
You may also check:How to resolve the algorithm Cantor set step by step in the Processing programming language