The following code rotates the second cube around the origin. How can I rotate the second cube around its center point ([5,5,0]) instead?
cube([10,10,1]);
rotate([0,0,45]) cube([10,10,1]);
This module will perform the desired rotation.
// rotate as per a, v, but around point pt
module rotate_about_pt(a, v, pt) {
translate(pt)
rotate(a,v)
translate(-pt)
children();
}
cube([10,10,1]);
rotate_about_pt(45,0,[5,5,0]) cube([10,10,1]);
In newer versions (tested with the January 2019 preview) the above code generates a warning. To fix that, update the parameters to rotate
:
module rotate_about_pt(z, y, pt) {
translate(pt)
rotate([0, y, z]) // CHANGE HERE
translate(-pt)
children();
}
If you are willing to 'center' the shape it is much easier:
cube(center =true,[10,10,1]);
rotate([0,0,45]) cube(center =true,[10,10,1]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With