473,769 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2299
"JustSomeGu y" <no**@nottellin g.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
"JustSomeGu y" <no**@nottellin g.com> wrote in message
news:FEwvc.6547 89$Ig.380269@pd 7tw2no...
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
2691
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 angle, but this rotates the whole drawing of the stars but what I realy want is for the stars to rotate round it's center point, is this possible? I hope I was clear enough in my explanation. Thanks in advance
17
29416
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
3075
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 arrow key, to rotate the object until its pointed to the right. i tried using a drawing matrix to accomplish this, but all it did was rotate my entire form (im drawing my object on the back of the form) and thats not what i need. I need it to rotate...
8
11047
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 makes one more copy of the original matrix, how is the efficiency? Can the copy be saved? Comments on it are welcome. Can I extend it to work on a matrix of any size (or even any type, not just integers) for the logic may be the same when it...
0
2396
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 square matrix.
2
13329
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 atleast help me in finding inverse of a ordinary n*n square matrix in java
3
5125
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
8096
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 involving lot of matrices. At one point I need to calculate the square root of a matrix e.g. A which contains non-zero off-diagonal elements. I searched for a lot of info on net but no algorithm worked. My best bet for finding square root was to find...
4
3421
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 funcations,The first funcation makes a squence which the user input where it begins and the differents between easch elements the size of this one dimensional array is 16. the second funcation puts the elements of the one dimensional arry into a two...
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10051
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.