Application Center - Maplesoft

App Preview:

Recognition of Leaves and General 2-D Objects

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

leaves.mws

Doc. RNDr. Stanislav Barton, CSc.
Mendel university of Agriculture and Forestry in Brno
Agronomical faculty
Dept. of Automobile transport and principles of technics
Zemedelska 1; 61300 Brno
++ 05 4513 2127
barton@mendelu.cz

Identification and Recognition of Leaves and General 2-D Objects

Part 1:  - Transformation of DXF file into a parametric function

Theory:   The outline of an arbitrary complicated 2D object can be approximated by a polygon consisting of a finite number of line segments. A scanned image can be converted into line segments by the program Adobe Streamline or similar, and the resulting outline can be saved as DXF file = Data Exchange Format. The [x, y]  coordinates of polygon vertices can be found in this file. The simplest approximation of such a polygon can be done by a couple of parametrically dependent functions .The main question is the proper selection of such a  parameter an ordinary number of the verticies can be an example of the parameter. But for other manipulations this parameter will be very important. If the parameter is a length from the initial point on the perimeter, measured along the perimeter normalized to 2 Pi , Fourier series can be used. As is shown in the section Fourier  and results from the orthogonality of goniometric functions, it is possible to compute Fourier coefficients independently, not only for x  and y  functions, but these coefficients are independent. The objects outline is converted into a couple of smooth continuous functions defined on the interval <0, 2 Pi > . These functions can be described by the lists of coefficients and can be used to compute the similarity of two different objects, described by the coefficients of the linear correlation, for example. These coefficients will be computed in the first part.

>   

>    restart;

>    File:="Maple1";

File :=

Reading of the procedures

>    read `DXFREAD.pro`:

>   

Procedure DXFREAD

The procedure reads the input DXF file and looks for x  and y  coordinates of the polygon describing the perimeter of the given object. Coordinates are read step by step as they are ordered in the input file. Coordinates are saved in the variables X  and Y  of type list.
Procedure's input is the name of the file, without extension, containing DXF data.  The output is two rlists of vertices, one for x coordinates and one for y.

DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description
DXFREAD := proc (FileName) local line; global X, Y, N; description

>    read `SOLAO.pro`:

>   

Procedure SOLAO

Procedure orients the object in the coordinate system. The line of orientation  is chosen to minimize the moment of inertia (with respect to the axis of rotation in the xy  plane). So the parameters k  and q  minimize J(k,q) = Int(r(k,q)^2,s = S .. ` `)  , where k  and q  are parameters describing the general line y = k*x+q , ds  = element of the curve (perimeter) and r  = distance of the element of the curve ds  from the line. The procedure finds two such lines, mutually perpendicular. One leads to a minimum of J(k,q)  the second one to a maximum. The whole object is shifted so that the intersection of these lines will be identical with the origin of the coordinate system [0,0] , and rotated so that line with the minimum moment of inertia will coincide with the x  axis. This leads to identical orientation of all objects. Because the object (polygon) is created from line segments, it is possible to use the following law to simplify computation
Int(r(k,q)^2,s = S .. ` `) = Int(Sum(r(k[i],q[i])^2,i = 1 .. N-1),s = S .. ` `)  => Sum(Int(r(k[i],q[i])^2,p = 0 .. 1),i = 1 .. N-1) ,
where
N  = count of found vertices, thus N-1  line segments, p = parameter describing line segment
The Maple functions
makeproc  and optimize  were used to derive this procedure.
Procedures inputs are lists
X  and Y  of coordinates of the vertices.  The procedure changes the values of X  and Y  inplace.

SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...
SOLAO := proc (Xi, Eta) local t240, t310, t232, t18, t299, t249, t147, t309, t106, t103, t100, t149, t108, t111, t153, t145, t120, t302, t311, t305, t317, t268, t321, t197, t142, t320, t156, t1, t3, t4...

Derivation of the procedure SOLAO

>    restart;

>    with(linalg):  open library Linear Algebra

>    with(codegen,optimize,makeproc,cost);  Open library for code generation, automatic optimization and computer resource computation

[optimize, makeproc, cost]

>    Prx:=x=Kx*p+Qx; Pry:=y=Ky*p+Qy;  Parametric description of the line segment creating part of the perimeter. K = [Kx, Ky] is a vector corresponding to the line segment and  p = parameter , 0 <= p <= 1.

Prx := x = Kx*p+Qx

Pry := y = Ky*p+Qy

>    solx:=solve({subs(x=X[i],p=0,Prx),subs(x=X[i+1],p=1,Prx)},{Kx,Qx}); soly:=solve({subs(y=Y[i],p=0,Pry),subs(y=Y[i+1],p=1,Pry)},{Ky,Qy});
Computation of the components of the vector  K

solx := {Qx = X[i], Kx = X[i+1]-X[i]}

soly := {Ky = Y[i+1]-Y[i], Qy = Y[i]}

>    S2 := (q-y+k*x)^2/(1+k^2);  Squared distance of the point [x,y]  from the line eta = k*xi+q

S2 := (q-y+k*x)^2/(1+k^2)

>    S2s:=subs(Prx,Pry,S2);    [ x,y ]  moves along Prx, Pry  = one of line segments describing object, S2s  = the squared distance from the point on the line segment to the general line. Point position is given by the parameter p .

S2s := (q-Ky*p-Qy+k*(Kx*p+Qx))^2/(1+k^2)

>    S2i:=int(S2s*L[i],p=0..1); Computation of the moment of inertia for one line segment

S2i := 1/3*(-Ky+k*Kx)^2/(1+k^2)*L[i]+(q-Qy+k*Qx)*(-Ky+k*Kx)/(1+k^2)*L[i]+(q-Qy+k*Qx)^2/(1+k^2)*L[i]

>    S2ii:=simplify(subs(solx,soly,S2i)); Kx and  Ky are described by  [x,y] coordinates of the initial and final point of the line segment. Substitution.

S2ii := 1/3*L[i]*(3*q*k*X[i]+3*q*k*X[i+1]-2*Y[i+1]*k*X[i+1]+k^2*X[i+1]*X[i]-3*q*Y[i+1]-2*Y[i]*k*X[i]+Y[i]^2+Y[i+1]*Y[i]+Y[i+1]^2+3*q^2-3*q*Y[i]+k^2*X[i]^2+k^2*X[i+1]^2-Y[i+1]*k*X[i]-Y[i]*k*X[i+1])/(1+k...
S2ii := 1/3*L[i]*(3*q*k*X[i]+3*q*k*X[i+1]-2*Y[i+1]*k*X[i+1]+k^2*X[i+1]*X[i]-3*q*Y[i+1]-2*Y[i]*k*X[i]+Y[i]^2+Y[i+1]*Y[i]+Y[i+1]^2+3*q^2-3*q*Y[i]+k^2*X[i]^2+k^2*X[i+1]^2-Y[i+1]*k*X[i]-Y[i]*k*X[i+1])/(1+k...

>    S2S1:=map(u->simplify(sum(u,i=1..N-1)),expand(S2ii));  Summation of individual integrals.

S2S1 := 1/(1+k^2)*q*k*sum(L[i]*X[i],i = 1 .. N-1)+1/(1+k^2)*q*k*sum(X[i+1]*L[i],i = 1 .. N-1)-2/3*1/(1+k^2)*k*sum(L[i]*Y[i+1]*X[i+1],i = 1 .. N-1)+1/3/(1+k^2)*k^2*sum(L[i]*X[i+1]*X[i],i = 1 .. N-1)-1/(...
S2S1 := 1/(1+k^2)*q*k*sum(L[i]*X[i],i = 1 .. N-1)+1/(1+k^2)*q*k*sum(X[i+1]*L[i],i = 1 .. N-1)-2/3*1/(1+k^2)*k*sum(L[i]*Y[i+1]*X[i+1],i = 1 .. N-1)+1/3/(1+k^2)*k^2*sum(L[i]*X[i+1]*X[i],i = 1 .. N-1)-1/(...
S2S1 := 1/(1+k^2)*q*k*sum(L[i]*X[i],i = 1 .. N-1)+1/(1+k^2)*q*k*sum(X[i+1]*L[i],i = 1 .. N-1)-2/3*1/(1+k^2)*k*sum(L[i]*Y[i+1]*X[i+1],i = 1 .. N-1)+1/3/(1+k^2)*k^2*sum(L[i]*X[i+1]*X[i],i = 1 .. N-1)-1/(...

>    sigma:=[selectfun(S2S1,sum)[]];  Separation of individual independent summations

sigma := [sum(L[i]*Y[i]^2,i = 1 .. N-1), sum(L[i],i = 1 .. N-1), sum(L[i]*X[i],i = 1 .. N-1), sum(L[i]*X[i+1]*X[i],i = 1 .. N-1), sum(L[i]*Y[i]*X[i],i = 1 .. N-1), sum(L[i]*Y[i],i = 1 .. N-1), sum(L[i]...
sigma := [sum(L[i]*Y[i]^2,i = 1 .. N-1), sum(L[i],i = 1 .. N-1), sum(L[i]*X[i],i = 1 .. N-1), sum(L[i]*X[i+1]*X[i],i = 1 .. N-1), sum(L[i]*Y[i]*X[i],i = 1 .. N-1), sum(L[i]*Y[i],i = 1 .. N-1), sum(L[i]...

>    n:=nops(sigma);

n := 15

>    Su:={seq(sigma[j]=Sigma||j,j=1..n)}; Substitution of summations leads to a simplified overview.

Su := {sum(L[i]*Y[i]^2,i = 1 .. N-1) = Sigma1, sum(L[i]*X[i+1]*X[i],i = 1 .. N-1) = Sigma4, sum(L[i]*X[i],i = 1 .. N-1) = Sigma3, sum(L[i],i = 1 .. N-1) = Sigma2, sum(X[i+1]*L[i],i = 1 .. N-1) = Sigma8...
Su := {sum(L[i]*Y[i]^2,i = 1 .. N-1) = Sigma1, sum(L[i]*X[i+1]*X[i],i = 1 .. N-1) = Sigma4, sum(L[i]*X[i],i = 1 .. N-1) = Sigma3, sum(L[i],i = 1 .. N-1) = Sigma2, sum(X[i+1]*L[i],i = 1 .. N-1) = Sigma8...
Su := {sum(L[i]*Y[i]^2,i = 1 .. N-1) = Sigma1, sum(L[i]*X[i+1]*X[i],i = 1 .. N-1) = Sigma4, sum(L[i]*X[i],i = 1 .. N-1) = Sigma3, sum(L[i],i = 1 .. N-1) = Sigma2, sum(X[i+1]*L[i],i = 1 .. N-1) = Sigma8...

>    Bs:=map(u->rhs(u)=lhs(u),Su); Back substitution

Bs := {Sigma5 = sum(L[i]*Y[i]*X[i],i = 1 .. N-1), Sigma11 = sum(L[i]*X[i]^2,i = 1 .. N-1), Sigma14 = sum(X[i+1]^2*L[i],i = 1 .. N-1), Sigma13 = sum(L[i]*Y[i+1]*X[i+1],i = 1 .. N-1), Sigma15 = sum(L[i]*...
Bs := {Sigma5 = sum(L[i]*Y[i]*X[i],i = 1 .. N-1), Sigma11 = sum(L[i]*X[i]^2,i = 1 .. N-1), Sigma14 = sum(X[i+1]^2*L[i],i = 1 .. N-1), Sigma13 = sum(L[i]*Y[i+1]*X[i+1],i = 1 .. N-1), Sigma15 = sum(L[i]*...
Bs := {Sigma5 = sum(L[i]*Y[i]*X[i],i = 1 .. N-1), Sigma11 = sum(L[i]*X[i]^2,i = 1 .. N-1), Sigma14 = sum(X[i+1]^2*L[i],i = 1 .. N-1), Sigma13 = sum(L[i]*Y[i+1]*X[i+1],i = 1 .. N-1), Sigma15 = sum(L[i]*...

>    S2S2:=simplify(subs(Su,S2S1)); Substituted integral

S2S2 := 1/3*(3*q*k*Sigma3+3*q*k*Sigma8-2*k*Sigma13+k^2*Sigma4-3*q*Sigma9-2*k*Sigma5+Sigma1+Sigma7+Sigma10+3*q^2*Sigma2-3*q*Sigma6+k^2*Sigma11+k^2*Sigma14-k*Sigma15-k*Sigma12)/(1+k^2)

>    Sk:=numer(diff(S2S2,k)); Sq:=numer(diff(S2S2,q)); Normal equations. Their solution returns values of k  and q  minimizing S2S2  = moment of inertia of the object

Sk := 3*q*Sigma3+3*q*Sigma8+6*k*q*Sigma9-2*k*Sigma7-2*k*Sigma10+2*Sigma5*k^2+Sigma15*k^2+Sigma12*k^2-2*k*Sigma1-2*Sigma5+2*Sigma13*k^2+2*k*Sigma4+2*k*Sigma11+2*k*Sigma14-Sigma12-3*q*Sigma8*k^2-3*q*Sigm...
Sk := 3*q*Sigma3+3*q*Sigma8+6*k*q*Sigma9-2*k*Sigma7-2*k*Sigma10+2*Sigma5*k^2+Sigma15*k^2+Sigma12*k^2-2*k*Sigma1-2*Sigma5+2*Sigma13*k^2+2*k*Sigma4+2*k*Sigma11+2*k*Sigma14-Sigma12-3*q*Sigma8*k^2-3*q*Sigm...

Sq := k*Sigma3+k*Sigma8-Sigma9+2*q*Sigma2-Sigma6

>    sol:=allvalues(solve({Sk,Sq},{k,q})): Computed variables of k  and q . Output is not presented, because it is too long.

>    SOLA:=vector([subs(sol[1],[k,q])[],subs(sol[2],[k,q])[]]): Solution is converted into a vector.

>    Cost1:=cost(SOLA); Consumption of computer memory for the original solution = SOLA

Cost1 := 2706*multiplications+8*divisions+726*additions+12*functions+4*storage+4*assignments+4*subscripts

>    SOLAp:=makeproc(SOLA,[seq(Sigma||j,j=1..n)]): Conversion of the solution into a procedure

>    SOLAO:=optimize(SOLAp): Procedure optimization

>    Cost2:=cost(SOLAo); Consumption of computer memory for the optimized solution = SOLAo

Cost2 := 72*storage+73*assignments+308*multiplications+2*divisions+138*additions+2*functions+4*subscripts

>    Cost1-Cost2; savings

2398*multiplications+6*divisions+588*additions+10*functions-68*storage-69*assignments

>   

Sense of the procedure

>    read `DXFREAD.pro`:

>    DXFREAD(`Oak1.dxf`); Input of the coordinates of the vertices

"Converting DXF file into lists of coordinates of vertices"

"102 vertices found"

>    P1:=plot(zip((x,y)->[x,y],X,Y),color=blue): Before centering and orientation

>    SOLAO(X,Y); application of the procedure

"Looking for center and axis of symmetry"

"Shift =[-3.846728402, -2.137677566]"

"Rotation = 2.201621101*degrees"

>    P2:=plot(zip((x,y)->[x,y],X,Y),color=red,thickness=2): Centered and orientated plot

>    plots[display]({P1,P2},scaling=constrained);

[Maple Plot]

>    read `PHASE0.pro`:

>   

Procedure PHASE0

Parametric functions are used to describe a given object, therefore it is advantageous to set 0  to the value of the parameter so that the corresponding point will have always the same positional = phase angle. This procedure is searching for the point situated on the x  axis, and its x  coordinate is maximal. The procedure later reorders the lists of coordinates in that way, so this point will be the first one, but the shape of the object will be preserved.
Inputs and outputs of the procedure are lists of the coordinates of the vertices..
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description
PHASE0 := proc (Xi, Eta) local Zeroes, X0, Max, J; global X, Y, N; description

Sense of the procedure

>    P1:=plot(zip((x,y)->[x,y],X,Y)):

>    A1:=plots[arrow]([X[1],Y[1]],color=blue):  Displays original initial point

>    read `PHASE0.pro`:

>    PHASE0(X,Y);

"Setting 0 to initial phase"

"Zero point = [3.537382891, 0]"

>    A2:=plots[arrow]([X[1],Y[1]],color=red):  New initial point lays on the x  axis

>    plots[display]({P1,A1,A2},scaling=constrained);

[Maple Plot]

>    read `FOURIER.pro`:

>   

Procedure FOURIER

Procedure Fourier  computes coefficients of the Fourier series substituting piecewise defined functions x(p)  and y(p) , 0 <= p <= L ,( L  = distance of the point [x(p),y(p)] , from the initial point, [x(0),y(0)]  measured along the perimeter). Fourier series will create smooth continuous functions defined on the interval <0,2 Pi > .
The procedures entries are the lists of the coordinates of the vertices, the third parameter indicates the number of the members of the series, outputs are the lists of the Fourier coefficients

FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description
FOURIER := proc (Xi, Eta, n) local L, K, Q, j; global N, X0, Y0, Cx, Sx, Cy, Sy; description

Derivation of the procedure FOURIER

>    restart;

>    q:=(f(p)-sum(c[i]*cos(p[i])+s[i]*sin(p[i]),i=0..3))^2; Squared residuals

q := (f(p)-c[0]*cos(p[0])-s[0]*sin(p[0])-c[1]*cos(p[1])-s[1]*sin(p[1])-c[2]*cos(p[2])-s[2]*sin(p[2])-c[3]*cos(p[3])-s[3]*sin(p[3]))^2

>    q2:=expand(q):

>    q3:=eval(subs(seq(p[i]=i*p,i=0..3),q2)); The first four members will be used, for the sake of brevity.

q3 := f(p)^2-2*f(p)*c[2]*cos(2*p)-2*f(p)*s[2]*sin(2*p)+s[2]^2*sin(2*p)^2+c[2]^2*cos(2*p)^2-2*f(p)*s[1]*sin(p)-2*f(p)*c[1]*cos(p)+2*c[1]*cos(p)*s[1]*sin(p)+2*c[1]*cos(p)*s[3]*sin(3*p)+2*s[1]*sin(p)*c[3]...
q3 := f(p)^2-2*f(p)*c[2]*cos(2*p)-2*f(p)*s[2]*sin(2*p)+s[2]^2*sin(2*p)^2+c[2]^2*cos(2*p)^2-2*f(p)*s[1]*sin(p)-2*f(p)*c[1]*cos(p)+2*c[1]*cos(p)*s[1]*sin(p)+2*c[1]*cos(p)*s[3]*sin(3*p)+2*s[1]*sin(p)*c[3]...
q3 := f(p)^2-2*f(p)*c[2]*cos(2*p)-2*f(p)*s[2]*sin(2*p)+s[2]^2*sin(2*p)^2+c[2]^2*cos(2*p)^2-2*f(p)*s[1]*sin(p)-2*f(p)*c[1]*cos(p)+2*c[1]*cos(p)*s[1]*sin(p)+2*c[1]*cos(p)*s[3]*sin(3*p)+2*s[1]*sin(p)*c[3]...
q3 := f(p)^2-2*f(p)*c[2]*cos(2*p)-2*f(p)*s[2]*sin(2*p)+s[2]^2*sin(2*p)^2+c[2]^2*cos(2*p)^2-2*f(p)*s[1]*sin(p)-2*f(p)*c[1]*cos(p)+2*c[1]*cos(p)*s[1]*sin(p)+2*c[1]*cos(p)*s[3]*sin(3*p)+2*s[1]*sin(p)*c[3]...
q3 := f(p)^2-2*f(p)*c[2]*cos(2*p)-2*f(p)*s[2]*sin(2*p)+s[2]^2*sin(2*p)^2+c[2]^2*cos(2*p)^2-2*f(p)*s[1]*sin(p)-2*f(p)*c[1]*cos(p)+2*c[1]*cos(p)*s[1]*sin(p)+2*c[1]*cos(p)*s[3]*sin(3*p)+2*s[1]*sin(p)*c[3]...
q3 := f(p)^2-2*f(p)*c[2]*cos(2*p)-2*f(p)*s[2]*sin(2*p)+s[2]^2*sin(2*p)^2+c[2]^2*cos(2*p)^2-2*f(p)*s[1]*sin(p)-2*f(p)*c[1]*cos(p)+2*c[1]*cos(p)*s[1]*sin(p)+2*c[1]*cos(p)*s[3]*sin(3*p)+2*s[1]*sin(p)*c[3]...

>    q4:=map(u->simplify(int(u,p=0..2*Pi)),q3); Integral of the squared residuals

q4 := int(f(p)^2,p = 0 .. 2*Pi)+Pi*c[1]^2-2*c[1]*int(f(p)*cos(p),p = 0 .. 2*Pi)+Pi*s[1]^2-2*c[2]*int(f(p)*cos(2*p),p = 0 .. 2*Pi)+Pi*c[3]^2+Pi*s[2]^2-2*c[0]*int(f(p),p = 0 .. 2*Pi)+Pi*c[2]^2-2*s[2]*int...
q4 := int(f(p)^2,p = 0 .. 2*Pi)+Pi*c[1]^2-2*c[1]*int(f(p)*cos(p),p = 0 .. 2*Pi)+Pi*s[1]^2-2*c[2]*int(f(p)*cos(2*p),p = 0 .. 2*Pi)+Pi*c[3]^2+Pi*s[2]^2-2*c[0]*int(f(p),p = 0 .. 2*Pi)+Pi*c[2]^2-2*s[2]*int...

>    Var:={c[0],seq({c[i],s[i]}[],i=1..3)}; The set of the unknown Fourier coefficients

Var := {c[2], c[3], c[0], c[1], s[1], s[3], s[2]}

>    Eq:=map(u->diff(q4,u)=0,Var); The normal equations.

Eq := {-2*int(f(p)*cos(2*p),p = 0 .. 2*Pi)+2*Pi*c[2] = 0, 2*Pi*s[3]-2*int(f(p)*sin(3*p),p = 0 .. 2*Pi) = 0, 2*Pi*s[1]-2*int(f(p)*sin(p),p = 0 .. 2*Pi) = 0, 2*Pi*c[1]-2*int(f(p)*cos(p),p = 0 .. 2*Pi) = ...
Eq := {-2*int(f(p)*cos(2*p),p = 0 .. 2*Pi)+2*Pi*c[2] = 0, 2*Pi*s[3]-2*int(f(p)*sin(3*p),p = 0 .. 2*Pi) = 0, 2*Pi*s[1]-2*int(f(p)*sin(p),p = 0 .. 2*Pi) = 0, 2*Pi*c[1]-2*int(f(p)*cos(p),p = 0 .. 2*Pi) = ...

>    sol:=solve(Eq,Var); Coefficients formulas, can be simply generalized

sol := {s[2] = int(f(p)*sin(2*p),p = 0 .. 2*Pi)/Pi, s[3] = int(f(p)*sin(3*p),p = 0 .. 2*Pi)/Pi, c[3] = int(f(p)*cos(3*p),p = 0 .. 2*Pi)/Pi, c[0] = 1/2*int(f(p),p = 0 .. 2*Pi)/Pi, s[1] = int(f(p)*sin(p)...
sol := {s[2] = int(f(p)*sin(2*p),p = 0 .. 2*Pi)/Pi, s[3] = int(f(p)*sin(3*p),p = 0 .. 2*Pi)/Pi, c[3] = int(f(p)*cos(3*p),p = 0 .. 2*Pi)/Pi, c[0] = 1/2*int(f(p),p = 0 .. 2*Pi)/Pi, s[1] = int(f(p)*sin(p)...

>    Sol:={C0=1/2*int(f(p),p=0..2*Pi)/Pi,
      Cn=int(f(p)*cos(n*p),p=0..2*Pi)/Pi,
      Sn=int(f(p)*sin(n*p),p=0..2*Pi)/Pi};
Generalized solution

Sol := {C0 = 1/2*int(f(p),p = 0 .. 2*Pi)/Pi, Cn = int(f(p)*cos(n*p),p = 0 .. 2*Pi)/Pi, Sn = int(f(p)*sin(n*p),p = 0 .. 2*Pi)/Pi}

>    sol1:=subs('p=0..2*Pi'='p=X[i]..X[i+1]',f(p)=K[i]*p+Q[i],Sol); Generalization for the piecewise defined function one interval of the validity, all partial functions are line segments

sol1 := {Sn = int((K[i]*p+Q[i])*sin(n*p),p = X[i] .. X[i+1])/Pi, C0 = 1/2*int(K[i]*p+Q[i],p = X[i] .. X[i+1])/Pi, Cn = int((K[i]*p+Q[i])*cos(n*p),p = X[i] .. X[i+1])/Pi}

>    sol2:=value(sol1); sol1  can be integrated

sol2 := {Sn = (K[i]*sin(n*X[i+1])-K[i]*n*X[i+1]*cos(n*X[i+1])-Q[i]*cos(n*X[i+1])*n-K[i]*sin(n*X[i])+K[i]*n*X[i]*cos(n*X[i])+Q[i]*cos(n*X[i])*n)/n^2/Pi, C0 = 1/2*(1/2*K[i]*(X[i+1]^2-X[i]^2)+Q[i]*(X[i+1]...
sol2 := {Sn = (K[i]*sin(n*X[i+1])-K[i]*n*X[i+1]*cos(n*X[i+1])-Q[i]*cos(n*X[i+1])*n-K[i]*sin(n*X[i])+K[i]*n*X[i]*cos(n*X[i])+Q[i]*cos(n*X[i])*n)/n^2/Pi, C0 = 1/2*(1/2*K[i]*(X[i+1]^2-X[i]^2)+Q[i]*(X[i+1]...
sol2 := {Sn = (K[i]*sin(n*X[i+1])-K[i]*n*X[i+1]*cos(n*X[i+1])-Q[i]*cos(n*X[i+1])*n-K[i]*sin(n*X[i])+K[i]*n*X[i]*cos(n*X[i])+Q[i]*cos(n*X[i])*n)/n^2/Pi, C0 = 1/2*(1/2*K[i]*(X[i+1]^2-X[i]^2)+Q[i]*(X[i+1]...

>    assign(sol2);

>    C0:=simplify(sum(C0,i=1..N-1)); and summarized for all line segments

C0 := -1/4/Pi*sum(-K[i]*X[i+1]^2+K[i]*X[i]^2-2*Q[i]*X[i+1]+2*Q[i]*X[i],i = 1 .. N-1)

>    Cn:=simplify(sum(Cn,i=1..N-1));

Cn := -1/n^2/Pi*sum(-K[i]*cos(n*X[i+1])-K[i]*n*X[i+1]*sin(n*X[i+1])-sin(n*X[i+1])*Q[i]*n+K[i]*cos(n*X[i])+K[i]*n*X[i]*sin(n*X[i])+sin(n*X[i])*Q[i]*n,i = 1 .. N-1)

>    Sn:=simplify(sum(Sn,i=1..N-1));

Sn := 1/n^2/Pi*sum(K[i]*sin(n*X[i+1])-K[i]*n*X[i+1]*cos(n*X[i+1])-Q[i]*cos(n*X[i+1])*n-K[i]*sin(n*X[i])+K[i]*n*X[i]*cos(n*X[i])+Q[i]*cos(n*X[i])*n,i = 1 .. N-1)

>    kq:=solve({Y[i]=K[i]*X[i]+Q[i],Y[i+1]=K[i]*X[i+1]+Q[i]},{K[i],Q[i]}); K[i]  and Q[i]  can be computed from the coordinates of the initial and final point of the line segments.

kq := {Q[i] = (-Y[i]*X[i+1]+X[i]*Y[i+1])/(-X[i+1]+X[i]), K[i] = (-Y[i+1]+Y[i])/(-X[i+1]+X[i])}

Sense of the procedure

>    P1:=plot(zip((x,y)->[x,y],X,Y),color=blue): The line plot

>    FOURIER(X,Y,40);  Coefficients generation

"Computing 40 Fouriere's coefficients"

X0 = -.1328943774e-7

Cx[1] = 2.900225949, Sx[1] = .1419823020

Cx[40] = .4754955872e-3, Sx[40] = .3202506275e-2

Y0 = .3724225667e-7

Cy[1] = .6723654211e-1, Sy[1] = -1.715950597

Cy[40] = .1312131189e-2, Sy[40] = .1486127291e-2

>    Fx:=sum(Cx[i]*cos(i*x)+Sx[i]*sin(i*x),i=1..40):  Fourier series describing x(p)

>    Fy:=sum(Cy[i]*cos(i*x)+Sy[i]*sin(i*x),i=1..40):  Fourier series describing y(p)

>    P2:=plot([Fx,Fy,x=0..2*Pi],color=red,numpoints=600):  parametric plot

>    plots[display]({P1,P2},scaling=constrained,title="Graphical comaprison");

[Maple Plot]

>    L:=[0.]: Computation of the paremeters coressponding to the vertices

>    for j from 2 to N do;   L:=[L[],L[j-1]+sqrt((X[j-1]-X[j])^2+(Y[j-1]-Y[j])^2)];
od:

>    L:=map(u->evalf(2*Pi*u/L[N]),L):

>    plot([zip((x,y)->[x,y],L,X),zip((x,y)->[x,y],L,Y),Fx,Fy],x=0..2*Pi,color=[blue,red,navy,brown],title="Oak (like a sine and cosine) functions",legend=["x lin. segm.","x(p) Fouriere","y lin. segm.","x(p) Fouriere"]);

[Maple Plot]

>    R:=zip((x,y)->sqrt(x^2+y^2),X,Y):  Distances of the vertices

>    F:=map(u->evalf(subs(x=u,sqrt(Fx^2+Fy^2))),L):  Distances of the point corresponding with vertices

>    RE:=zip((x,y)->(1-y/x)*100,R,F):  The relative errors

>    Var:=sqrt(sum(RE[i]^2,i=1..N)/N):  The variance of the relative errors

>    plot([zip((x,y)->[x,y],L,RE),[[0,Var],[2*Pi,Var]],[[0,-Var],[2*Pi,-Var]]],color=[red,blue,blue],title="The relative error of the distance from the origin and its variance",labels=["Perimeter's parameter","%"]);

[Maple Plot]

Increasing the number of the Fourier coefficients decreases the error of the approximation.

>   

Processing

>    DXFREAD(cat(File,".dxf"));

`"Converting DXF file into lists of coordinates of vertices"`

`"574 vertices found"`

>   

>    SOLAO(X,Y);

`"Looking for center and axis of symmetry"`

`"Shift =[-12.21275220, -9.483011334]"`

`"Rotation = 3.418483572*degrees"`

>   

>    PHASE0(X,Y);

`"Setting 0 to initial phase"`

`"Zero point = [9.226803319, 0]"`

>   

>    FOURIER(X,Y,50);

`"Computing 50 Fouriere's coefficients"`

`X0 = -.2212253708e-6`

`Cx[1] = 8.672002591, Sx[1] = -1.017347828`

`Cx[50] = -.1191587246e-1, Sx[50] = -.1287842212e-1`

`Y0 = .1917817064e-6`

`Cy[1] = -.8152692550, Sy[1] = -6.792215980`

`Cy[50] = .2360530589e-1, Sy[50] = -.1289477692e-1`

>   

>    plots[display]({plot(zip((x,y)->[x,y],X,Y),color=blue),
                plot([sum(Cx[i]*cos(i*x)+Sx[i]*sin(i*x),i=1..nops(Cx)),
                sum(Cy[i]*cos(i*x)+Sy[i]*sin(i*x),i=1..nops(Cy)),x=0..2*Pi],
                color=red)},scaling=constrained);

[Maple Plot]

>    save X0, Cx, Sx, Y0, Cy, Sy, cat(File,".sav");

>   

Part 2:  - Computation of the transformation parameters, (mutual rotation, shift, rescaling and phase shift) of two different objects using Least Square Method and computing of the Coefficient of the Linear Correlation,.

>   

Theory:  The Least Square Method is used to determine the parameters of the transformation. These parameters are:

      K  = rescaling of the first object

     Dx, Dy  = shift of the first object in x  and y

     a   = rotation of the second object
    
f  = phase shift of the second object,

which will minimize IR2 = Int((Dx+Fx(p)*cos(a)+Fy(p)*sin(a)-K*Gx(p+f))^2+(Dy-Fx(p)*sin(a)+Fy(p)*cos(a)-K*Gy(p+f))^2,p = 0 .. 2*Pi) .

With respect to ortogonality of individual terms of Fourier series creating Fx, Fy, Gx  and Gy,  it is possible to use a lot of simplifications leading to an exact analytical value of the integral mentioned above. The analytical solution of   a, Dx, Dy  a K  can be determined from this value. The value of f  can be found by its direct minimization.

If the exact values of transformation are known, it is possible to create new transformed functions FX, FY, GX  and GY , where:
     
FX(p) = Dx+Fx(p)*cos(a)+Fy(p)*sin(a) ,

      FY(p) = Dy-Fx(p)*sin(a)+Fy(p)*cos(a)

      GX(p) = K*Gx(p+f) .

      GY(p) = K*Gy(p+f)  

Similarity of the transformed objects will be described by the coefficient of the linear correlation computed below.

      R1(p) = sqrt(FX(p)^2+FY(p)^2) ,      R2(p) = sqrt(GX(p)^2+Gy(p)^2) ,     

      P1 = Int(R1(p),p = 0 .. 2*Pi)/2/Pi ,      P2 = Int(R1(p),p = 0 .. 2*Pi)/2/Pi ,

      V1 = Int((R1(p)-P1)^2,p = 0 .. 2*Pi)/2/Pi ,      V2 = Int((R2(p)-P2)^2,p = 0 .. 2*Pi)/2/Pi ,

      C12 = Int((R1(p)-P1)*(R2(p)-P2),p = 0 .. 2*Pi)/2/Pi ,

      LinCor = C12/sqrt(V1*V2)

>   

Reading of the procedures

>    restart;

>    read `KAF.pro`:

>   

Procedure KAF

Procedure KAF computes parameters of the transformation of two objects, resulting in a maximal similarity of both objects. The computation will be finished when the step size of the variable f , (see main page) is lower than a desired correctness = the third parameter.. The fourth, optional parameter is the number of lines connecting the corresponding points on perimeters of both transformed objects. If value of this parameter is 0 , both transformed objects are plotted without lines. If this parameter is missing, the  procedure will not create graphical output. The procedure creates new parametric dependent functions describing both transformed objects, saved as new global variables x1, y1, x2  and y2 .

Entries of the procedure are filenames containing coefficients of the Fourier equations describing the first and second object. The third parameter is the desired correctness step of
f . The four optional parameter controls graphical output.

KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...
KAF := proc (File1, File2, eps, Lines) local S, C1x, C1y, S1x, S1y, N1, N2, C2x, C2y, S2x, S2y, Min, MIN, LSQM, f, rc, df, k, c1x, c2x, c1y, c2y, s1x, s2x, s1y, s2y, P1, P2, P3, L; global a, K, N, x1, ...

Derivation of the procedure KAF

>    restart;

Simplified functions describing x and y  coordinates of the first (Fx, Fy)  and second (Gx, Gy)  objects

>    Fx:=CFx[i]*cos(i*x)+CFx[j]*cos(j*x)+SFx[i]*sin(i*x)+SFx[j]*sin(j*x);

Fx := CFx[i]*cos(i*x)+CFx[j]*cos(j*x)+SFx[i]*sin(i*x)+SFx[j]*sin(j*x)

>    Fy:=CFy[i]*cos(i*x)+CFy[j]*cos(j*x)+SFy[i]*sin(i*x)+SFy[j]*sin(j*x);

Fy := CFy[i]*cos(i*x)+CFy[j]*cos(j*x)+SFy[i]*sin(i*x)+SFy[j]*sin(j*x)

>    Gx:=CGx[i]*cos(i*x)+CGx[j]*cos(j*x)+SGx[i]*sin(i*x)+SGx[j]*sin(j*x);

Gx := CGx[i]*cos(i*x)+CGx[j]*cos(j*x)+SGx[i]*sin(i*x)+SGx[j]*sin(j*x)

>    Gy:=CGy[i]*cos(i*x)+CGy[j]*cos(j*x)+SGy[i]*sin(i*x)+SGy[j]*sin(j*x);

Gy := CGy[i]*cos(i*x)+CGy[j]*cos(j*x)+SGy[i]*sin(i*x)+SGy[j]*sin(j*x)

The first object will be rotated through angle  a and shifted by Dx and  Dy.

>    FX:=Dx+expand(Fx*cos(a)+Fy*sin(a)); FY:=Dy+expand(-Fx*sin(a)+Fy*cos(a));

FX := Dx+cos(a)*CFx[i]*cos(i*x)+cos(a)*CFx[j]*cos(j*x)+cos(a)*SFx[i]*sin(i*x)+cos(a)*SFx[j]*sin(j*x)+sin(a)*CFy[i]*cos(i*x)+sin(a)*CFy[j]*cos(j*x)+sin(a)*SFy[i]*sin(i*x)+sin(a)*SFy[j]*sin(j*x)
FX := Dx+cos(a)*CFx[i]*cos(i*x)+cos(a)*CFx[j]*cos(j*x)+cos(a)*SFx[i]*sin(i*x)+cos(a)*SFx[j]*sin(j*x)+sin(a)*CFy[i]*cos(i*x)+sin(a)*CFy[j]*cos(j*x)+sin(a)*SFy[i]*sin(i*x)+sin(a)*SFy[j]*sin(j*x)

FY := Dy-sin(a)*CFx[i]*cos(i*x)-sin(a)*CFx[j]*cos(j*x)-sin(a)*SFx[i]*sin(i*x)-sin(a)*SFx[j]*sin(j*x)+cos(a)*CFy[i]*cos(i*x)+cos(a)*CFy[j]*cos(j*x)+cos(a)*SFy[i]*sin(i*x)+cos(a)*SFy[j]*sin(j*x)
FY := Dy-sin(a)*CFx[i]*cos(i*x)-sin(a)*CFx[j]*cos(j*x)-sin(a)*SFx[i]*sin(i*x)-sin(a)*SFx[j]*sin(j*x)+cos(a)*CFy[i]*cos(i*x)+cos(a)*CFy[j]*cos(j*x)+cos(a)*SFy[i]*sin(i*x)+cos(a)*SFy[j]*sin(j*x)

The phase of the second object will be shifted by f  and object will be rescaled by a factor of K  

>    GX:=expand(subs(x=x+f,K*Gx));

GX := K*CGx[i]*cos(i*x)*cos(i*f)-K*CGx[i]*sin(i*x)*sin(i*f)+K*CGx[j]*cos(j*x)*cos(j*f)-K*CGx[j]*sin(j*x)*sin(j*f)+K*SGx[i]*sin(i*x)*cos(i*f)+K*SGx[i]*cos(i*x)*sin(i*f)+K*SGx[j]*sin(j*x)*cos(j*f)+K*SGx[...
GX := K*CGx[i]*cos(i*x)*cos(i*f)-K*CGx[i]*sin(i*x)*sin(i*f)+K*CGx[j]*cos(j*x)*cos(j*f)-K*CGx[j]*sin(j*x)*sin(j*f)+K*SGx[i]*sin(i*x)*cos(i*f)+K*SGx[i]*cos(i*x)*sin(i*f)+K*SGx[j]*sin(j*x)*cos(j*f)+K*SGx[...

>    GY:=expand(subs(x=x+f,K*Gy));

GY := K*CGy[i]*cos(i*x)*cos(i*f)-K*CGy[i]*sin(i*x)*sin(i*f)+K*CGy[j]*cos(j*x)*cos(j*f)-K*CGy[j]*sin(j*x)*sin(j*f)+K*SGy[i]*sin(i*x)*cos(i*f)+K*SGy[i]*cos(i*x)*sin(i*f)+K*SGy[j]*sin(j*x)*cos(j*f)+K*SGy[...
GY := K*CGy[i]*cos(i*x)*cos(i*f)-K*CGy[i]*sin(i*x)*sin(i*f)+K*CGy[j]*cos(j*x)*cos(j*f)-K*CGy[j]*sin(j*x)*sin(j*f)+K*SGy[i]*sin(i*x)*cos(i*f)+K*SGy[i]*cos(i*x)*sin(i*f)+K*SGy[j]*sin(j*x)*cos(j*f)+K*SGy[...

Squared distance of the corresponding points of the first and second objects = squared residual. Output is too long, so it is not presented.

>    R2:=expand((FX-GX)^2+(FY-GY)^2):

>    assume(i,integer); assume(j,integer); Arguments of Fourier series contains always integer multiple of 2 Pi .

>    R21:=map(u->simplify(Int(u,x=0..2*Pi)),R2): Integral of residuals. Values of Dx, Dy, K, a  and f , minimizing its value are to be found. Output is too long, it contains 262  integrals.

>    sigma:=selectfun(R21,Int); But only 15  of them are individual

sigma := {Int(-1+cos(j*x)^2,x = 0 .. 2*Pi), Int(cos(j*x)*sin(j*x),x = 0 .. 2*Pi), Int(cos(j*x),x = 0 .. 2*Pi), Int(cos(i*x)*sin(j*x),x = 0 .. 2*Pi), Int(cos(i*x)*sin(i*x),x = 0 .. 2*Pi), Int(cos(i*x)^2...
sigma := {Int(-1+cos(j*x)^2,x = 0 .. 2*Pi), Int(cos(j*x)*sin(j*x),x = 0 .. 2*Pi), Int(cos(j*x),x = 0 .. 2*Pi), Int(cos(i*x)*sin(j*x),x = 0 .. 2*Pi), Int(cos(i*x)*sin(i*x),x = 0 .. 2*Pi), Int(cos(i*x)^2...
sigma := {Int(-1+cos(j*x)^2,x = 0 .. 2*Pi), Int(cos(j*x)*sin(j*x),x = 0 .. 2*Pi), Int(cos(j*x),x = 0 .. 2*Pi), Int(cos(i*x)*sin(j*x),x = 0 .. 2*Pi), Int(cos(i*x)*sin(i*x),x = 0 .. 2*Pi), Int(cos(i*x)^2...

>    Su:=[seq(sigma[k]=Sigma[k],k=1..nops(sigma))]; Substitution for the integrals

Su := [Int(-1+cos(j*x)^2,x = 0 .. 2*Pi) = Sigma[1], Int(cos(j*x)*sin(j*x),x = 0 .. 2*Pi) = Sigma[2], Int(cos(j*x),x = 0 .. 2*Pi) = Sigma[3], Int(cos(i*x)*sin(j*x),x = 0 .. 2*Pi) = Sigma[4], Int(cos(i*x...
Su := [Int(-1+cos(j*x)^2,x = 0 .. 2*Pi) = Sigma[1], Int(cos(j*x)*sin(j*x),x = 0 .. 2*Pi) = Sigma[2], Int(cos(j*x),x = 0 .. 2*Pi) = Sigma[3], Int(cos(i*x)*sin(j*x),x = 0 .. 2*Pi) = Sigma[4], Int(cos(i*x...
Su := [Int(-1+cos(j*x)^2,x = 0 .. 2*Pi) = Sigma[1], Int(cos(j*x)*sin(j*x),x = 0 .. 2*Pi) = Sigma[2], Int(cos(j*x),x = 0 .. 2*Pi) = Sigma[3], Int(cos(i*x)*sin(j*x),x = 0 .. 2*Pi) = Sigma[4], Int(cos(i*x...
Su := [Int(-1+cos(j*x)^2,x = 0 .. 2*Pi) = Sigma[1], Int(cos(j*x)*sin(j*x),x = 0 .. 2*Pi) = Sigma[2], Int(cos(j*x),x = 0 .. 2*Pi) = Sigma[3], Int(cos(i*x)*sin(j*x),x = 0 .. 2*Pi) = Sigma[4], Int(cos(i*x...

>    Bs:=map(u->rhs(u)=value(lhs(u)),Su); Back substitution, only 5 are not zero

Bs := [Sigma[1] = -Pi, Sigma[2] = 0, Sigma[3] = 0, Sigma[4] = 0, Sigma[5] = 0, Sigma[6] = Pi, Sigma[7] = 0, Sigma[8] = -Pi, Sigma[9] = 0, Sigma[10] = Pi, Sigma[11] = 0, Sigma[12] = 0, Sigma[13] = 2*Pi,...

>    R22:=subs(Su,R21): Integrals are substituted, still too long

>    R23:=subs(Bs,R22);  Values of the integrals are substituted. Simple and short.
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...
R23 := K^2*SGy[i]^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+K^2*SGx[j]^2*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi+CFx[i]^2*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+2*s...

>    W1:=selectfun(R23,`^`); Squared terms are extracted

W1 := {Dx^2, Dy^2, CFx[i]^2, CFx[j]^2, CFy[i]^2, CFy[j]^2, SFy[j]^2, SFy[i]^2, SFx[i]^2, SFx[j]^2, K^2, SGy[i]^2, SGx[j]^2, CGy[i]^2, CGx[j]^2, CGx[i]^2, SGx[i]^2, CGy[j]^2, SGy[j]^2}
W1 := {Dx^2, Dy^2, CFx[i]^2, CFx[j]^2, CFy[i]^2, CFy[j]^2, SFy[j]^2, SFy[i]^2, SFx[i]^2, SFx[j]^2, K^2, SGy[i]^2, SGx[j]^2, CGy[i]^2, CGx[j]^2, CGx[i]^2, SGx[i]^2, CGy[j]^2, SGy[j]^2}

>    W11:=select(has,W1,[i,j]);  Indexed variables are extracted

W11 := {CFx[i]^2, CFx[j]^2, CFy[i]^2, CFy[j]^2, SFy[j]^2, SFy[i]^2, SFx[i]^2, SFx[j]^2, SGy[i]^2, SGx[j]^2, CGy[i]^2, CGx[j]^2, CGx[i]^2, SGx[i]^2, CGy[j]^2, SGy[j]^2}

>    W12:=map(u->factor(u),collect(select(has,R23,W11),K));  , These terms are removed, and converted into a proper summation.

W12 := Pi*(SGy[i]^2+SGx[j]^2+CGy[i]^2+CGx[j]^2+CGx[i]^2+SGx[i]^2+CGy[j]^2+SGy[j]^2)*K^2+CFx[i]^2*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+SFy[j]^2*Pi+SFy[i]^2*Pi+SFx[i]^2*Pi+SFx[j]^2*Pi
W12 := Pi*(SGy[i]^2+SGx[j]^2+CGy[i]^2+CGx[j]^2+CGx[i]^2+SGx[i]^2+CGy[j]^2+SGy[j]^2)*K^2+CFx[i]^2*Pi+CFx[j]^2*Pi+CFy[i]^2*Pi+CFy[j]^2*Pi+SFy[j]^2*Pi+SFy[i]^2*Pi+SFx[i]^2*Pi+SFx[j]^2*Pi

>    R24:=R23-expand(W12)+Pi*sum(C1x[k]^2+C1y[k]^2+S1x[k]^2+S1y[k]^2,k=1..N)
            +Pi*K^2*sum(C2x[k]^2+C2y[k]^2+S2x[k]^2+S2y[k]^2,k=1..N);
 This summation will replace old terms in R23 .
R24 := 2*Dx^2*Pi+2*Dy^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi-2*cos(a)*CFx[j]*K*CGx[j]*c...
R24 := 2*Dx^2*Pi+2*Dy^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi-2*cos(a)*CFx[j]*K*CGx[j]*c...
R24 := 2*Dx^2*Pi+2*Dy^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi-2*cos(a)*CFx[j]*K*CGx[j]*c...
R24 := 2*Dx^2*Pi+2*Dy^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi-2*cos(a)*CFx[j]*K*CGx[j]*c...
R24 := 2*Dx^2*Pi+2*Dy^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi-2*cos(a)*CFx[j]*K*CGx[j]*c...
R24 := 2*Dx^2*Pi+2*Dy^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi-2*cos(a)*CFx[j]*K*CGx[j]*c...
R24 := 2*Dx^2*Pi+2*Dy^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi-2*cos(a)*CFx[j]*K*CGx[j]*c...
R24 := 2*Dx^2*Pi+2*Dy^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi-2*cos(a)*CFx[j]*K*CGx[j]*c...
R24 := 2*Dx^2*Pi+2*Dy^2*Pi-2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi-2*cos(a)*CFy[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*CFy[i]*K*CGy[i]*cos(i*f)*Pi+2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi-2*cos(a)*CFx[j]*K*CGx[j]*c...

>    W1:=select(has,R24,CFx);  Simplification of terms containing  CFx

W1 := -2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi-2*cos(a)*CFx[j]*K*CGx[j]*cos(j*f)*Pi+2*sin(a)*CFx[j]*K*SGy[j]*sin(j*f)*Pi+2*sin(a)*CFx[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*...
W1 := -2*cos(a)*CFx[i]*K*CGx[i]*cos(i*f)*Pi+2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi-2*cos(a)*CFx[j]*K*CGx[j]*cos(j*f)*Pi+2*sin(a)*CFx[j]*K*SGy[j]*sin(j*f)*Pi+2*sin(a)*CFx[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*...

>    W12:=factor(select(has,W1,CGx));

W12 := -2*cos(a)*K*Pi*(CFx[i]*CGx[i]*cos(i*f)+cos(j*f)*CGx[j]*CFx[j])

>    W13:=-2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k=1..N);

W13 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)

>    W2:=W1-expand(W12)+W13;

W2 := 2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi+2*sin(a)*CFx[j]*K*SGy[j]*sin(j*f)*Pi+2*sin(a)*CFx[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*CFx[j]*K*SGx[j]*sin(j*f)*Pi-2*cos(a)*CFx[i]*K*SGx[i]*sin(i*f)*Pi+2*sin(a)*C...
W2 := 2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi+2*sin(a)*CFx[j]*K*SGy[j]*sin(j*f)*Pi+2*sin(a)*CFx[j]*K*CGy[j]*cos(j*f)*Pi-2*cos(a)*CFx[j]*K*SGx[j]*sin(j*f)*Pi-2*cos(a)*CFx[i]*K*SGx[i]*sin(i*f)*Pi+2*sin(a)*C...

>    W12:=factor(select(has,W2,CGy));

W12 := 2*sin(a)*K*Pi*(cos(j*f)*CGy[j]*CFx[j]+CFx[i]*CGy[i]*cos(i*f))

>    W13:=2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k=1..N);

W13 := 2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)

>    W3:=W2-expand(W12)+W13;

W3 := 2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi+2*sin(a)*CFx[j]*K*SGy[j]*sin(j*f)*Pi-2*cos(a)*CFx[j]*K*SGx[j]*sin(j*f)*Pi-2*cos(a)*CFx[i]*K*SGx[i]*sin(i*f)*Pi-2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 ...
W3 := 2*sin(a)*CFx[i]*K*SGy[i]*sin(i*f)*Pi+2*sin(a)*CFx[j]*K*SGy[j]*sin(j*f)*Pi-2*cos(a)*CFx[j]*K*SGx[j]*sin(j*f)*Pi-2*cos(a)*CFx[i]*K*SGx[i]*sin(i*f)*Pi-2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 ...

>    W12:=factor(select(has,W3,SGy));

W12 := 2*Pi*sin(a)*K*(CFx[i]*SGy[i]*sin(i*f)+sin(j*f)*SGy[j]*CFx[j])

>    W13:=2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k=1..N);

W13 := 2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)

>    W4:=W3-expand(W12)+W13;

W4 := -2*cos(a)*CFx[j]*K*SGx[j]*sin(j*f)*Pi-2*cos(a)*CFx[i]*K*SGx[i]*sin(i*f)*Pi-2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*...
W4 := -2*cos(a)*CFx[j]*K*SGx[j]*sin(j*f)*Pi-2*cos(a)*CFx[i]*K*SGx[i]*sin(i*f)*Pi-2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*...

>    W12:=factor(select(has,W4,SGx));

W12 := -2*cos(a)*K*Pi*(CFx[j]*SGx[j]*sin(j*f)+sin(i*f)*SGx[i]*CFx[i])

>    W13:=-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*sin(k*f),k=1..N);

W13 := -2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*sin(k*f),k = 1 .. N)

>    W5:=W4-expand(W12)+W13;

W5 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*sin...
W5 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*sin...

>    R25:=R24-W1+W5;

R25 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*si...
R25 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*si...
R25 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*si...
R25 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*si...
R25 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*si...
R25 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*si...
R25 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*si...
R25 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*si...
R25 := -2*cos(a)*Pi*K*sum(C1x[k]*C2x[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*C2y[k]*cos(k*f),k = 1 .. N)+2*sin(a)*Pi*K*sum(C1x[k]*S2y[k]*sin(k*f),k = 1 .. N)-2*cos(a)*Pi*K*sum(C1x[k]*S2x[k]*si...

>    W1:=select(has,R25,SFx): Simplification of terms containing SFx, ..... Because it is the same method as before, outputs will not be presented.

>    W12:=factor(select(has,W1,CGy)):

>    W13:=-2*sin(a)*Pi*K*sum(S1x[k]*C2y[k]*sin(k*f),k=1..N):

>    W2:=W1-expand(W12)+W13:

>    W12:=factor(select(has,W2,SGy)):

>    W13:=2*sin(a)*Pi*K*sum(S1x[k]*S2y[k]*cos(k*f),k=1..N):

>    W3:=W2-expand(W12)+W13:

>    W12:=factor(select(has,W3,CGx)):

>    W13:=2*cos(a)*Pi*K*sum(S1x[k]*C2x[k]*sin(k*f),k=1..N):

>    W4:=W3-expand(W12)+W13:

>    W12:=factor(select(has,W4,SGx)):

>    W13:=-2*cos(a)*Pi*K*sum(S1x[k]*S2x[k]*cos(k*f),k=1..N):

>    W5:=W4-expand(W12)+W13:

>    R26:=R25-W1+W5:

>    W1:=select(has,R26,CFy):  Atd. s CFy.

>    W12:=factor(select(has,W1,CGx)):

>    W13:=-2*sin(a)*Pi*K*sum(C1y[k]*C2x[k]*cos(k*f),k=1..N):

>    W2:=W1-expand(W12)+W13:

>    W12:=factor(select(has,W2,CGy)):

>    W13:=-2*cos(a)*Pi*K*sum(C1y[k]*C2y[k]*cos(k*f),k=1..N):

>    W3:=W2-expand(W12)+W13:

>    W12:=factor(select(has,W3,SGx)):

>    W13:=-2*sin(a)*Pi*K*sum(C1y[k]*S2x[k]*sin(k*f),k=1..N):

>    W4:=W3-expand(W12)+W13:

>    W12:=factor(select(has,W4,SGy)):

>    W13:=-2*cos(a)*Pi*K*sum(C1y[k]*C2y[k]*sin(k*f),k=1..N):

>    W5:=W4-expand(W12)+W13:

>    R27:=R26-W1+W5:

>    W1:=select(has,R27,SFy):  Atd. s SFy.

>    W12:=factor(select(has,W1,CGy)):

>    W13:=2*cos(a)*Pi*K*sum(S1y[k]*C2y[k]*sin(k*f),k=1..N):

>    W2:=W1-expand(W12)+W13:

>    W12:=factor(select(has,W2,CGx)):

>    W13:=2*sin(a)*Pi*K*sum(S1y[k]*C2x[k]*sin(k*f),k=1..N):

>    W3:=W2-expand(W12)+W13:

>    W12:=factor(select(has,W3,SGx)):

>    W13:=-2*sin(a)*Pi*K*sum(S1y[k]*S2x[k]*cos(k*f),k=1..N):

>    W4:=W3-expand(W12)+W13:

>    W12:=factor(select(has,W4,SGy)):

>    W13:=-2*cos(a)*Pi*K*sum(S1y[k]*S2y[k]*cos(k*f),k=1..N):

>    W5:=W4-expand(W12)+W13:

>    R28:=R27-W1+W5:

>    sigma:=selectfun(R28,sum);  Collection of summations of the final term R28

sigma := {sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N), sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N), sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N), sum(S1x[k]*C2x[k]*sin(k*f),k = 1 .. N), sum(S1y[k]*S2x[k]*cos(k*f),k = ...
sigma := {sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N), sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N), sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N), sum(S1x[k]*C2x[k]*sin(k*f),k = 1 .. N), sum(S1y[k]*S2x[k]*cos(k*f),k = ...
sigma := {sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N), sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N), sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N), sum(S1x[k]*C2x[k]*sin(k*f),k = 1 .. N), sum(S1y[k]*S2x[k]*cos(k*f),k = ...
sigma := {sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N), sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N), sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N), sum(S1x[k]*C2x[k]*sin(k*f),k = 1 .. N), sum(S1y[k]*S2x[k]*cos(k*f),k = ...

>    Su:=[seq(sigma[l]=Sigma[l],l=1..nops(sigma))];  Substitution

Su := [sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N) = Sigma[1], sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N) = Sigma[2], sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N) = Sigma[3], sum(S1x[k]*C2x[k]*sin(k*f),k = 1 .. N) = ...
Su := [sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N) = Sigma[1], sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N) = Sigma[2], sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N) = Sigma[3], sum(S1x[k]*C2x[k]*sin(k*f),k = 1 .. N) = ...
Su := [sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N) = Sigma[1], sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N) = Sigma[2], sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N) = Sigma[3], sum(S1x[k]*C2x[k]*sin(k*f),k = 1 .. N) = ...
Su := [sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N) = Sigma[1], sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N) = Sigma[2], sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N) = Sigma[3], sum(S1x[k]*C2x[k]*sin(k*f),k = 1 .. N) = ...
Su := [sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N) = Sigma[1], sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N) = Sigma[2], sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N) = Sigma[3], sum(S1x[k]*C2x[k]*sin(k*f),k = 1 .. N) = ...

>    Bs:=map(u->rhs(u)=lhs(u),Su);  and back substitution

Bs := [Sigma[1] = sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N), Sigma[2] = sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N), Sigma[3] = sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N), Sigma[4] = sum(S1x[k]*C2x[k]*sin(k*f),k =...
Bs := [Sigma[1] = sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N), Sigma[2] = sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N), Sigma[3] = sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N), Sigma[4] = sum(S1x[k]*C2x[k]*sin(k*f),k =...
Bs := [Sigma[1] = sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N), Sigma[2] = sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N), Sigma[3] = sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N), Sigma[4] = sum(S1x[k]*C2x[k]*sin(k*f),k =...
Bs := [Sigma[1] = sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N), Sigma[2] = sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N), Sigma[3] = sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N), Sigma[4] = sum(S1x[k]*C2x[k]*sin(k*f),k =...
Bs := [Sigma[1] = sum(S1y[k]*C2x[k]*sin(k*f),k = 1 .. N), Sigma[2] = sum(S1x[k]*S2x[k]*cos(k*f),k = 1 .. N), Sigma[3] = sum(C1y[k]*C2y[k]*cos(k*f),k = 1 .. N), Sigma[4] = sum(S1x[k]*C2x[k]*sin(k*f),k =...

>    R1:=subs(Su,R28);  Integral of the squared residuals is quite simple now.

R1 := -2*cos(a)*Pi*K*Sigma[2]-2*cos(a)*Pi*K*Sigma[6]+2*sin(a)*Pi*K*Sigma[9]-2*sin(a)*Pi*K*Sigma[5]-2*cos(a)*Pi*K*Sigma[3]-2*sin(a)*Pi*K*Sigma[7]-2*cos(a)*Pi*K*Sigma[10]+2*sin(a)*Pi*K*Sigma[8]-2*sin(a)*...
R1 := -2*cos(a)*Pi*K*Sigma[2]-2*cos(a)*Pi*K*Sigma[6]+2*sin(a)*Pi*K*Sigma[9]-2*sin(a)*Pi*K*Sigma[5]-2*cos(a)*Pi*K*Sigma[3]-2*sin(a)*Pi*K*Sigma[7]-2*cos(a)*Pi*K*Sigma[10]+2*sin(a)*Pi*K*Sigma[8]-2*sin(a)*...
R1 := -2*cos(a)*Pi*K*Sigma[2]-2*cos(a)*Pi*K*Sigma[6]+2*sin(a)*Pi*K*Sigma[9]-2*sin(a)*Pi*K*Sigma[5]-2*cos(a)*Pi*K*Sigma[3]-2*sin(a)*Pi*K*Sigma[7]-2*cos(a)*Pi*K*Sigma[10]+2*sin(a)*Pi*K*Sigma[8]-2*sin(a)*...

>    R1x:=diff(R1,Dx); R1y:=diff(R1,Dy); Normal equations for Dx  and Dy .

R1x := 4*Dx*Pi

R1y := 4*Dy*Pi

>    Dx:=0: Dy:=0:  No shift. Notice that absolute terms X0  and Y0  were not used to create Fx, Fy, Gx  and Gy .

>    R1K:=collect(simplify(diff(R1,K)/2/Pi),[sin,cos]);  Normal equation for K

R1K := (-Sigma[7]-Sigma[11]+Sigma[13]+Sigma[8]+Sigma[1]-Sigma[15]+Sigma[9]-Sigma[5])*sin(a)+(-Sigma[2]-Sigma[6]-Sigma[18]-Sigma[3]-Sigma[10]-Sigma[14]+Sigma[12]+Sigma[4])*cos(a)+K*Sigma[17]

>    Ksol:=K=collect(solve(R1K,K),[sin,cos]);  Solution for K

Ksol := K = -(-Sigma[7]-Sigma[11]+Sigma[13]+Sigma[8]+Sigma[1]-Sigma[15]+Sigma[9]-Sigma[5])/Sigma[17]*sin(a)-(-Sigma[2]-Sigma[6]-Sigma[18]-Sigma[3]-Sigma[10]-Sigma[14]+Sigma[12]+Sigma[4])/Sigma[17]*cos(...

>    R1a:=collect(simplify(diff(R1,a)/2/Pi),[sin,cos]);  Normal equation for a

R1a := K*(Sigma[10]+Sigma[6]-Sigma[12]+Sigma[14]+Sigma[3]+Sigma[2]-Sigma[4]+Sigma[18])*sin(a)+K*(-Sigma[7]-Sigma[11]+Sigma[13]+Sigma[8]+Sigma[1]-Sigma[15]+Sigma[9]-Sigma[5])*cos(a)

>    Asol:=a=solve(R1a,a);  Solution for a

Asol := a = -arctan((-Sigma[7]-Sigma[11]+Sigma[13]+Sigma[8]+Sigma[1]-Sigma[15]+Sigma[9]-Sigma[5])/(Sigma[10]+Sigma[6]-Sigma[12]+Sigma[14]+Sigma[3]+Sigma[2]-Sigma[4]+Sigma[18]))

>    R1c:=collect(simplify(R1/Pi),[sin,cos,K]);  It is necessary to find the value of f  minimizing this term. It is simpler to solve its normal equation, because all summations contains f .

R1c := (-2*Sigma[11]-2*Sigma[7]+2*Sigma[8]+2*Sigma[1]+2*Sigma[13]+2*Sigma[9]-2*Sigma[5]-2*Sigma[15])*K*sin(a)+(-2*Sigma[2]-2*Sigma[6]-2*Sigma[3]-2*Sigma[18]-2*Sigma[10]-2*Sigma[14]+2*Sigma[12]+2*Sigma[...
R1c := (-2*Sigma[11]-2*Sigma[7]+2*Sigma[8]+2*Sigma[1]+2*Sigma[13]+2*Sigma[9]-2*Sigma[5]-2*Sigma[15])*K*sin(a)+(-2*Sigma[2]-2*Sigma[6]-2*Sigma[3]-2*Sigma[18]-2*Sigma[10]-2*Sigma[14]+2*Sigma[12]+2*Sigma[...

>   

>    read `COREL.pro`:

>   

Procedure COREL

The procedure computes coefficients of linear correlation of two functions, R1(p)  and R2(p) . These functions are created from two pairs of input functions: R1(p) = sqrt(x1(p)^2+y1(p)^2)  and R2(p) = sqrt(x2(p)^2+y2(p)^2) , see main file for details. The Simpsons rule is used for numeric integration. As the coefficient of the linear correlation approaches 1, the similarity  increases. Zero value indicates no similarity of objects.

Entries of the procedure are four functions
x1(p), y1(p), x2(p)  and y2(p)  describing parameter dependence of x  and y  coordinate of the first and second object. The fifth parameter controls the relative accuracy of the numeric integration.

COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...
COREL := proc (x1, y1, x2, y2, eps) local R1, R2, P1, P2, V1, V2, C12, SIMPS; SIMPS := proc (F, eps) local delta, n, Q1, Q2, pi, j; delta := 10; n := 16; pi := evalf(Pi,25); Q1 := 0; for j from 0 to n-...

>   

>   

Processing

>    KAF(`Maple1.sav`,`Maple2.sav`,0.00001,360);

"f = .2,  df = .1,  MIN = 4.74937257675374613"

"f = .16784667968750,  df = -.1220703125e-4,  MIN = 4.69629115004216838"

"_____________________________________________"

"Rotation of Maple1.sav = 8.0004480430310438605*degrees"

"Phase shift of Maple2.sav = 9.6176057627489623335*degrees"

"Scale of Maple2.sav = 2.7941995986574304523"

[Maple Plot]

>    Similarity:=COREL(x1, y1, x2, y2, 0.001);

P1 = 7.912570760

V1 = 2.837610148

P2 = 7.785024297

V2 = 2.514006750

C12 = 1.944717629

Similarity := .7281099519

>   

Conclusion:

The presented algorithm can be used as an instrument to determine rate of similarity of simple two-dimensional objects. Its advantage is simplicity and possibility of conversion into source files of other programming languages. These procedures were designed for minimization of computer memory consumption, and so Maple special functions were not used, because these functions cannot be used out of Maple.

As examples we used a couple of leaf types: Maple, Oak, and Pothos. Linear coefficients describing similarity of individual leaves are shown in the following table.

>   

NULL Maple1 Maple2 Oak1 Oak2 Pothos1 Pothos2
Maple1 NULL .73 .15 .27 .12 .24
Maple2 NULL NULL .41 .49 .36 .45
Oak1 NULL NULL NULL .92 .84 .91
Oak2 NULL NULL NULL NULL .83 .91
Pothos1 NULL NULL NULL NULL NULL .97

It is evident that leaves of the same variety are the most similar each to other. Similarity depends on leaf segmentation, of course

The algorithms were derived in the program Maple 7, running on the computer Autocont, PIV, 512 MB RAM

 5. 2. 2002