# rotating a cube around the center of the y-axis of the cube Classic List Threaded 11 messages Open this post in threaded view
|

## rotating a cube around the center of the y-axis of the cube

 Hi guys and gals,when you rotate a cube it rotates around the base corner i.e. x=0 y=0 z=0 what if I wanted to rotate the box around let's say x=0 y= y/2 z=0 instead of the default setting this may help me in designing various projects. anyway to do this elegantly ? terramir-
Open this post in threaded view
|

## Re: rotating a cube around the center of the y-axis of the cube

 The only way to do this is to move the object so that the desired center of rotation is at the origin, rotate, then place it where you want it. On Wednesday, November 14, 2012 at 9:26 AM, r.d. terramir wrote: Hi guys and gals,when you rotate a cube it rotates around the base corner i.e. x=0 y=0 z=0 what if I wanted to rotate the box around let's say x=0 y= y/2 z=0 instead of the default setting this may help me in designing various projects. anyway to do this elegantly ? terramir- _______________________________________________OpenSCAD mailing list[hidden email]http://rocklinux.net/mailman/listinfo/openscad
Open this post in threaded view
|

## Re: rotating a cube around the center of the y-axis of the cube

 It's important to note that the rotation is performed about the origin, [0,0,0], not any point relative to the object being rotated. If you can move the object such that then origin is at your desired rotation point, then you can do as you wish. On 15 November 2012 03:54, whosawhatsis wrote: The only way to do this is to move the object so that the desired center of rotation is at the origin, rotate, then place it where you want it. On Wednesday, November 14, 2012 at 9:26 AM, r.d. terramir wrote: Hi guys and gals,when you rotate a cube it rotates around the base corner i.e. x=0 y=0 z=0 what if I wanted to rotate the box around let's say x=0 y= y/2 z=0 instead of the default setting this may help me in designing various projects. anyway to do this elegantly ? terramir- _______________________________________________OpenSCAD mailing list[hidden email]http://rocklinux.net/mailman/listinfo/openscad _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad http://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|

## Re: rotating a cube around the center of the y-axis of the cube

 How do I do this though let's say that at this current time I have a desired rotation point of the center of this cylinder:  translate([zrd,0,0]) cylinder(r=trd*2, h=trd*1.6, \$fn=64); translate([zrd,0,0]) rotate([0,0,30]) cube([50,trd*4,trd*2]); now this would produce a cube that would have a cornerpoint at the center of the cylinderbut if I translate the corner point to the edge of the cylinder like this ......translate([zrd,trd*2,0]) rotate([0,0,30]) cube([50,trd*4,trd*2])then it will rotate along the edge of the cylinder above  so how do I set the origin for this object to ([zrd,0,0]) after I translate it so it matches the cylinder and before I rotate the object in question? terramirOn Wed, Nov 14, 2012 at 2:00 PM, tjhowse wrote: It's important to note that the rotation is performed about the origin, [0,0,0], not any point relative to the object being rotated. If you can move the object such that then origin is at your desired rotation point, then you can do as you wish. On 15 November 2012 03:54, whosawhatsis wrote: The only way to do this is to move the object so that the desired center of rotation is at the origin, rotate, then place it where you want it. On Wednesday, November 14, 2012 at 9:26 AM, r.d. terramir wrote: Hi guys and gals,when you rotate a cube it rotates around the base corner i.e. x=0 y=0 z=0 what if I wanted to rotate the box around let's say x=0 y= y/2 z=0 instead of the default setting this may help me in designing various projects. anyway to do this elegantly ? terramir- _______________________________________________OpenSCAD mailing list[hidden email]http://rocklinux.net/mailman/listinfo/openscad _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad http://openscad.org - https://flattr.com/thing/121566 _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad http://openscad.org - https://flattr.com/thing/121566 -- Respectfully,R. Daniel Borkan727 S. Coronado St. 201Los Angeles, CA 90057H: (213) 739-1863C: (213) 271-6721
Open this post in threaded view
|

## Re: rotating a cube around the center of the y-axis of the cube

 On Thu, Nov 15, 2012 at 11:04 AM, r.d. terramir wrote: but if I translate the corner point to the edge of the cylinder like this ......translate([zrd,trd*2,0]) rotate([0,0,30]) cube([50,trd*4,trd*2])you're still rotating before translating so the cube will still rotate around its corner. you want rotate() translate() cube() instead of translate() rotate() cube() or possibly even translate() rotate() translate() cube()
Open this post in threaded view
|

## Re: rotating a cube around the center of the y-axis of the cube

 In reply to this post by terramir I am just attempting this and have found that it's very steep mathematics for an evening to adjust transformation and rotation matrices to account for irregular rotations of cubes around the middle of the y axis of one of the faces, i basically want rotate cubes as if they were jointed by a point in the middle of their base. I figure that the only logical way for me to do that is to rewrite a cube primitive centered in the middle of a y axis face and not in the middle or corner of the cube.
Open this post in threaded view
|

## Re: rotating a cube around the center of the y-axis of the cube

 In reply to this post by terramir You may find it useful to use center=true when defining you objects. This will place the center of all three dimension at the coordinate origin [0,0,0]. However the general answer to you question is: 1. Translate the cube so that the point about which you wish to rotate is at [0,0,0]. 2. Perform the rotation. 3. Translate so that the point about which you rotated is at its desired location. Example: x= 5; y =8; z=10; translate([5,-10,15]){ // move rotated object   rotate([0,0,30]){     translate([0,-x/2,0]){ // move rotation point to origin       cube([x,y,z]); } } } note that the the pairs of braces {} are not required but are shown here for clarity of the scope of each operation. Larry
Open this post in threaded view
|

## Re: rotating a cube around the center of the y-axis of the cube

 Oops. I had meant to use  translate([0,-y/2,0]) not x/2 But this shows that you can use any point location. Even one outside the object will work. Larry
Open this post in threaded view
|

## Re: rotating a cube around the center of the y-axis of the cube

 I don't understand that method. if you wished to rotate the object around its centre - y=1, once the obect is rotate you can find where the point y-1 is relative to the new rotation of the object, using the object's orientation vector3, and then use that minus the same point at it's previous rotation, to translate the point to the rotatearound position. ?!?