[PD] Advice: best way to do matrix-rotation in PD

B. Bogart ben at ekran.org
Sat Apr 2 22:05:59 CEST 2005

Hey Frank,

How do I specify the angle of rotation using matrix multiplication?

Code I have used in the past has been:

   for(i=0; i<8; i++)
     tx = cos(zangle)*(points[i][0])+sin(zangle)*(points[i][1]);
     x1 = cos(yangle)*(tx)+sin(yangle)*(points[i][2])+200;
     y1 = (-sin(zangle))*(points[i][0])+cos(zangle)*(points[i][1])+200;
     z1 = (-sin(yangle))*(tx)+cos(yangle)*(points[i][2]);

where "points" stores the positions of each point in a shape. I is the
point # (8 points for a cube in this case) and [0]:X, [1]:Y and [2]:Z)

So the new position is set based on the previous position. What I can't
remeber is what tx is for... when I already have x1, y1 and z1....

Using zexy can I just store the current position of the points in an
matrix, do the rotation and replace the old positions with the rotated
ones? Then the matrix itself is what stores the points and I'll dump it
out as messages to set the control points.

I'll take a peek at the zexy matrix stuff...

Thanks for the tips.

Frank Barknecht wrote:
> Hallo,
> B. Bogart hat gesagt: // B. Bogart wrote:
>>So I had the great idea of using matrix rotation to rotate the control
>>points on various axes to distort the cube. In order to get this to work
>>I need to solve two problems:
>>A. I need to be able to do matrix-rotation fast and efficiently, and I'd
>>rather not need an external to do it!
> I'm not sure that I understand what exactly you want to do, but to me
> it sounds as if this would be a simple task for zexy's matrix/mtx
> objects. Matrix rotation then simply is a multiplication of two
> matrices using [mtx_mult] rsp. [mtx_*] The only real problem then
> would be point B:
>>B. I need to query the current position of each point before I can
>>rotate it.
> namely building the matrices from the 3D data, but the needed data
> probably already is available somewhere.
> Of course zexy is an external library, but I suppose it's installed
> more often than [py].
> Ciao
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20050402/9b846e64/attachment.pgp>

More information about the Pd-list mailing list