Advertisement

Rotating a 2D array

Started by October 04, 2000 01:50 PM
1 comment, last by jollyjeffers 24 years, 3 months ago
hi, say I have an array of points (2D) [9][9] in a standard pattern: 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 how can I rotate them all about 45 degrees? say I have the origin as the point at [0][9] - and I rotate them all around that.... it''d basically end up looking like an isometric diamond... any help is much appreciated.. Jack,

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Rotating in 2D, that''s like rotating around the z-axes. Lemme see...

Should be sum like this :

Point3D Rotate3D(Point3DT P, angle_z)
{
long rx = 0, ry = 0, rz = 0;
long angle_x = 0;
long angle_y = 0;
ry = cos(angle_x) * P.y - sin(angle_x) * P.z;
rz = sin(angle_x) * P.y + cos(angle_x) * P.z;
rx = cos(angle_y) * P.x + sin(angle_y) * rz;
P.z = -sin(angle_y) * P.x + cos(angle_y] * rz;
P.x = cos(angle_z) * rx - sin(angle_z) * ry;
P.y = sin(angle_z) * rx + cos(angle_z) * ry;
return( P );
}

Now, you must assign a 3D point to every point in your array (shouldn''t be so tough, just set the z to... 1, and the x and y to equal the position in the array), and rotate...

Divide Overflow

"Ergos locus" -- Anonymous
Advertisement
cool.
thanks.

I''m currently only working in 2D though.

I think I can work with that code though

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement