// Created in 2021 by Ryan A. Colyer. // This work is released with CC0 into the public domain. // https://creativecommons.org/publicdomain/zero/1.0/ // Rotate children to reorient vector "from" toward "to". // Uses the rotation which preserves the xy plane orientation. module RotateFromTo(from, to) { rotate([0, 0, atan2(to[1], to[0])]) rotate([0, -atan2(sqrt(to[0]^2 + to[1]^2), -to[2]), 0]) rotate([0, atan2(sqrt(from[0]^2 + from[1]^2), -from[2]), 0]) rotate([0, 0, -atan2(from[1], from[0])]) children(); } module RotateFromToSteps(from, to, step_num, last_step) { f = step_num/last_step; rotate(f*[0, 0, atan2(to[1], to[0])]) rotate(f*[0, -atan2(sqrt(to[0]^2 + to[1]^2), -to[2]), 0]) rotate(f*[0, atan2(sqrt(from[0]^2 + from[1]^2), -from[2]), 0]) rotate(f*[0, 0, -atan2(from[1], from[0])]) children(); } for (i=[0:7]) { RotateFromToSteps([1, 0, 0], [0, 1, 1], i, 7) cube([10, 4, 2]); }