discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] Rotation question

RP
Ronaldo Persiano
Mon, Dec 17, 2018 1:16 PM

As I said, rotFromTo() is all you need:

module rotFromTo(di,do)
if( norm(di-do)==0 || norm(di)==0 || norm(do)==0 )
children();
else
mirror(do/norm(do)+di/norm(di)) mirror(di) children();

module axis(x,y){
color("red") hull() {sphere(0.01norm(x)); translate(x)
sphere(0.01
norm(x)); }
color("blue") hull() {sphere(0.01norm(y)); translate(y)
sphere(0.01
norm(y)); }
}

module object(x,y,colour=undef) {
axis(x,y);
color(colour)
polyhedron([[0,0,0], x, y, cross(x,y)/norm(x)/norm(y)+(x+y)/3],
[[0,1,2],[3,2,1],[3,1,0],[3,2,0], ]);
}

X = [-1,2,1];
Y = [1,1,1];

object(X,Y);
translate([(norm(X)+norm(Y))/2,0,0])
rotFromTo(cross(X,Y),[0,0,1])
object(X,Y,"magenta");
translate([(norm(X)+norm(Y)),0,0])
rotFromTo(cross(Y,X),[0,0,1])
object(X,Y,"green");

[image: laydown.PNG]
Maurice van Peursem openscad@vanpeursem.net wrote:

Thanks, but it doesn't do what I want. I've built a whole structure,
and I want to rotate the structure so it will lay horizontally
according to the 2 vectors, but the structure itself must stay
unchanged.

As I said, rotFromTo() is all you need: module rotFromTo(di,do) if( norm(di-do)==0 || norm(di)==0 || norm(do)==0 ) children(); else mirror(do/norm(do)+di/norm(di)) mirror(di) children(); module axis(x,y){ color("red") hull() {sphere(0.01*norm(x)); translate(x) sphere(0.01*norm(x)); } color("blue") hull() {sphere(0.01*norm(y)); translate(y) sphere(0.01*norm(y)); } } module object(x,y,colour=undef) { axis(x,y); color(colour) polyhedron([[0,0,0], x, y, cross(x,y)/norm(x)/norm(y)+(x+y)/3], [[0,1,2],[3,2,1],[3,1,0],[3,2,0], ]); } X = [-1,2,1]; Y = [1,1,1]; object(X,Y); translate([(norm(X)+norm(Y))/2,0,0]) rotFromTo(cross(X,Y),[0,0,1]) object(X,Y,"magenta"); translate([(norm(X)+norm(Y)),0,0]) rotFromTo(cross(Y,X),[0,0,1]) object(X,Y,"green"); [image: laydown.PNG] Maurice van Peursem <openscad@vanpeursem.net> wrote: > Thanks, but it doesn't do what I want. I've built a whole structure, > and I want to rotate the structure so it will lay horizontally > according to the 2 vectors, but the structure itself must stay > unchanged. >
P
Parkinbot
Mon, Dec 17, 2018 2:13 PM

Ronaldo,

cool! I didn't follow your link, but now I remember.

--
Sent from: http://forum.openscad.org/

Ronaldo, cool! I didn't follow your link, but now I remember. -- Sent from: http://forum.openscad.org/