#### Archived

This topic is now archived and is closed to further replies.

# Rotating a 2D array

This topic is 6498 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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,

##### Share on other sites
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

##### Share on other sites
cool.
thanks.

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

I think I can work with that code though

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631758
• Total Posts
3002137
×