| // 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();
|
| }
|
|
|
| RotateFromTo([10, 4, 2], [1, 0, 0])
|
| cube([10, 4, 2]);
|
|
|
| translate([0, 5, 0])
|
| RotateFromTo([1, 0, 0], [1, 1, 1])
|
| cube([10, 4, 2]);
|
|
|
| translate([0, -5, 0])
|
| RotateFromTo([0.1, 0.1, 50], [-0.1, 0, 50])
|
| cube([10, 4, 2]);
|