\(\(Clear[t1, t2, t3]; 
alpha0\  = \ 0; \ a0\  = \ 0; \ d1\  = \ 0; 

    alpha1\  = \ \(-Pi\)/2; \ a1\  = \ 0; \ d2\  = \ 0; 
alpha2\  = \ 0; \ 
    a2\  = \ 7.84; \ d3\  = \ 5; 
alpha3\  = \ Pi/2; \ a3\  = \ 0; \ 
    d4\  = \ 8; 
alpha4\  = \ \(-Pi\)/2; \ a4\  = \ 0; \ d5 = \ 0; 

    alpha5\  = \ Pi/2; \ a5\  = \ 0; \ d6\  = \ 0; 

x\  = \ 6; 

    y\  = \ 6; 
z\  = \ \(-6\); 
r\  = \ x^2 + y^2 + z^2; 


    f1\  = \ a3\ Cos[t3]\  + \ d4\ Sin[alpha3]\ Sin[t3]\  + \ a2; 

    f2\  = \ a3\ Cos[alpha2]\ Sin[t3]\  - \ 
        d4\ Sin[alpha3]\ Cos[alpha2]\ Cos[t3]\  - \ 
        d4\ Sin[alpha2]\ Cos[alpha3]\  - \ d3\ Sin[alpha2]; 

    f3\  = \ a3\ Sin[alpha2]\ Sin[t3]\  - \ 
        d4\ Sin[alpha3]\ Sin[alpha2]\ Cos[t3]\  + \ 
        d4\ Cos[alpha2]\ Cos[alpha3]\  + \ d3\ Cos[alpha2]; 


    soln\  = \ 
      Solve[f1^2\  + \ f2^2\  + \ f3^2\  + \ a1^2\  + \ d2^2\  + \ 
            2\ d2\ f3\  == \ r, \ t3]; 
Print[soln]; 

    t3\  = \ t3 /. soln[\([2]\)]; 
Print["t3 = ", t3]; 
    
 (*
soln\  = \ 
        Solve[\((f1\ Sin[t2]\  + \ f2\ Cos[t2])\)\ Sin[alpha1]\  + \ 
              f3\ Cos[alpha1]\  + \ d2\ Cos[alpha1]\  == \ z, \ t2]; 

      Print[soln]; 
t2\  = \ t2 /. soln[\([2]\)]; 


      g1\  = \ Cos[t2]\ f1\  - \ Sin[t2]\ f2\  + \ a1; 

      g2\  = \ Sin[t2]\ Cos[alpha1]\ f1\  + \ Cos[t2]\ Cos[alpha1]\ f2\  - \ 
          Sin[alpha1]\ f3\  - \ d2\ Sin[alpha1]; 

      g3\  = \ Sin[t2]\ Sin[alpha1]\ f1\  + \ Cos[t2]\ Sin[alpha1]\ f2\  + \ 
          Cos[alpha1]\ f3\  + \ d2\ Cos[alpha1]; 


      soln\  = \ Solve[Cos[t1]\ g1\  - \ Sin[t1]\ g2\  == \ x, \ t1]; 
		
      Print[soln]; 

      soln\  = \ Solve[\ Sin[t1]\ g1\  + \ Cos[t1]\ g2\  == \ y, \ t1]; 
		
      Print[soln]; 
	*) \)\)

<< forward.m;

?? T

MatrixForm[
      Drop[Transpose[
            Drop[T[0, 0, 0, -0.345357577753175881]  .  
                T[-Pi/2, 0, 0, 1.69138249470619106]  .  
                T[0, 7.84, 5, 0.155260917332884034], -1]], -1]  . 
         {{-1/Sqrt[2], 0, 1/Sqrt[2]}, {0, 1, 0}, {1/Sqrt[2], 0, 
            1/Sqrt[2]}}]

T[0, 0, 0, -0.345357577753175881]  .  
      T[-Pi/2, 0, 0, 1.69138249470619106]  .  
      T[0, 7.84, 5, 0.155260917332884034]

MatrixForm[
      Simplify[T[Pi/2, 0, 8, t4] . T[-Pi/2, 0, 0, t5] . 
          T[Pi/2, 0, 0, t6]]]

t5  =  ArcCos[-0.447612325129763366]

f1

f2

f3