%%                        MTEX Workshop 2020
%
%%                         Exercises Day 1
%
%% Exercise 1.0 - Matlab Basics
%
%% a)
% Generate a list of all square numbers from 1 to 20.


%% b)
% Single out all even square numbers.


%% c)
% Compute the sum over the reciprocals of all square numbers. Is there a
% limit if the numbers go to infinity?


%% d)
% Compute the alternating sum of the reciprocals of the even and odd
% squares: 1/1^2 - 1/2^2 + 1/3^2 - 1/4^2 + 1/5^2 .....
% What is the limit? Hint: it is a multiple of pi^2.


%% Exercise 1.1
%
%% a)
% Visualize the two vectors u1 = (1,0,2) and u2 = (2,3,-1) and determine
% the angle between these two vectors.

%% b)
% Find a third vector u3 that is orthogonal to u1 and u2.


%% c)
% Normalize u1, u2, u3 such that they form an orthonormal basis. How can we
% check that u1, u2, u3 form a right handed basis?


%% d)
% Perform the steps a) and b) also with the vectors v1 = (1,1,1) and v2 =
% (1,1,-2) and find the matrix M of the active rotation that maps u1 to v1 
% and u2 to v2.

%% e)
% Could we have replaced v2 by (1,1,-1)?

%% f)
% Transform the matrix M into a MTEX rotation and compute its rotational
% axis and its rotational angle.


%% g)
% Set up an arbitrary rotation matrix M2 and verify that the following two
% lines yield the same result. Why?

M * M2
matrix(rotation.byMatrix(M) * rotation.byMatrix(M2))

%% Exercise 1.2
%
%% a)
% Define the rotation with the Euler angles (10, 20, 30) without using the
% command rotation.byEuler. 

%% b)
% Visualize the rotation in 3d Euler angle space.

%% c)
% Visualize the rotation in Euler angle sections.

%% Exercise 1.3
%
%% a)
% Generate two random rotations rot1 and rot2 and visualize them in a three
% dimensional axis angle plot and in the three dimensional Euler angle
% plot.

%% b)
% Determine the misrotation angle delta between rot1 and rot2.

%% c)
% Determine a rotation rotM such that misrotation angles between rot and
% rot1 and rot and rot2 are both delta/2. Highlight rotM in the two plots
% of a) as a red square.

%% d)
% Find a list rotL of 101 rotations that gradualy change from rot1 to rot2,
% i.e., rotL(1) = rot1, rot(101) = rot2; rotL(51) = rotM. Visualize this
% line. 

%% e)
% Determine as many rotations rotP as posible such that the distances
% between (rotP,rot1) and (rotP,rot2) are equal.

%% f)
% Recreate the above plot in Euler angle space and Rodrigues Frank space.

%% Exercise 1.4
%
%% a)
% Generate random pairs of rotations with misrotation angle delta = 20
% degree.

%% b) 
% Plot these pairs of rotations as lines in a three dimensional Euler angle
% plot

%% c) 
% Plot these pairs of rotations as lines in a three dimensional axis angle
% plot.

%% Exercise 1.5
%
% Consider the following Quartz crystal

cs = crystalSymmetry.load('quartz.cif')

cS = crystalShape.quartz

plot(cS,'colored')

%% a)
% Visualize the normals of the planes positive rhomboedron (1,0,-1,1), the
% negative rhomboedron (0,1,-1,1) and left tridiagonal bipyramid (1,1,-2,1)
% in a equal angle projection. Colorize them as in the crystal shape plot
% and label them nicely.

%% b)
% Visualize the traces of the coresponding planes.
%
% useful command: circle 

%% c)
% Determine all angles between the above planes.

%% d)
% Determine the directions of the intersections between the above planes
% and visualize them in a spherical projection.
