discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

I can't figure out what's going on with rotate and translate...

B
bac1024
Wed, Feb 15, 2017 12:41 AM

I'm sure I've done things like this before, but this one is giving me issues,
I'm sure it's related to the rotate, but my objects are not lining up right
with my translate commands...  Can someone tell me what's going on here, and
how to fix it?
(The first hinge works ok, but the second one, the pieces don't all move the
same....)

module Hinge(x,y,z,d){

$fn=25;

Dir= d==0?0:7;
Rot= d==0?0:180;
    echo (Dir);
rotate([0,0,0]) translate([x,y,z])   cube([29,16,2],center=false);

rotate([0,90,0]) translate([x,y+20,z+(7-Dir)]) sphere(d=2,center=false);
difference(){
    union(){
        rotate([0,0,0]) translate([x,y+16,z]) 

cube([7,4,2],center=false);
rotate([0,90,0]) translate([x,y+20,z])
cylinder(h=7,d=4,center=false);
}
rotate([0,90,0]) translate([x,y+20,z+Dir])
sphere(d=2,center=false);
}

rotate([0,90,0]) translate([x,y+20,z+(22-Dir)])

sphere(d=2,center=false);
difference(){
union(){
rotate([0,0,0]) translate([x+15,y+16,z])
cube([7,4,2],center=false);
rotate([0,90,0]) translate([x,y+20,z+15])
cylinder(h=7,d=4,center=false);
}
rotate([0,90,0]) translate([x,y+20,z+15+Dir])
sphere(d=2,center=false);
}
}
Hinge(0,0,0,1);
Hinge(40,0,0,1);

--
View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I'm sure I've done things like this before, but this one is giving me issues, I'm sure it's related to the rotate, but my objects are not lining up right with my translate commands... Can someone tell me what's going on here, and how to fix it? (The first hinge works ok, but the second one, the pieces don't all move the same....) module Hinge(x,y,z,d){ $fn=25; Dir= d==0?0:7; Rot= d==0?0:180; echo (Dir); rotate([0,0,0]) translate([x,y,z]) cube([29,16,2],center=false); rotate([0,90,0]) translate([x,y+20,z+(7-Dir)]) sphere(d=2,center=false); difference(){ union(){ rotate([0,0,0]) translate([x,y+16,z]) cube([7,4,2],center=false); rotate([0,90,0]) translate([x,y+20,z]) cylinder(h=7,d=4,center=false); } rotate([0,90,0]) translate([x,y+20,z+Dir]) sphere(d=2,center=false); } rotate([0,90,0]) translate([x,y+20,z+(22-Dir)]) sphere(d=2,center=false); difference(){ union(){ rotate([0,0,0]) translate([x+15,y+16,z]) cube([7,4,2],center=false); rotate([0,90,0]) translate([x,y+20,z+15]) cylinder(h=7,d=4,center=false); } rotate([0,90,0]) translate([x,y+20,z+15+Dir]) sphere(d=2,center=false); } } Hinge(0,0,0,1); Hinge(40,0,0,1); -- View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443.html Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Wed, Feb 15, 2017 2:51 AM

As a generalisation, you want to do rotates before translates, particularly
when tilting cylinders.

module Hinge(x,y,z,d){

$fn=25;

Dir= d==0?0:7;
Rot= d==0?0:180;
    echo (Dir);
rotate([0,0,0]) translate([x,y,z])   cube([29,16,2],center=false);

 translate([x,y+20,z+(7-Dir)]) rotate([0,90,0])

sphere(d=2,center=false);
difference(){
union(){
rotate([0,0,0]) translate([x,y+16,z])
cube([7,4,2],center=false);
translate([x,y+20,z])rotate([0,90,0])
cylinder(h=7,d=4,center=false);
}
translate([x+7,y+20,z+(7-Dir)])rotate([0,90,0])
sphere(d=2,center=false);
}

 translate([x+15,y+20,z+(7-Dir)])rotate([0,90,0])

sphere(d=2,center=false);
difference(){
union(){
rotate([0,0,0]) translate([x+15,y+16,z])
cube([7,4,2],center=false);
translate([x+15,y+20,z]) rotate([0,90,0])
cylinder(h=7,d=4,center=false);
}
translate([x+15+7,y+20,z+(7-Dir)]) rotate([0,90,0])
sphere(d=2,center=false);
}
}
Hinge(0,0,0,1);
Hinge(40,0,0,1);

You may need to fix the Dir bits...


Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443p20444.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

As a generalisation, you want to do rotates before translates, particularly when tilting cylinders. module Hinge(x,y,z,d){ $fn=25; Dir= d==0?0:7; Rot= d==0?0:180; echo (Dir); rotate([0,0,0]) translate([x,y,z]) cube([29,16,2],center=false); translate([x,y+20,z+(7-Dir)]) rotate([0,90,0]) sphere(d=2,center=false); difference(){ union(){ rotate([0,0,0]) translate([x,y+16,z]) cube([7,4,2],center=false); translate([x,y+20,z])rotate([0,90,0]) cylinder(h=7,d=4,center=false); } translate([x+7,y+20,z+(7-Dir)])rotate([0,90,0]) sphere(d=2,center=false); } translate([x+15,y+20,z+(7-Dir)])rotate([0,90,0]) sphere(d=2,center=false); difference(){ union(){ rotate([0,0,0]) translate([x+15,y+16,z]) cube([7,4,2],center=false); translate([x+15,y+20,z]) rotate([0,90,0]) cylinder(h=7,d=4,center=false); } translate([x+15+7,y+20,z+(7-Dir)]) rotate([0,90,0]) sphere(d=2,center=false); } } Hinge(0,0,0,1); Hinge(40,0,0,1); You may need to fix the Dir bits... ----- Admin - PM me if you need anything, or if I've done something stupid... Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443p20444.html Sent from the OpenSCAD mailing list archive at Nabble.com.
B
bac1024
Wed, Feb 15, 2017 3:58 AM

ok, I'm confused now (ok, a little more?) You say to do the rotates before
the translates, but then you moved my rotates to after the translates?

--
View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443p20445.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

ok, I'm confused now (ok, a little more?) You say to do the rotates before the translates, but then you moved my rotates to after the translates? -- View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443p20445.html Sent from the OpenSCAD mailing list archive at Nabble.com.
B
bac1024
Wed, Feb 15, 2017 5:06 AM

Ok, nevermind.  I got it straightened out....  I think you meant to do the
rotates AFTER the translates, because otherwise the XYZ order is changed.

--
View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443p20446.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Ok, nevermind. I got it straightened out.... I think you meant to do the rotates AFTER the translates, because otherwise the XYZ order is changed. -- View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443p20446.html Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Wed, Feb 15, 2017 5:14 AM

Sorry, I should have been clearer.

Operations apply to the child, and rotate() rotates around an axis.

translate() sphere() translates the sphere,
rotate() sphere() rotates the sphere, in it's place, so you don't see any
effect
rotate() translate() sphere(), moves the sphere away from the axis, then
rotates it on an axis

So what I meant by do rotates before, was to apply the rotate to the object,
rotate() object()

then translate it
translate()
rotate()
object();

Try thinking like the {} brackets are in place

translate() {
rotate() {
object();
}
}

Or try this code:

module cubeOrigin(col) {
color(col)
cube([10,15,10]);
color("red")
cylinder(d=1,h=10);
}

cubeOrigin("lightgreen");
rotate([0,0,90])
cubeOrigin("green");

translate([0,20,0])
cubeOrigin("lightblue");
rotate([0,0,90])
translate([0,20,0])
cubeOrigin("blue");

translate([0,40,0])
cubeOrigin("plum");
rotate([0,0,90])
translate([0,40,0])
cubeOrigin("purple");

translate([0,0,30]) { // move up a layer & reverse order of translate/rotate
translate([0,20,0])
cubeOrigin("lightblue");
translate([0,20,0])
rotate([0,0,90])
cubeOrigin("blue");

translate([0,40,0])
cubeOrigin("plum");
translate([0,40,0])
rotate([0,0,90])
cubeOrigin("purple");
}

http://forum.openscad.org/file/n20447/trans-rota.jpg

Note the red origin (at [0,0,0] before any transformations).


Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443p20447.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Sorry, I should have been clearer. Operations apply to the child, and rotate() rotates around an axis. translate() sphere() translates the sphere, rotate() sphere() rotates the sphere, in it's place, so you don't see any effect rotate() translate() sphere(), moves the sphere away from the axis, then rotates it on an axis So what I meant by do rotates before, was to apply the rotate to the object, rotate() object() then translate it translate() rotate() object(); Try thinking like the {} brackets are in place translate() { rotate() { object(); } } Or try this code: module cubeOrigin(col) { color(col) cube([10,15,10]); color("red") cylinder(d=1,h=10); } cubeOrigin("lightgreen"); rotate([0,0,90]) cubeOrigin("green"); translate([0,20,0]) cubeOrigin("lightblue"); rotate([0,0,90]) translate([0,20,0]) cubeOrigin("blue"); translate([0,40,0]) cubeOrigin("plum"); rotate([0,0,90]) translate([0,40,0]) cubeOrigin("purple"); translate([0,0,30]) { // move up a layer & reverse order of translate/rotate translate([0,20,0]) cubeOrigin("lightblue"); translate([0,20,0]) rotate([0,0,90]) cubeOrigin("blue"); translate([0,40,0]) cubeOrigin("plum"); translate([0,40,0]) rotate([0,0,90]) cubeOrigin("purple"); } <http://forum.openscad.org/file/n20447/trans-rota.jpg> Note the red origin (at [0,0,0] before any transformations). ----- Admin - PM me if you need anything, or if I've done something stupid... Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443p20447.html Sent from the OpenSCAD mailing list archive at Nabble.com.
JD
Jerry Davis
Wed, Feb 15, 2017 4:09 PM

you can also think of it this way.

the rightmost transformation gets done first, then the one to the left of
that, and so on.

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Openscad developer

The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov

On Tue, Feb 14, 2017 at 10:14 PM, MichaelAtOz oz.at.michael@gmail.com
wrote:

Sorry, I should have been clearer.

Operations apply to the child, and rotate() rotates around an axis.

translate() sphere() translates the sphere,
rotate() sphere() rotates the sphere, in it's place, so you don't see any
effect
rotate() translate() sphere(), moves the sphere away from the axis, then
rotates it on an axis

So what I meant by do rotates before, was to apply the rotate to the
object,
rotate() object()

then translate it
translate()
rotate()
object();

Try thinking like the {} brackets are in place

translate() {
rotate() {
object();
}
}

Or try this code:

module cubeOrigin(col) {
color(col)
cube([10,15,10]);
color("red")
cylinder(d=1,h=10);
}

cubeOrigin("lightgreen");
rotate([0,0,90])
cubeOrigin("green");

translate([0,20,0])
cubeOrigin("lightblue");
rotate([0,0,90])
translate([0,20,0])
cubeOrigin("blue");

translate([0,40,0])
cubeOrigin("plum");
rotate([0,0,90])
translate([0,40,0])
cubeOrigin("purple");

translate([0,0,30]) { // move up a layer & reverse order of
translate/rotate
translate([0,20,0])
cubeOrigin("lightblue");
translate([0,20,0])
rotate([0,0,90])
cubeOrigin("blue");

translate([0,40,0])
cubeOrigin("plum");
translate([0,40,0])
rotate([0,0,90])
cubeOrigin("purple");
}

http://forum.openscad.org/file/n20447/trans-rota.jpg

Note the red origin (at [0,0,0] before any transformations).


Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the
Public Domain; to the extent possible under law, I have waived all
copyright and related or neighbouring rights to this work. Obviously
inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it!
http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/I-
can-t-figure-out-what-s-going-on-with-rotate-and-translate-
tp20443p20447.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

you can also think of it this way. the rightmost transformation gets done first, then the one to the left of that, and so on. -- Extra Ham Operator: K7AZJ Registered Linux User: 275424 Raspberry Pi and Openscad developer *The most exciting phrase to hear in science - the one that heralds new discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov On Tue, Feb 14, 2017 at 10:14 PM, MichaelAtOz <oz.at.michael@gmail.com> wrote: > Sorry, I should have been clearer. > > Operations apply to the child, and rotate() rotates around an axis. > > translate() sphere() translates the sphere, > rotate() sphere() rotates the sphere, in it's place, so you don't see any > effect > rotate() translate() sphere(), moves the sphere away from the axis, then > rotates it on an axis > > So what I meant by do rotates before, was to apply the rotate to the > object, > rotate() object() > > then translate it > translate() > rotate() > object(); > > Try thinking like the {} brackets are in place > > translate() { > rotate() { > object(); > } > } > > Or try this code: > > module cubeOrigin(col) { > color(col) > cube([10,15,10]); > color("red") > cylinder(d=1,h=10); > } > > cubeOrigin("lightgreen"); > rotate([0,0,90]) > cubeOrigin("green"); > > translate([0,20,0]) > cubeOrigin("lightblue"); > rotate([0,0,90]) > translate([0,20,0]) > cubeOrigin("blue"); > > translate([0,40,0]) > cubeOrigin("plum"); > rotate([0,0,90]) > translate([0,40,0]) > cubeOrigin("purple"); > > translate([0,0,30]) { // move up a layer & reverse order of > translate/rotate > translate([0,20,0]) > cubeOrigin("lightblue"); > translate([0,20,0]) > rotate([0,0,90]) > cubeOrigin("blue"); > > translate([0,40,0]) > cubeOrigin("plum"); > translate([0,40,0]) > rotate([0,0,90]) > cubeOrigin("purple"); > } > > <http://forum.openscad.org/file/n20447/trans-rota.jpg> > > Note the red origin (at [0,0,0] before any transformations). > > > > > ----- > Admin - PM me if you need anything, or if I've done something stupid... > > Unless specifically shown otherwise above, my contribution is in the > Public Domain; to the extent possible under law, I have waived all > copyright and related or neighbouring rights to this work. Obviously > inclusion of works of previous authors is not included in the above. > > The TPP is no simple “trade agreement.” Fight it! > http://www.ourfairdeal.org/ time is running out! > -- > View this message in context: http://forum.openscad.org/I- > can-t-figure-out-what-s-going-on-with-rotate-and-translate- > tp20443p20447.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
B
bac1024
Thu, Feb 16, 2017 7:01 AM

heh, I actually did a test very similar to your graphic to figure out how all
of it worked. :)  Thank you for your help.....

--
View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443p20463.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

heh, I actually did a test very similar to your graphic to figure out how all of it worked. :) Thank you for your help..... -- View this message in context: http://forum.openscad.org/I-can-t-figure-out-what-s-going-on-with-rotate-and-translate-tp20443p20463.html Sent from the OpenSCAD mailing list archive at Nabble.com.