se3.scad 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. use <linalg.scad>
  2. use <so3.scad>
  3. function combine_se3_exp(w, ABt) = construct_Rt(rodrigues_so3_exp(w, ABt[0], ABt[1]), ABt[2]);
  4. // [A,B,t]
  5. function se3_exp_1(t,w) = concat(
  6. so3_exp_1(w*w),
  7. [t + 0.5 * cross(w,t)]
  8. );
  9. function se3_exp_2(t,w) = se3_exp_2_0(t,w,w*w);
  10. function se3_exp_2_0(t,w,theta_sq) =
  11. se3_exp_23(
  12. so3_exp_2(theta_sq),
  13. C = (1.0 - theta_sq/20) / 6,
  14. t=t,w=w);
  15. function se3_exp_3(t,w) = se3_exp_3_0(t,w,sqrt(w*w)*180/PI,1/sqrt(w*w));
  16. function se3_exp_3_0(t,w,theta_deg,inv_theta) =
  17. se3_exp_23(
  18. so3_exp_3_0(theta_deg = theta_deg, inv_theta = inv_theta),
  19. C = (1 - sin(theta_deg) * inv_theta) * (inv_theta * inv_theta),
  20. t=t,w=w);
  21. function se3_exp_23(AB,C,t,w) =
  22. [AB[0], AB[1], t + AB[1] * cross(w,t) + C * cross(w,cross(w,t)) ];
  23. function se3_exp(mu) = se3_exp_0(t=take3(mu),w=tail3(mu)/180*PI);
  24. function se3_exp_0(t,w) =
  25. combine_se3_exp(w,
  26. // Evaluate by Taylor expansion when near 0
  27. w*w < 1e-8
  28. ? se3_exp_1(t,w)
  29. : w*w < 1e-6
  30. ? se3_exp_2(t,w)
  31. : se3_exp_3(t,w)
  32. );
  33. function se3_ln(m) = se3_ln_to_deg(se3_ln_rad(m));
  34. function se3_ln_to_deg(v) = concat(take3(v),tail3(v)*180/PI);
  35. function se3_ln_rad(m) = se3_ln_0(m,
  36. rot = so3_ln_rad(rotation_part(m)));
  37. function se3_ln_0(m,rot) = se3_ln_1(m,rot,
  38. theta = sqrt(rot*rot));
  39. function se3_ln_1(m,rot,theta) = se3_ln_2(m,rot,theta,
  40. shtot = theta > 0.00001 ? sin(theta/2*180/PI)/theta : 0.5,
  41. halfrotator = so3_exp_rad(rot * -.5));
  42. function se3_ln_2(m,rot,theta,shtot,halfrotator) =
  43. concat( (halfrotator * translation_part(m) -
  44. (theta > 0.001
  45. ? rot * ((translation_part(m) * rot) * (1-2*shtot) / (rot*rot))
  46. : rot * ((translation_part(m) * rot)/24)
  47. )) / (2 * shtot), rot);
  48. __se3_test = [20,-40,60,-80,100,-120];
  49. echo(UNITTEST_se3=norm(__se3_test-se3_ln(se3_exp(__se3_test))) < 1e-8);