hi,
was tricky, but there is a more or less easy solution if you use two rotate objects. first rotate around the z axis with:
180/3.14159265 * atan2($f2, $f1);
then rotate the cube around its y axis with:
180/3.14159265 * (acos($f3/$f4)-3.14159265/2);
where $f4 is the length of the diff vector. the subtraction of half pi (90 degree) was found by trial and error ...
attached is the solution (i hope).
have fun !
tebjan
Frank Barknecht schrieb:
Hallo, Tebjan Halm hat gesagt: // Tebjan Halm wrote:
if i understand your patch, you just have to calculate the angles of the spherical coordinates of your second point.
r = length (of your diff vector)
angle 1: atan2( y, z )
angle 2: acos( z/r )
angle3: 0
and remember, two angles are always sufficiant in 3d space ;)
This sounds good and thank you a lot for this clarification. Now with my first rotation around the Z-axis I basically do the transformation to polar coordinates: distance r and angle inside the XY-plane. IIR I then need to rotate again by the angle, that the difference vector has to the xy-plane (often called Phi and basically it is "angle 2")
However while I think I know how to find the correct angle, I still have difficulties to find the *axis* to rotate around. In (my) theory I would need to rotate around the vector, which is the result of the outer/cross product of the difference vector and the z-axis, because that is the vector which is rectangular to both the diff. vector and z-axis. However I already tried that, and it still looks very wrong.
Ciao
#N canvas 444 45 793 669 10; #X obj 514 438 gemwin; #X msg 515 328 0 , destroy; #X msg 603 314 reset; #X msg 587 396 color 0.7 0.7 0.7; #X msg 592 368 color 0 0 0; #X obj 427 341 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X msg 425 361 lighting $1; #N canvas 0 0 1035 704 mouse 0; #X obj 344 498 translateXYZ 1 2 0; #X obj 433 276 gemhead; #X obj 431 297 color 1 0 0; #X obj 149 466 separator; #X obj 344 477 separator; #X obj 124 489 translateXYZ -2 1 0; #N canvas 0 0 450 300 demux 0; #X obj 117 104 list prepend; #X obj 117 70 inlet; #X obj 201 67 inlet; #X obj 117 167 route 0 1; #X obj 116 209 outlet; #X obj 170 210 outlet; #X msg 241 102 2; #X obj 253 81 loadbang; #X connect 0 0 3 0; #X connect 1 0 0 0; #X connect 2 0 0 1; #X connect 3 0 4 0; #X connect 3 1 5 0; #X connect 6 0 0 1; #X connect 7 0 6 0; #X restore 161 245 pd demux; #X obj 160 223 spigot; #X obj 243 228 hradio 15 1 0 3 empty empty empty 0 -6 0 8 -262144 -1 -1 0; #X obj 161 203 pack 0 0; #X msg 274 207 1; #X msg 242 204 0; #X obj 124 516 sphere 0.1; #X obj 345 517 sphere 0.1; #X obj 154 163 - 4; #X obj 162 101 gemmouse 8 8; #X obj 194 174 * -1; #X obj 197 151 - 4; #X obj 73 600 outlet; #X obj 274 277 unpack 0 0; #X obj 161 273 unpack 0 0; #X obj 466 452 inlet z2; #X obj 256 452 inlet z1; #X obj 93 560 list append 0; #X obj 321 594 outlet; #X obj 321 556 list append 0; #X connect 0 0 13 0; #X connect 1 0 2 0; #X connect 2 0 4 0; #X connect 2 0 3 0; #X connect 3 0 5 0; #X connect 4 0 0 0; #X connect 5 0 12 0; #X connect 6 0 20 0; #X connect 6 0 23 0; #X connect 6 1 19 0; #X connect 6 1 25 0; #X connect 7 0 6 0; #X connect 8 0 6 1; #X connect 9 0 7 0; #X connect 10 0 8 0; #X connect 11 0 8 0; #X connect 14 0 9 0; #X connect 15 0 14 0; #X connect 15 1 17 0; #X connect 15 2 7 1; #X connect 15 2 11 0; #X connect 15 4 10 0; #X connect 15 4 7 1; #X connect 16 0 9 1; #X connect 17 0 16 0; #X connect 19 0 0 1; #X connect 19 1 0 2; #X connect 20 0 5 1; #X connect 20 1 5 2; #X connect 21 0 0 3; #X connect 21 0 25 1; #X connect 22 0 5 3; #X connect 22 0 23 1; #X connect 23 0 18 0; #X connect 25 0 24 0; #X restore 220 261 pd mouse; #X obj 160 189 gemhead; #X obj 160 381 cube 1; #X obj 160 296 solid-link; #X obj 166 523 gemhead; #X obj 166 547 world_light; #X floatatom 220 235 5 0 0 2 Z1 - -; #X floatatom 277 236 5 0 0 2 Z2 - -; #X obj 304 292 gemhead; #X obj 304 322 color 0 1 0; #X obj 304 350 curve 2; #X msg 511 287 create , lighting 1 , 1; #X text 165 81 Create Gemwin , then move red spheres with left and right mouse button.; #X msg 241 209 2; #X text 161 121 After that , change Z1 or Z2 , and move red spheres again. Why is the white cube wrong now??; #X connect 1 0 0 0; #X connect 2 0 0 0; #X connect 3 0 0 0; #X connect 4 0 0 0; #X connect 5 0 6 0; #X connect 6 0 0 0; #X connect 7 0 10 1; #X connect 7 0 17 1; #X connect 7 1 10 2; #X connect 7 1 17 2; #X connect 8 0 10 0; #X connect 10 0 9 0; #X connect 11 0 12 0; #X connect 13 0 7 0; #X connect 14 0 7 1; #X connect 15 0 16 0; #X connect 16 0 17 0; #X connect 18 0 0 0; #X connect 20 0 13 0;
#N canvas 670 101 527 611 10; #X obj 105 164 unpack 0 0 0; #X obj 401 543 sphere 1; #X obj 83 62 inlet; #N canvas 118 218 991 636 vec-minus 0; #X obj 45 401 outlet; #X obj 45 142 inlet; #X obj 45 175 unpack 0 0 0; #X obj 153 148 inlet; #X obj 183 215 unpack 0 0 0; #X obj 45 267 expr $f4 - $f1 ; $f5 - $f2 ; $f6 - $f3; #X obj 45 325 pack 0 0 0; #X text 105 401 difference vector; #X obj 153 175 t b a; #X connect 1 0 2 0; #X connect 2 0 5 0; #X connect 2 1 5 1; #X connect 2 2 5 2; #X connect 3 0 8 0; #X connect 4 0 5 3; #X connect 4 1 5 4; #X connect 4 2 5 5; #X connect 5 0 6 0; #X connect 5 1 6 1; #X connect 5 2 6 2; #X connect 6 0 0 0; #X connect 8 0 5 0; #X connect 8 1 4 0; #X restore 262 125 pd vec-minus; #X obj 237 53 inlet; #X obj 329 53 inlet; #N canvas 0 0 430 223 distance 0; #X obj 51 115 outlet; #X text 110 117 distance; #X obj 51 80 expr sqrt($f1*$f1 + $f2*$f2 + $f3*$f3); #X obj 51 34 inlet; #X connect 2 0 0 0; #X connect 3 0 2 0; #X restore 299 187 pd distance; #N canvas 511 187 655 437 calc-rotate 0; #X obj 40 217 outlet; #X obj 311 221 outlet; #X text 79 266 rotations; #X obj 40 70 inlet; #X text 330 131 f1: diff x; #X text 331 145 f2: diff y; #X text 331 160 f3: diff z; #X obj 263 70 inlet; #X text 45 238 Z; #X text 312 245 Y; #X floatatom 367 222 5 0 0 0 - - -; #X obj 40 139 expr 180/3.14159265 * atan2($f2 , $f1) ; 180/3.14159265
#X connect 3 0 11 0; #X connect 7 0 11 3; #X connect 11 0 0 0; #X connect 11 1 1 0; #X connect 11 1 10 0; #X restore 220 223 pd calc-rotate; #X obj 262 152 t a a a; #X obj 237 85 t a a; #X obj 83 529 outlet; #X text 333 541 to e.g.:; #X text 85 37 gemhead; #X text 236 26 first point; #X text 327 25 second point; #X obj 363 327 * 0.5; #X obj 83 262 rotateXYZ 0 0 0; #X obj 83 498 scaleXYZ 1 0.1 0.1; #X obj 83 355 rotateXYZ 0 0 0; #X obj 83 413 translateXYZ 0 0 0 0; #X obj 83 222 translateXYZ; #X connect 0 0 20 1; #X connect 0 1 20 2; #X connect 0 2 20 3; #X connect 2 0 20 0; #X connect 3 0 8 0; #X connect 4 0 9 0; #X connect 5 0 3 1; #X connect 6 0 15 0; #X connect 6 0 7 1; #X connect 7 0 16 3; #X connect 7 1 18 2; #X connect 8 1 7 0; #X connect 8 2 6 0; #X connect 9 0 0 0; #X connect 9 1 3 0; #X connect 15 0 17 1; #X connect 15 0 19 1; #X connect 16 0 18 0; #X connect 17 0 10 0; #X connect 18 0 19 0; #X connect 19 0 17 0; #X connect 20 0 16 0;