rotate([45,45,0])

rotate([45,45,0])

hi
i dont like this instruction because it is not clear in the formalism wether
x or y are calculated first
see this example, where tube is any module :
//rotate([0,45,0]) rotate([45,0,0]) tube();
rotate([45,0,0]) rotate([0,45,0]) tube();
rotate([45,45,0]) tube();

now, i needed something to automatically put a z-oriented object (say, a
cylinder) to any [x,y,z] direction
if it can be usegul :

Re: rotate([45,45,0])

hi
i am working on your codes, but i enconter something that i dont understand :
if (3!=0) {a=2;echo(a);}
echo(a);
the second echo(a); returns "undef" as if the variable a was defined only inside the {if}
how shall i understand this ?
Vincent

Re: rotate([45,45,0])

On 5/18/2018 12:18 AM, Vincent Douce
Mathoscope wrote:

hi
i am working on your codes, but i enconter something that i dont understand :
if (3!=0) {a=2;echo(a);}
echo(a);
the second echo(a); returns "undef" as if the variable a was defined only inside the {if}
how shall i understand this ?

This might well be the most common OpenSCAD question.

OpenSCAD variables... aren't variables. They're constants, sort
of, with the last assignment winning and with inner scopes able to
override values from outer scopes. You can't change them, or at
least not exactly, and you especially can't change them inside an
"if".

x=1;
echo(x=x);
x=2;
echo(x=x);

produces

ECHO: x = 2
ECHO: x = 2

and

x=1;
echo(x=x);
if (true) {
x=2;
echo (x=x);
}
echo (x=x);

produces

ECHO: x = 1
ECHO: x = 2
ECHO: x = 1

If you need to set a value conditionally, you need to use the ? :
operator, e.g.

Also, note that your code is not a one-step rotation as you described in
"put a z-oriented object (say, a
cylinder) to any [x,y,z] direction". There's an extra twist other than the
rotation from z to [x,y,z].

Suppose we want to rotate a cube from *P=[0,0,4]* to *Q=[2,2,2]*. This would
imply a rotation about axis [[-1,1,0],[0,0,0],[1,-1,0]] (red line below) by
an angle= *54.7356* :

I'm not sure if that's intended. The twist is hard to spot if the starting
obj is a cylinder aligning w/ the z-axis. IMO, the extra twist makes it
harder to use in the context of "put a z-oriented objec to any [x,y,z]
direction".

Re: rotate([45,45,0])

​The point is that there is an infinite set of rotations that bring a vector to another.​ For instance,

rotFromTo(w,d0) rotFromTo(di,w)

​is able to bring di to do with a different rotation for (almost) any ​other vector w.

rotFromTo chooses one specific rotation among that set: the rotation with the minimum angle. The minimum rotation is unique and well defined: its axis is cross(di,do).

In general, module pointvers(v) does not compute the minimum rotation (except in trivial cases). That is fine but it has a major drawback: it is not continuous in v. I would expect that for v very near to [0,0,1],
pointvers(v) be very near to the identity and that is not true. For v near to [0,0,1], the internally computed angle phi is near to 0 but theta is not.

Re: rotate([45,45,0])

is a bit too simplified (thus misleading) for what pointervers(v) does, 'cos
other than "bringing [0,0,1] to v", it also makes a swing of the obj, which
is evident if you compare the the figures I attached.

Re: rotate([45,45,0])

@runsun

I agree with your observations. I just wanted to clarify that what you call the "swing" produced by pointvers(v) is an additional rotation around axis v (with an angle that depends on v). So it meets the requirement of bringing [0,0,1] to v but adds another rotation on that. It is not a minimum rotation like mine.

is a bit too simplified (thus misleading) for what pointervers(v) does, 'cos
other than "bringing [0,0,1] to v", it also makes a swing of the obj, which
is evident if you compare the the figures I attached.