discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Symmetrical Rotation

FI
Factotum Industries
Mon, Oct 5, 2015 3:04 AM
Hi everyone.  

I've been an OpenSCAD user for some time - it's awesome. I recently upgraded from 2014.x to the latest 2015.x and the new changes are fantastic!

I'm doing a bit of design project at the moment - what I want : a rectangular 'bar' rotated about the z-axis and the x-axis (an interesting twist) and then iterated (circularly) around the z-axis.

Code :

length = 400;
width = 35;
thick = 80;
steps = 90;
offs = 95;

module bar(x,y,z,off){
translate([off,0,0])
rotate([30,0,0]) //Rotate bar x-axis
rotate([0,0,30]) //Rotate bar z-axis
cube([x,y,z],center=true);
}

for (i=[0:(steps-1)]) {
rotate([0, 0, i*(360/steps)])
bar(width, thick, length, offs);
}

I'm expecting it to be a mirror image through the XY plane (but it's not). Can anyone see what fatal assumption I've made? The "steps" variable is set high to make it easier to see the imbalance..

Addendum - Marius recommended the following trick to further help with visualising the problem :

.. try this: rotate([0,0,$t*180-90]) //Rotate bar z-axis
.. then go to View->Animate. set FPS to 30 or so and Steps to 100. That should give you some way of playing with this.

R
runsun
Mon, Oct 5, 2015 4:19 AM

Not sure if this is what you want:

Factotum wrote

   length = 400; 
     width = 35; 
     thick = 80; 
     steps = 90; 
     offs = 95; 
       
     module bar(x,y,z,off){ 
         translate([off,0,0]) 
         rotate([30,0,0])    //Rotate bar x-axis 
         //rotate([0,0,30])    //Rotate bar z-axis  <====== take this

out
    cube([x,y,z],center=true);
}

     for (i=[0:(steps-1)]) { 
         rotate([0, 0, i*(360/steps)]) 
         bar(width, thick, length, offs); 
       } 

$  Runsun Pan, PhD

$ libs: doctest , faces ( git ), offliner ( git ), runscad.py ;

$ tips: hash( 1 , 2 ), sweep , var , lerp , animGif

--
View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14063.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Not sure if this is what you want: Factotum wrote > length = 400; > width = 35; > thick = 80; > steps = 90; > offs = 95; > > module bar(x,y,z,off){ >     translate([off,0,0]) >     rotate([30,0,0])    //Rotate bar x-axis >     //rotate([0,0,30])    //Rotate bar z-axis <====== take this > out >     cube([x,y,z],center=true); > } > > for (i=[0:(steps-1)]) { >     rotate([0, 0, i*(360/steps)]) >     bar(width, thick, length, offs); >   } ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offliner ( git ), runscad.py ; $ tips: hash( 1 , 2 ), sweep , var , lerp , animGif -- View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14063.html Sent from the OpenSCAD mailing list archive at Nabble.com.
FI
Factotum Industries
Mon, Oct 5, 2015 4:28 AM

That leaves me with no rotation of the 'bar' around its z-axis which is a required part of the design...

I realised my description isn't quite correct either - I said 'mirrored about the XY plane' - what I actually mean is the final object should be of identical length / rotation above / below the XY plane (I'm sure there is a better way of saying this)...

On 5/10/2015 12:19 PM, runsun wrote:

<pre wrap="">Not sure if this is what you want:

            //rotate([0,0,30])    //Rotate bar z-axis  <====== take this

--

R
runsun
Mon, Oct 5, 2015 5:46 AM

Then, try this:

  1. Take out the translate([off,0,0]). This will make it symmetric off XY
    plane
  2. Add a new translate( [offx, offy,0] ) as shown below. This will simply
    push the bar away from the center.

The idea is to delay the translation until the final rotation is made. The
offx, offy are to be calculated using cos and sin, which shouldn't be hard.

Factotum wrote

   length = 400; 
     width = 35; 
     thick = 80; 
     steps = 90; 
     offs = 95; 
       
     module bar(x,y,z,off){ 
         //translate([off,0,0])   <============== take this out
         rotate([30,0,0])    //Rotate bar x-axis 
         rotate([0,0,30])    //Rotate bar z-axis 
         cube([x,y,z],center=true); 
     } 
       
     for (i=[0:(steps-1)]) { 
         translate( [offx,offy,0] )   // <========= add this 
         rotate([0, 0, i*(360/steps)]) 
         bar(width, thick, length, offs); 
       } 

$  Runsun Pan, PhD

$ libs: doctest , faces ( git ), offliner ( git ), runscad.py ;

$ tips: hash( 1 , 2 ), sweep , var , lerp , animGif

--
View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14065.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Then, try this: 1) Take out the translate([off,0,0]). This will make it symmetric off XY plane 2) Add a new translate( [offx, offy,0] ) as shown below. This will simply push the bar away from the center. The idea is to delay the translation until the final rotation is made. The offx, offy are to be calculated using cos and sin, which shouldn't be hard. Factotum wrote > > length = 400; > width = 35; > thick = 80; > steps = 90; > offs = 95; > > module bar(x,y,z,off){ >     //translate([off,0,0]) <============== take this out >     rotate([30,0,0])    //Rotate bar x-axis >     rotate([0,0,30])    //Rotate bar z-axis >     cube([x,y,z],center=true); > } > > for (i=[0:(steps-1)]) { > translate( [offx,offy,0] ) // <========= add this >     rotate([0, 0, i*(360/steps)]) >     bar(width, thick, length, offs); >   } > ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offliner ( git ), runscad.py ; $ tips: hash( 1 , 2 ), sweep , var , lerp , animGif -- View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14065.html Sent from the OpenSCAD mailing list archive at Nabble.com.
CL
Chow Loong Jin
Mon, Oct 5, 2015 8:00 AM

On Mon, Oct 05, 2015 at 12:28:26PM +0800, Factotum Industries wrote:

That leaves me with no rotation of the 'bar' around its z-axis which is a
required part of the design...

I realised my description isn't quite correct either - I said 'mirrored about
the XY plane' - what I actually mean is the final object should be of identical
length / rotation above / below the XY plane (I'm sure there is a better way of
saying this)...

It looks of identical length above and below the Z=0 plane to me..
http://imgur.com/2FDdTL8

Perhaps you should draw it out on paper?

--
Kind regards,
Loong Jin

On Mon, Oct 05, 2015 at 12:28:26PM +0800, Factotum Industries wrote: > That leaves me with no rotation of the 'bar' around its z-axis which is a > required part of the design... > > I realised my description isn't quite correct either - I said 'mirrored about > the XY plane' - what I actually mean is the final object should be of identical > length / rotation above / below the XY plane (I'm sure there is a better way of > saying this)... It looks of identical length above and below the Z=0 plane to me.. http://imgur.com/2FDdTL8 Perhaps you should draw it out on paper? -- Kind regards, Loong Jin
W
wolf
Mon, Oct 5, 2015 10:24 AM

Your thinking is wrong, meaning your visualisation of what should have
happened is not quite what you have actually done. Use the % operator in
front of the bar(...) statement inside the for loop, to make your bars
transparent. Then use your mouse to rotate your shape, and you'll see . . .

for (i=[0:(steps-1)]) {
rotate([0, 0, i*(360/steps)])
%  bar(width, thick, length, offs);

Because your bar is not rotation symmetric, your shape isn't either. Replace
cube([x,y,z],center=true);
with
cylinder(d=x,h=z,center=true);
and get the hyperboloid you're after . . .
http://forum.openscad.org/file/n14067/hyperboloid.jpg

--
View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14067.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Your thinking is wrong, meaning your visualisation of what should have happened is not quite what you have actually done. Use the % operator in front of the bar(...) statement inside the for loop, to make your bars transparent. Then use your mouse to rotate your shape, and you'll see . . . for (i=[0:(steps-1)]) { rotate([0, 0, i*(360/steps)]) % bar(width, thick, length, offs); Because your bar is not rotation symmetric, your shape isn't either. Replace cube([x,y,z],center=true); with cylinder(d=x,h=z,center=true); and get the hyperboloid you're after . . . <http://forum.openscad.org/file/n14067/hyperboloid.jpg> -- View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14067.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Mon, Oct 5, 2015 1:36 PM

wolf wrote

Because your bar is not rotation symmetric, your shape isn't either.
Replace
cube([x,y,z],center=true);
with
cylinder(d=x,h=z,center=true);
and get the hyperboloid you're after . . .

The shape looks nice. But it is specifically mentioned that "rotation of the
'bar' around its z-axis is a required part of the design", which this answer
failed to fulfill.


$  Runsun Pan, PhD

$ libs: doctest , faces ( git ), offliner ( git ), runscad.py ;

$ tips: hash( 1 , 2 ), sweep , var , lerp , animGif

--
View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14073.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

wolf wrote > Because your bar is not rotation symmetric, your shape isn't either. > Replace > cube([x,y,z],center=true); > with > cylinder(d=x,h=z,center=true); > and get the hyperboloid you're after . . . The shape looks nice. But it is specifically mentioned that "rotation of the 'bar' around its z-axis is a required part of the design", which this answer failed to fulfill. ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offliner ( git ), runscad.py ; $ tips: hash( 1 , 2 ), sweep , var , lerp , animGif -- View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14073.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Mon, Oct 5, 2015 3:45 PM

Chow Loong Jin wrote

It looks of identical length above and below the Z=0 plane to me..

u r right. That was a wrong approach.


$  Runsun Pan, PhD

$ libs: doctest , faces ( git ), offliner ( git ), runscad.py ;

$ tips: hash( 1 , 2 ), sweep , var , lerp , animGif

--
View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14074.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Chow Loong Jin wrote > It looks of identical length above and below the Z=0 plane to me.. u r right. That was a wrong approach. ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offliner ( git ), runscad.py ; $ tips: hash( 1 , 2 ), sweep , var , lerp , animGif -- View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14074.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Mon, Oct 5, 2015 3:55 PM

I am not sure the exact 30 degree is the requirement:

rotate([30,0,0])    //Rotate bar x-axis
rotate([0,0,30])    //Rotate bar z-axis

If not, make z-rotation to 90 and you will get what you want. Here is the
code and an animating object with varying ax from 0 to 60:

length= 400;
width = 35;
thick = 80;
steps = 90;
offs  = 95;
ax = 0;
az = 90;
w =width;
th=thick;
l =length;

module bar(x=w,y=th,z=l,off){
translate([offs,0,0])
rotate([ax,0,0])    //Rotate bar x-axis
rotate([0,0,az])    //Rotate bar z-axis
cube([x,y,z],center=true);
}

module Obj(){
for (i=[0:(steps-1)]) {
rotate([0, 0, i*(360/steps)])
bar(width, thick, length, offs);
}
}

module animateRot3d( t=$t, loc=[0,0,0] ){

//http://forum.openscad.org/Animating-gif-with-3D-rotation-td14011.html
tt = 540*t;
rot = t< 1/3 ? [ tt,0,0 ]
: t<2/3 ? [ 180, tt-180,0 ]
: [180,180,tt];

 translate(loc)
 rotate(rot)    
 translate( -1*loc) children();

}

t=$t;
animateRot3d(t=t)
Obj();

http://forum.openscad.org/file/n14075/151004_sym_rot.gif

The animation was made using runscad.py (see my signature) in command line
and  here
http://forum.openscad.org/Animating-gif-with-3D-rotation-td14011.html  :

$ python ../../runscad.py 20151004_sym_rotate.scad 151004_sym_rot.png
D="t=%(t)s;ax=sin(180*%(t)s)*60" n=30
$ convert -delay 30 -loop 0 ./151004_sym_rot000??.png 151004_sym_rot.gif


$  Runsun Pan, PhD

$ libs: doctest , faces ( git ), offliner ( git ), runscad.py ;

$ tips: hash( 1 , 2 ), sweep , var , lerp , animGif

--
View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14075.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I am not sure the exact 30 degree is the requirement: rotate([30,0,0]) //Rotate bar x-axis rotate([0,0,30]) //Rotate bar z-axis If not, make z-rotation to 90 and you will get what you want. Here is the code and an animating object with varying ax from 0 to 60: > length= 400; > width = 35; > thick = 80; > steps = 90; > offs = 95; > ax = 0; > az = 90; > w =width; > th=thick; > l =length; > > module bar(x=w,y=th,z=l,off){ > translate([offs,0,0]) > rotate([ax,0,0]) //Rotate bar x-axis > rotate([0,0,az]) //Rotate bar z-axis > cube([x,y,z],center=true); > } > > module Obj(){ > for (i=[0:(steps-1)]) { > rotate([0, 0, i*(360/steps)]) > bar(width, thick, length, offs); > } > } > > module animateRot3d( t=$t, loc=[0,0,0] ){ > > //http://forum.openscad.org/Animating-gif-with-3D-rotation-td14011.html > tt = 540*t; > rot = t< 1/3 ? [ tt,0,0 ] > : t<2/3 ? [ 180, tt-180,0 ] > : [180,180,tt]; > > translate(loc) > rotate(rot) > translate( -1*loc) children(); > } > > t=$t; > animateRot3d(t=t) > Obj(); <http://forum.openscad.org/file/n14075/151004_sym_rot.gif> The animation was made using runscad.py (see my signature) in command line and here <http://forum.openscad.org/Animating-gif-with-3D-rotation-td14011.html> : > $ python ../../runscad.py 20151004_sym_rotate.scad 151004_sym_rot.png > D="t=%(t)s;ax=sin(180*%(t)s)*60" n=30 > $ convert -delay 30 -loop 0 ./151004_sym_rot000??.png 151004_sym_rot.gif ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offliner ( git ), runscad.py ; $ tips: hash( 1 , 2 ), sweep , var , lerp , animGif -- View this message in context: http://forum.openscad.org/Symmetrical-Rotation-tp14062p14075.html Sent from the OpenSCAD mailing list archive at Nabble.com.