###############################################################################
# This maple script deliniates the derivation of the summands of the
# three dimensional isometric error term $F_{metric}^{3D}$.
# It uses an integral similar to equation (9) for a finite deformation
# induced by the map.

########################
restart;
with(LinearAlgebra):
assume(r,real,r>0);

# we consider the line segment S = (x0,y0,z0)->(x1,y1,z1)
x0 := 0;
y0 := 0;
z0 := 0;

x1 := x0 + r*rx;
y1 := y0 + r*ry;
z1 := z0 + r*rz;

# we apply a linear map to S and obtain SS = (xx0,yy0)->(xx1,yy1)
xx0 := x0*u_x + y0*u_y + z0*u_z;
yy0 := x0*v_x + y0*v_y + z0*v_z;
zz0 := x0*w_x + y0*w_y + z0*w_z;

xx1 := x1*u_x + y1*u_y + z1*u_z;
yy1 := x1*v_x + y1*v_y + z1*v_z;
zz1 := x1*w_x + y1*w_y + z1*w_z;


# we compare the lenth of S and SS: 
hh := factor(((xx1-xx0)^2 + (yy1-yy0)^2 + (zz1-zz0)^2) - ((x1-x0)^2 + (y1-y0)^2 + (z1-z0)^2));
hhh := factor(hh/r^2);

# this corresponds to equation (7) for a finite map
err := factor(int(int(cos(be)*eval(hhh,{rx=cos(al)*cos(be) , ry=sin(al)*cos(be) , rz=sin(be)})^2, be=-Pi/2..Pi/2),al=0..2*Pi)/(4*Pi));

J := Matrix([[u_x,u_y,u_z], [v_x,v_y,v_z],[w_x,w_y,w_z]]);
JT := Transpose(J);
E := Eigenvalues(Multiply(JT,J));

# singular values of Jacobian
s1 := E[1];
s2 := E[2];
s3 := E[3];

# this is an unweighted summand of $F_{metric}^{3D}$,
# we discard the scaling factor (1/3) for the error term.
eerr := (1/3)*( (1-s1)^2 + (1-s2)^2 + (1-s3)^2 - (1/5)*((s1 - s2)^2 + (s2 - s3)^2 + (s3 - s1)^2)):

factor(err-eerr);