473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Rotate non square matrix 180... Not working...

mx = Cols/2;
if ((mx * 2) != Cols) // Odd.
++mx;
}

for (y1=0; y1 < Rows; ++y1)
{
y2 = Rows-1 - y1;

for (x1=0; x1 < mx; ++x1)
{
x2 = Cols-1 - x1;

p = t[y1][x1];
t[y1][x1] = t[y2][x2];
t[y2][x2] = p;
}
}
This code doesn't seem to do the center column of
a matrix whos dimensions are odd on the x dimensions...
Can any one see why? I tried I don't see it...
Jul 22 '05 #1
2 2279
"JustSomeGuy" <no**@nottelling.com> wrote...
mx = Cols/2;
if ((mx * 2) != Cols) // Odd.
++mx;
}
This closing curly brace seems misplaced. Besides, you could
simply write

mx = (Cols+1)/2;

instead of three lines above, no?

for (y1=0; y1 < Rows; ++y1)
{
y2 = Rows-1 - y1;

for (x1=0; x1 < mx; ++x1)
{
x2 = Cols-1 - x1;

p = t[y1][x1];
t[y1][x1] = t[y2][x2];
t[y2][x2] = p;
}
}
This code doesn't seem to do the center column of
a matrix whos dimensions are odd on the x dimensions...
Can any one see why? I tried I don't see it...


You probably rotate the middle twice. Try doing it by
hand and see where you screw up.

Victor
Jul 22 '05 #2
"JustSomeGuy" <no**@nottelling.com> wrote in message
news:FEwvc.654789$Ig.380269@pd7tw2no...
mx = Cols/2;
if ((mx * 2) != Cols) // Odd.
++mx;
}

for (y1=0; y1 < Rows; ++y1)
{
y2 = Rows-1 - y1;

for (x1=0; x1 < mx; ++x1)
{
x2 = Cols-1 - x1;

p = t[y1][x1];
t[y1][x1] = t[y2][x2];
t[y2][x2] = p;
}
}
This code doesn't seem to do the center column of
a matrix whos dimensions are odd on the x dimensions...
Can any one see why? I tried I don't see it...


You're swapping the center column twice.

Here's one solution:

// rotate top half with bottom half
int y1 = 0;
int y2 = Rows-1;
for (; y1 < y2; ++y1, --y2)
{
int x2 = Columns-1;
// swap all columns
for (int x1 = 0; x1 < Columns; ++x1, --x2)
swap( t[y1,x1], t[y2,x2] );
}
// odd number of rows? rotate middle row
if (y1 == y2)
{
int x2 = Columns-1;
// only swap left with right (to prevent swapping twice)
for (int x1 = 0; x1 < x2; ++x1, --x2)
swap( t[y1,x1], t[y1,x2] );
}

-Howard

"All programmers write perfect code.
....All other programmers write crap."

"I'm never wrong.
I thought I was wrong once,
but I was mistaken."

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Peter Proost | last post by:
Hi group, I got the following piece of code which draws a square with stars round it, now I want the stars to rotate round the square, I can do this with the mx.rotate and a timer and an...
17
by: santel_helvis | last post by:
Hi All, Could anyone tell me how to rotate the image in javascript. Which concepts I should concentrate to rotate the image
1
by: iwdu15 | last post by:
hi, im trying to rotate a gdi drawn object on my form with a keypress....forinstance when i push the down arrow, for it to rotate the object drawn until the top is down, or if i push the right...
8
by: lovecreatesbeauty | last post by:
I write a function to rotate a matrix by 90 degrees clockwise, this function works on a matrix of specific size, for example, it rotates a 4*4 matrix of integers in the following code. The function...
0
by: YUSUF ISIAKA | last post by:
Him please help me with the codes for the following questions: 1. Write a program in c/c++ to compute the inverse of a square matrix. 2. Write a program in c/c++ to compute the determinant of a...
2
by: leelaramtenneti | last post by:
hello I need a program to find a Inverse of a square complex matrix in java... . The program should calculate the inverse of a matrix in which each element has both real and imaginary parts. Or...
3
by: Diego F. | last post by:
Hi all. I have a listview with images and my application must be able to rotate one image. I need a method to rotate 90 degrees rigth (i.e.). Is that possible? -- Regards, Diego F.
4
by: krishnai888 | last post by:
I had already asked this question long back but no one has replied to me..I hope someone replies to me because its very important for me as I am doing my internship. I am currently writing a code...
4
by: inferi9 | last post by:
Hi, I am working in a program caals magic square and it must be done only with loops and user definied funcations,I will tell you about my code and where my problem, the main is only calls the other...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.