Hallo,
could someone maybe help me do something against my headache, which has its reason in the buggy patch attached (open "move-in-space.pd")?
Problem: I want to move and scale a primitive like [cube] or [sphere] etc. so that both its ends fall on two given points in the 3D space. I currently use a combination of stretching with scaleXYZ, translating and rotating the [cube]. Lok in [solid-link] for details. It's very likely that I do the rotation stuff wrong, however I can't fidn the right way. Sometimes it sucks being an audio guy primarily.
In just two dimensions what I want to achieve already works as can be seen in attached patch - which requires [list] btw. However as soon as the two points don't fall into the (x,y) plane anymore, that is, one of them has a differenc Z-coordinate than the other, everything falls apart.
I kind of know that the order of rotations probably is wrong, that I should use some kind of matrix transformation instead, quaterions, etc. however I'm so confused now: Any help is appreciated!
Frank Barknecht _ ______footils.org_ __goto10.org__
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 ;)
hope that helps ...
best wishes, tebjan
Frank Barknecht schrieb:
Hallo,
could someone maybe help me do something against my headache, which has its reason in the buggy patch attached (open "move-in-space.pd")?
Problem: I want to move and scale a primitive like [cube] or [sphere] etc. so that both its ends fall on two given points in the 3D space. I currently use a combination of stretching with scaleXYZ, translating and rotating the [cube]. Lok in [solid-link] for details. It's very likely that I do the rotation stuff wrong, however I can't fidn the right way. Sometimes it sucks being an audio guy primarily.
In just two dimensions what I want to achieve already works as can be seen in attached patch - which requires [list] btw. However as soon as the two points don't fall into the (x,y) plane anymore, that is, one of them has a differenc Z-coordinate than the other, everything falls apart.
I kind of know that the order of rotations probably is wrong, that I should use some kind of matrix transformation instead, quaterions, etc. however I'm so confused now: Any help is appreciated!
Ciao
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.
Frank Barknecht _ ______footils.org_ __goto10.org__
hello Frank,
maybee you can have a look at the tLink3D object of the pmpd lib.
just send position of your 2 points on the 2 inlets, you'll have the orientation output in a gem compatible way. hum, i think so, but i never used this object to much...
cyrille
Frank Barknecht a écrit :
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
Hallo, cyrille henry hat gesagt: // cyrille henry wrote:
maybee you can have a look at the tLink3D object of the pmpd lib.
just send position of your 2 points on the 2 inlets, you'll have the orientation output in a gem compatible way.
Using tLink3D surly will make the computatons more effective, however calculating the vector between to points and its length (as tLink does) is not my real problem, the problem is more, how to correctly use this information to draw correct rotations in Gem.
In 2D (polar coordinates) this is simple, but I still haven't found a way to add the missing rotation to go from polar/cartesian to spherical coordinates.
Frank Barknecht _ ______footils.org_ __goto10.org__
hello,
your right, tLink3D does not do this, as i thought. i should fix it.... tLink2D does, but it's easy.
i've got an other patch that is doing this (with only 1 moving point : changing to your nead will be easy i think)
hope it will halp.
Cyrille
Frank Barknecht a écrit :
Hallo, cyrille henry hat gesagt: // cyrille henry wrote:
maybee you can have a look at the tLink3D object of the pmpd lib.
just send position of your 2 points on the 2 inlets, you'll have the orientation output in a gem compatible way.
Using tLink3D surly will make the computatons more effective, however calculating the vector between to points and its length (as tLink does) is not my real problem, the problem is more, how to correctly use this information to draw correct rotations in Gem.
In 2D (polar coordinates) this is simple, but I still haven't found a way to add the missing rotation to go from polar/cartesian to spherical coordinates.
Ciao
#N canvas 571 115 805 813 10; #N canvas 325 151 507 709 cartosphere 0; #X obj 19 25 inlet; #X obj 105 26 inlet; #X obj 192 25 inlet; #X obj 19 84 *; #X obj 105 84 *; #X obj 19 156 +; #X obj 19 177 sqrt; #X obj 192 86 *; #X obj 192 55 t f f; #X obj 103 123 +; #X obj 19 499 outlet; #X obj 164 303 atan; #X obj 164 280 /; #X obj 164 235 pack f f; #X msg 164 258 $2 $1; #X obj 164 328 / 3.14159; #X obj 164 353 * 180; #X obj 164 500 outlet; #X obj 307 288 /; #X obj 307 243 pack f f; #X msg 307 266 $2 $1; #X obj 307 312 acos; #X obj 307 336 / 3.14159; #X obj 307 361 * 180; #X obj 307 500 outlet; #X obj 177 392 moses 0; #X obj 105 53 t f f f f; #X msg 177 416 -180; #X msg 214 416 180; #X obj 177 446 * 0; #X obj 164 472 +; #X obj 20 53 t f f f f; #X obj 69 327 moses 0; #X msg 106 355 0; #X msg 69 355 1; #X obj 69 379 t b f; #X connect 0 0 31 0; #X connect 1 0 26 0; #X connect 2 0 8 0; #X connect 2 0 19 1; #X connect 3 0 5 0; #X connect 4 0 9 0; #X connect 5 0 6 0; #X connect 6 0 10 0; #X connect 6 0 19 0; #X connect 7 0 9 1; #X connect 8 0 7 0; #X connect 8 1 7 1; #X connect 9 0 5 1; #X connect 11 0 15 0; #X connect 12 0 11 0; #X connect 13 0 14 0; #X connect 14 0 12 0; #X connect 15 0 16 0; #X connect 16 0 30 0; #X connect 18 0 21 0; #X connect 19 0 20 0; #X connect 20 0 18 0; #X connect 21 0 22 0; #X connect 22 0 23 0; #X connect 23 0 24 0; #X connect 25 0 27 0; #X connect 25 1 28 0; #X connect 26 0 4 0; #X connect 26 1 4 1; #X connect 26 2 13 1; #X connect 26 3 25 0; #X connect 27 0 29 0; #X connect 28 0 29 0; #X connect 29 0 30 1; #X connect 30 0 17 0; #X connect 31 0 3 0; #X connect 31 1 3 1; #X connect 31 2 13 0; #X connect 31 3 32 0; #X connect 32 0 34 0; #X connect 32 1 33 0; #X connect 33 0 35 0; #X connect 34 0 35 0; #X connect 35 0 29 0; #X connect 35 1 29 1; #X restore 159 355 pd cartosphere; #X obj 83 116 vsl 15 128 -1 1 0 0 empty empty empty 0 -8 0 8 -262144 -1 -1 11600 1; #X obj 204 121 vsl 15 128 -1 1 0 0 empty empty empty 0 -8 0 8 -262144 -1 -1 0 1; #X obj 291 86 vsl 15 128 -1 1 0 0 empty empty empty 0 -8 0 8 -262144 -1 -1 200 1; #X floatatom 178 376 5 0 0 0 - - -; #X floatatom 217 376 5 0 0 0 - - -; #X floatatom 256 376 5 0 0 0 - - -; #X obj 496 323 gemhead; #X obj 498 540 sphere 0.2; #X obj 498 495 translateXYZ; #X obj 479 174 gemhead; #X obj 479 198 world_light; #X msg 553 518 30; #X obj 32 368 gemhead; #X obj 31 450 color 1 0 0; #X obj 238 403 - 90; #X floatatom 251 464 5 0 0 0 - - -; #X obj 238 482 +; #X floatatom 211 447 5 0 0 0 - - -; #X obj 198 465 +; #X floatatom 50 482 5 0 0 0 - - -; #X floatatom 66 500 5 0 0 0 - - -; #X floatatom 82 520 5 0 0 0 - - -; #X obj 32 690 cube 0.5; #X obj 30 739 cube 0.2; #X obj 291 234 * -1; #X obj 31 715 translateXYZ 0.7 0 0; #X floatatom 585 389 5 0 0 0 - - -; #X floatatom 582 416 5 0 0 0 - - -; #X floatatom 548 383 5 0 0 0 - - -; #X obj 496 425 rotateXYZ; #X obj 493 347 rotate -120 1 1 1; #X obj 31 419 rotate -120 1 1 1; #X obj 32 667 rotateXYZ; #X obj 32 533 rotateXYZ; #X obj 32 644 rotateXYZ; #X obj 487 129 gemwin; #X msg 485 90 create , 1; #X obj 160 265 t b f; #X obj 226 282 t b f; #X connect 0 0 4 0; #X connect 0 1 5 0; #X connect 0 1 19 0; #X connect 0 2 6 0; #X connect 0 2 15 0; #X connect 1 0 0 0; #X connect 1 0 9 1; #X connect 2 0 9 2; #X connect 2 0 38 0; #X connect 3 0 25 0; #X connect 7 0 31 0; #X connect 9 0 8 0; #X connect 10 0 11 0; #X connect 12 0 8 2; #X connect 13 0 32 0; #X connect 14 0 34 0; #X connect 15 0 17 0; #X connect 16 0 17 1; #X connect 17 0 33 2; #X connect 18 0 19 1; #X connect 19 0 35 3; #X connect 20 0 34 1; #X connect 21 0 34 2; #X connect 22 0 34 3; #X connect 23 0 26 0; #X connect 25 0 9 3; #X connect 25 0 39 0; #X connect 26 0 24 0; #X connect 27 0 30 2; #X connect 28 0 30 3; #X connect 29 0 30 1; #X connect 30 0 9 0; #X connect 31 0 30 0; #X connect 32 0 14 0; #X connect 33 0 23 0; #X connect 34 0 35 0; #X connect 35 0 33 0; #X connect 37 0 36 0; #X connect 38 0 1 0; #X connect 38 1 0 1; #X connect 39 0 1 0; #X connect 39 1 0 2;
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;
Hallo Tebjan, Tebjan Halm hat gesagt: // Tebjan Halm wrote:
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).
YESSS! Thank you a lot this is working perfectly as intended!
I just changed:
180/3.14159265 * (acos($f3/$f4)-3.14159265/2);
to be:
180/3.14159265 * acos($f3/$f4) - 90;
as that is a bit easier to read any maybe a little bit faster and more accurate as well.
Frank Barknecht _ ______footils.org_ __goto10.org__
Frank Barknecht schrieb:
Hallo Tebjan, Tebjan Halm hat gesagt: // Tebjan Halm wrote:
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).
YESSS! Thank you a lot this is working perfectly as intended!
I just changed:
180/3.14159265 * (acos($f3/$f4)-3.14159265/2);
to be:
180/3.14159265 * acos($f3/$f4) - 90;
as that is a bit easier to read any maybe a little bit faster and more accurate as well.
yeah, of course. was thinking to much in radians ... nice to hear that its working.
adios
Ciao