[PD] GEM/math: correctly rotating in space

Frank Barknecht fbar at footils.org
Fri Oct 14 20:26:08 CEST 2005


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
-- 
 Frank Barknecht                 _ ______footils.org_ __goto10.org__
-------------- next part --------------
#N canvas 0 0 789 665 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 1
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;
-------------- next part --------------
#N canvas 444 396 522 592 10;
#X obj 151 163 unpack 0 0 0;
#X obj 83 338 rotateXYZ;
#X obj 83 222 translateXYZ;
#X obj 224 480 sphere 1;
#X obj 83 96 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 267 159 pd vec-minus;
#X obj 237 87 inlet;
#X obj 346 87 inlet;
#N canvas 0 0 426 219 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 289 316 pd distance;
#N canvas 396 210 635 417 calc-rotate 0;
#X obj 30 211 outlet;
#X obj 141 209 outlet;
#X obj 253 211 outlet;
#X text 35 232 X;
#X text 69 260 rotations;
#X text 142 233 Y;
#X text 260 234 Z;
#X obj 40 135 expr 180/3.14159 * atan($f3/$f2) \; 180/3.14159 * atan($f1/$f3)
\; 180/3.14159 * atan($f2/$f1);
#X obj 40 91 inlet;
#X text 315 128 f1: diff x;
#X text 316 142 f2: diff y;
#X text 316 157 f3: diff z;
#X connect 7 0 0 0;
#X connect 7 1 1 0;
#X connect 7 2 2 0;
#X connect 8 0 7 0;
#X restore 311 207 pd calc-rotate;
#X obj 267 181 t a a a;
#X obj 237 119 t a a;
#X obj 83 477 outlet;
#X text 156 478 to e.g.:;
#X text 85 71 gemhead;
#X text 236 60 first point;
#X text 344 59 second point;
#X obj 123 383 * 0.5;
#X floatatom 237 367 5 0 0 0 - - -;
#X obj 83 409 scaleXYZ 1 0.1 0.1;
#X obj 83 249 translate 0.5 0 0 0;
#X obj 237 384 t b f;
#X connect 0 0 2 1;
#X connect 0 1 2 2;
#X connect 0 2 2 3;
#X connect 1 0 19 0;
#X connect 2 0 20 0;
#X connect 4 0 2 0;
#X connect 5 0 10 0;
#X connect 6 0 11 0;
#X connect 7 0 5 1;
#X connect 8 0 17 0;
#X connect 9 0 1 1;
#X connect 9 1 1 2;
#X connect 9 2 1 3;
#X connect 10 0 20 2;
#X connect 10 1 8 0;
#X connect 10 2 9 0;
#X connect 11 0 0 0;
#X connect 11 1 5 0;
#X connect 17 0 19 1;
#X connect 18 0 21 0;
#X connect 19 0 12 0;
#X connect 20 0 1 0;
#X connect 21 0 17 0;
#X connect 21 1 17 1;


More information about the Pd-list mailing list