This is your code. It uses two rotations, one around the y axis and the other
one around the x axis.
You can play with the vectors.
X = [3, -2, .10];
Y = [2, 0, 3];
vector(X, .02, "red");
vector(Y, .02, "blue");
x = X/norm(X); // 1st rotation
X_ = mmult(rotxz(x), [X]); // rot X by X projected to xz
Y1 = mmult(rotxz(x), [Y]); // rot Y by X projected to xz
y = Y1/norm(Y1); // second rotation
Y_ = mmult(rotyz(y), [Y1]); // rot Y1 by Y1 projected to yz
vector(X_, 0.02, "black");
vector(Y_, 0.02, "white");
function rotxz(d) =
[[d[0], 0, d[2]],
[0, 1, 0],
[-d[2], 0, d[0]]];
function rotyz(d) =
[[1, 0, 0],
[0, d[1], d[2]],
[0, -d[2], d[1]]];
function mmult(X, Y) = len(X) != len(Y[0])? undef:
[for(i=[0:len(Y)-1])
[for(j=[0:len(X[0])-1])
X[j]*Y[i]]][0];
module vector(p1=[100,100], r=undef, color=undef, reverse=false)
{
t = reverse?p1:[0,0,0];
s = reverse?-1:1;
r = r==undef?norm(p1)/100:r;
translate(t)scale(s)
if(color) color(color) vec();
else vec();
module vec()
{
l = norm(p1);
v = p1/l;
hull()
{
sphere(r);
translate((l-5*r)v) sphere(r);
}
hull()
{
translate((l-5r)v) sphere(2r);
translate(p1) sphere(r/10);
}
}
}
--
Sent from: http://forum.openscad.org/
Hi Parkinbot,
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. If I feed in these vectors in your script:
X = [1, 1, 1];
Y = [0, 0, 1];
The angle between X and Y changes. Or do I interpret your script wrongly?
Rogier Wolff gives a hint of how to do it, but it is not a complete
solution unfortunately...
Maurice
This is your code. It uses two rotations, one around the y axis and the other
one around the x axis.
You can play with the vectors.
X = [3, -2, .10];
Y = [2, 0, 3];
vector(X, .02, "red");
vector(Y, .02, "blue");
x = X/norm(X); // 1st rotation
X_ = mmult(rotxz(x), [X]); // rot X by X projected to xz
Y1 = mmult(rotxz(x), [Y]); // rot Y by X projected to xz
y = Y1/norm(Y1); // second rotation
Y_ = mmult(rotyz(y), [Y1]); // rot Y1 by Y1 projected to yz
vector(X_, 0.02, "black");
vector(Y_, 0.02, "white");
function rotxz(d) =
[[d[0], 0, d[2]],
[0, 1, 0],
[-d[2], 0, d[0]]];
function rotyz(d) =
[[1, 0, 0],
[0, d[1], d[2]],
[0, -d[2], d[1]]];
function mmult(X, Y) = len(X) != len(Y[0])? undef:
[for(i=[0:len(Y)-1])
[for(j=[0:len(X[0])-1])
X[j]*Y[i]]][0];
module vector(p1=[100,100], r=undef, color=undef, reverse=false)
{
t = reverse?p1:[0,0,0];
s = reverse?-1:1;
r = r==undef?norm(p1)/100:r;
translate(t)scale(s)
if(color) color(color) vec();
else vec();
module vec()
{
l = norm(p1);
v = p1/l;
hull()
{
sphere(r);
translate((l-5*r)v) sphere(r);
}
hull()
{
translate((l-5r)v) sphere(2r);
translate(p1) sphere(r/10);
}
}
}
--
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Sorry, there must be a bug choosing the rotations
The usual solution is to create an orthogonal base and use it as
transformation. So try this:
X = [1, 1, 1];
Y = [0, 0, 1];
vector(X, .02, "red");
vector(Y, .02, "blue");
x = X/norm(X); // unit length
y_ = Y/norm(Y); // unit length
y = y_-x*(x*y_); // orthogonal to x
z = cross(x,y); // orthogonal to x and y
X1 = mmult([x,y,z], [X]);
Y1 = mmult([x,y,z], [Y]);
vector(X1, 0.02, "black");
vector(Y1, 0.02, "white");
function mmult(X, Y) = len(X) != len(Y[0])? undef:
[for(i=[0:len(Y)-1])
[for(j=[0:len(X[0])-1])
X[j]*Y[i]]][0];
--
Sent from: http://forum.openscad.org/
and last but not least: I forgot to unify the lenght of y and z. So the
proper coordinate system is:
x = X/norm(X); //
y_ = Y/norm(Y); //
y1 = y_-x*y_*x; // orthogonal to x
y = y1/norm(y1);
z1 = cross(x,y); // orthogonal to x and y
z = z1/norm(z1);
--
Sent from: http://forum.openscad.org/
The rotated points P1', P2' and P3' are not in the X - Y plane, but that
is no problem, the slicer will fix that.
A simple translate(-P1) before the hull leaves the result on the XY plane.
On Mon, 17 Dec 2018 at 01:39, Parkinbot rudolf@digitaldocument.de wrote:
and last but not least: I forgot to unify the lenght of y and z. So the
proper coordinate system is:
x = X/norm(X); //
y_ = Y/norm(Y); //
y1 = y_-x*y_*x; // orthogonal to x
y = y1/norm(y1);
z1 = cross(x,y); // orthogonal to x and y
z = z1/norm(z1);
--
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org