trajectory.scad 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. use <so3.scad>
  2. function val(a=undef,default=undef) = a == undef ? default : a;
  3. function vec_is_undef(x,index_=0) = index_ >= len(x) ? true :
  4. is_undef(x[index_]) && vec_is_undef(x,index_+1);
  5. function is_undef(x) = len(x) > 0 ? vec_is_undef(x) : x == undef;
  6. // Either a or b, but not both
  7. function either(a,b,default=undef) = is_undef(a) ? (is_undef(b) ? default : b) : is_undef(b) ? a : undef;
  8. function translationv(left=undef,right=undef,up=undef,down=undef,forward=undef,backward=undef,translation=undef) =
  9. translationv_2(
  10. x = either(up,-down),
  11. y = either(right,-left),
  12. z = either(forward,-backward),
  13. translation = translation);
  14. function translationv_2(x,y,z,translation) =
  15. x == undef && y == undef && z == undef ? translation :
  16. is_undef(translation) ? [val(x,0),val(y,0),val(z,0)]
  17. : undef;
  18. function rotationv(pitch=undef,yaw=undef,roll=undef,rotation=undef) =
  19. rotation == undef ? [val(yaw,0),val(pitch,0),val(roll,0)] :
  20. pitch == undef && yaw == undef && roll == undef ? rotation :
  21. undef;
  22. function trajectory(
  23. left=undef, right=undef,
  24. up=undef, down=undef,
  25. forward=undef, backward=undef,
  26. translation=undef,
  27. pitch=undef,
  28. yaw=undef,
  29. roll=undef,
  30. rotation=undef
  31. ) = concat(
  32. translationv(left=left,right=right,up=up,down=down,forward=forward,backward=backward,translation=translation),
  33. rotationv(pitch=pitch,yaw=yaw,roll=roll,rotation=rotation)
  34. );
  35. function rotationm(rotation=undef,pitch=undef,yaw=undef,roll=undef) = so3_exp(rotationv(rotation=rotation,pitch=pitch,yaw=yaw,roll=roll));