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

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

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

terramir
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

-
Reply | Threaded
Open this post in threaded view
|

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

Whosawhatsis
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

-

Reply | Threaded
Open this post in threaded view
|

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

tjhowse
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 <[hidden email]> 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
http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

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

terramir
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: 
<code> 
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]); </code>

now this would produce a cube that would have a cornerpoint at the center of the cylinder
but if I translate the corner point to the edge of the cylinder like this <code>
......
translate([zrd,trd*2,0]) rotate([0,0,30]) cube([50,trd*4,trd*2])</code>
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?
terramir

On Wed, Nov 14, 2012 at 2:00 PM, tjhowse <[hidden email]> 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 <[hidden email]> 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
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 Borkan
727 S. Coronado St. 201
Los Angeles, CA 90057
H: (213) 739-1863
C: (213) 271-6721
Reply | Threaded
Open this post in threaded view
|

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

Triffid Hunter
On Thu, Nov 15, 2012 at 11:04 AM, r.d. terramir <[hidden email]> wrote:
but if I translate the corner point to the edge of the cylinder like this <code>
......
translate([zrd,trd*2,0]) rotate([0,0,30]) cube([50,trd*4,trd*2])</code>

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()

Reply | Threaded
Open this post in threaded view
|

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

ufomorace
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.
Reply | Threaded
Open this post in threaded view
|

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

L Boyd
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
Reply | Threaded
Open this post in threaded view
|

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

L Boyd
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
Reply | Threaded
Open this post in threaded view
|

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

ufomorace
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. ?!?
Reply | Threaded
Open this post in threaded view
|

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

nophead
I don't understand your problem.

OpenScad rotate() is always around the origin. So you translate your object so the point on it you want the rotation to be around is at the origin. Then you rotate it. That point is still on the origin. Then you translate it back to where it used to be. The end result is that point on the object has not moved but the object has rotated about it.

On 26 August 2015 at 20:50, ufomorace <[hidden email]> wrote:
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. ?!?



--
View this message in context: http://forum.openscad.org/rotating-a-cube-around-the-center-of-the-y-axis-of-the-cube-tp3424p13613.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

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

L Boyd
ufomorace you are over thinking the problem.

If you move your object to place the center of rotation at the origin, rotate it, then move it back by changing the sign on the x,y,z values used for the first move, it is right back where it was, but rotated.

Nothing complicated about the math.
Yes, all the other points have a new location, but that is what you wanted.

If you now want it some where else, think about moving that center of rotation.
Larry