Nabble has removed Mailing-list integration.
Posts created here DO NOT GET SENT TO THE MAILING LIST.
Mailing-list emails DO NOT GET POSTED TO THE FORUM.
So basically the Forum is now out of date, we are looking into migrating the history.

# cube rotate on another cube edge Classic List Threaded 8 messages Open this post in threaded view
|

## cube rotate on another cube edge

 Hello all, I am a newbie in OpenSCAD.  A few objects have worked well. Now I come to a problem that I can not fix. I have a bar of 100 and I want to bend it 25° after 25. Therefore I have made the following: I have one cube with 25 and the other with 75. cube([10, 25, 10.5], center=true); color("red")  rotate([0,0,25])  translate([(-10.5)/2+0.45, -46.6, 0])  cube([10, 75, 10.5], center=true); With the command rotate I do not get on so properly. How can I get this better so that the two edges also fit? Thanks Mike Sent from the OpenSCAD mailing list archive at Nabble.com._______________________________________________ OpenSCAD mailing list To unsubscribe send an email to [hidden email]
Open this post in threaded view
|

## Re: cube rotate on another cube edge

 You have to to 3 steps 1. Translate the object, so the point you want to rotate by is on [0,0,0] (or at least the axis, you want to rotate by, should be @ 0,0 2. Rotate 3. Translate the rotated object to the target position ```cube([10, 25, 10.5], center=true); color("red") translate([10/2,25/2, 0]) rotate([0,0,25]) translate([-10/2,75/2, 0]) cube([10, 75, 10.5], center=true); ``` Sent from the OpenSCAD mailing list archive at Nabble.com._______________________________________________ OpenSCAD mailing list To unsubscribe send an email to [hidden email]
Open this post in threaded view
|

## Re: cube rotate on another cube edge

 This animation will show you whats happening (so you can better understand) ```// animate with FPS=5 Steps=50 cube([10, 25, 10.5], center=true); function ft(s1,s2)=(\$ts2) ? 1: (\$t-s1)/(s2-s1); color("red") translate([10/2,25/2, 0]*ft(0.7,1.00)) rotate([0,0,25]*ft(0.4,0.7)) translate([-10/2,75/2, 0]*ft(0,0.4)) cube([10, 75, 10.5], center=true); ``` Sent from the OpenSCAD mailing list archive at Nabble.com._______________________________________________ OpenSCAD mailing list To unsubscribe send an email to [hidden email]
Open this post in threaded view
|

## Re: cube rotate on another cube edge

 Or even better with these timing parameters ```// animate with FPS=5 Steps=50 cube([10, 25, 10.5], center=true); function ft(s1,s2)=(\$ts2) ? 1: (\$t-s1)/(s2-s1); color("red") translate([10/2,25/2, 0]*ft(0.7,0.9)) rotate([0,0,25]*ft(0.4,0.6)) translate([-10/2,75/2, 0]*ft(0.1,0.3)) cube([10, 75, 10.5], center=true); ``` Sent from the OpenSCAD mailing list archive at Nabble.com._______________________________________________ OpenSCAD mailing list To unsubscribe send an email to [hidden email]
Open this post in threaded view
|

## Re: cube rotate on another cube edge

 In reply to this post by bassklampfe That works only for the single case of  'bends' parallel to the side of the 'cube'. In other instances the joint probably has to be mitred, (or worse - tapered cylinder?) On 17/04/2021 10:07, bassklampfe wrote: You have to to 3 steps 1. Translate the object, so the point you want to rotate by is on [0,0,0] (or at least the axis, you want to rotate by, should be @ 0,0 2. Rotate 3. Translate the rotated object to the target position ```cube([10, 25, 10.5], center=true); color("red") translate([10/2,25/2, 0]) rotate([0,0,25]) translate([-10/2,75/2, 0]) cube([10, 75, 10.5], center=true); ``` Sent from the OpenSCAD mailing list archive at Nabble.com. ```_______________________________________________ OpenSCAD mailing list To unsubscribe send an email to [hidden email] ``` _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to [hidden email]
Open this post in threaded view
|

## Re: cube rotate on another cube edge

 In reply to this post by bassklampfe Thank you bassklampfe. Now my understanding about the rotate is better. And also I will change something in future too: first create the objetct then I will translate to the target position. Sent from the OpenSCAD mailing list archive at Nabble.com._______________________________________________ OpenSCAD mailing list To unsubscribe send an email to [hidden email]
 In reply to this post by q166132 The simplest way to do this is the way bassklampfe showed, but he is mistaken in thinking that 3 steps are required. It can be done with two steps, as you were trying to do, but your translation vector is incorrect. I’m not sure how you arrived at the numbers you used, but this is the correct way to calculate the translation vector.``````/* object is rotated about z-axis before transformation, the corner you want to align is located at (-5,+37.5) and you want it to be at (-5,-12.5) if you're going to translate it first, then rotate it, you need to translate it to a position that will wind up at (-5,-12.5) when rotated 25 degrees. The way to find that position is to rotate (-5, -12.5) by -25 degrees, and see where it ends up. This is most easily done by transforming (-5, -12.5) from the rectangular coordinates (x, y) to polar coordinates (r, theta): r = sqrt(x^2 + y^2) = sqrt((-5)^2 + (-12.5)^2) = sqrt(25 + 156.25) = 13.4629 theta = atan(y/x) = atan(-12.5/-5) = atan(2.5) = 68.1986 degrees but since the point is in Quadrant III, not Quadrant I, we need to add 180 degrees to get the true angle of 248.1986 now rotate -25 degrees to 223.1986 and re-convert to rectangular coordinates x = r cos(theta) = 13.4629 * cos(223.1986) = -9.8143 y = r sin(theta) = 13.4629 * sin(223.1986) = -9.2157 corner is at (-5, 37.5) and needs to be at (-9.8143, -9.2157) so translate (-4.8143, -46.7157) */ cube([10, 25, 10.5], center=true); color("red") rotate([0,0,25]) //translate([(-10.5)/2+0.45, -46.6, 0]) translate ([-4.8143, -46.7157, 0]) cube([10, 75, 10.5], center=true); // et voila`````` _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to [hidden email]
 I found this https://stackoverflow.com/questions/45826208/openscad-rotating-around-a-particular-pointmodule rotate_about_pt(z, y, pt) {    translate(pt)    rotate([0, y, z])    translate(-pt)    children(); }It took me a bit to figure it out, but it does work.Dan White | [hidden email]------------------------------------------------“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”  (Bill Waterson: Calvin & Hobbes)On April 18, 2021 at 12:07 PM, [hidden email] wrote:The simplest way to do this is the way bassklampfe showed, but he is mistaken in thinking that 3 steps are required. It can be done with two steps, as you were trying to do, but your translation vector is incorrect. I’m not sure how you arrived at the numbers you used, but this is the correct way to calculate the translation vector.``````/* object is rotated about z-axis before transformation, the corner you want to align is located at (-5,+37.5) and you want it to be at (-5,-12.5) if you're going to translate it first, then rotate it, you need to translate it to a position that will wind up at (-5,-12.5) when rotated 25 degrees. The way to find that position is to rotate (-5, -12.5) by -25 degrees, and see where it ends up. This is most easily done by transforming (-5, -12.5) from the rectangular coordinates (x, y) to polar coordinates (r, theta): r = sqrt(x^2 + y^2) = sqrt((-5)^2 + (-12.5)^2) = sqrt(25 + 156.25) = 13.4629 theta = atan(y/x) = atan(-12.5/-5) = atan(2.5) = 68.1986 degrees but since the point is in Quadrant III, not Quadrant I, we need to add 180 degrees to get the true angle of 248.1986 now rotate -25 degrees to 223.1986 and re-convert to rectangular coordinates x = r cos(theta) = 13.4629 * cos(223.1986) = -9.8143 y = r sin(theta) = 13.4629 * sin(223.1986) = -9.2157 corner is at (-5, 37.5) and needs to be at (-9.8143, -9.2157) so translate (-4.8143, -46.7157) */ cube([10, 25, 10.5], center=true); color("red") rotate([0,0,25]) //translate([(-10.5)/2+0.45, -46.6, 0]) translate ([-4.8143, -46.7157, 0]) cube([10, 75, 10.5], center=true); // et voila``````_______________________________________________OpenSCAD mailing listTo unsubscribe send an email to [hidden email]_______________________________________________ OpenSCAD mailing list To unsubscribe send an email to [hidden email]