school's back, and so am i :D

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2006
Posts: 1,169
Reputation: Duki has a spectacular aura about Duki has a spectacular aura about Duki has a spectacular aura about 
Solved Threads: 9
Duki's Avatar
Duki Duki is offline Offline
Veteran Poster

school's back, and so am i :D

 
0
  #1
Aug 28th, 2007
Hey everyone, I'm back in C++ this semester; Last semester I went through Structured C++ (and passed with a 4.0; many thanks to all of you!) and this semester I'm in OOP.

I don't have sample code yet because I haven't started. But I was talking to a classmate, and one of our programming exercises wants us to write a function that will modify a point (i.e., (3, 2)) so that it will rotate it 90 degrees, clockwise. Is there an easier way to do this rather than 5 or 6 "If" statements?


Example scenario:

I input point x as 3 and point y as 2. I select the option to rotate the point by 90 degrees and should get x as 2 and y as -3.
Last edited by Duki; Aug 28th, 2007 at 5:41 pm.
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.

-Edsger Dijkstra
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: school's back, and so am i :D

 
0
  #2
Aug 28th, 2007
How do you rotate a point? A point is a point, there's no kind of transformation you can do until you have more than one.
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: school's back, and so am i :D

 
1
  #3
Aug 28th, 2007
Don't they teach simple geometry in schools any more?
http://mathworld.wolfram.com/RotationMatrix.html
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 130
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: school's back, and so am i :D

 
0
  #4
Aug 28th, 2007
Originally Posted by Hamrick View Post
How do you rotate a point? A point is a point, there's no kind of transformation you can do until you have more than one.
I haven't taken a math class in many, many years, but from what I can recall, you rotate a point by drawing a vector starting at the origin and passing through the point, and then rotate that vector 90 degrees, in this case.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 486
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 48
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: school's back, and so am i :D

 
0
  #5
Aug 28th, 2007
Originally Posted by cscgal View Post
I haven't taken a math class in many, many years, but from what I can recall, you rotate a point by drawing a vector starting at the origin and passing through the point, and then rotate that vector 90 degrees, in this case.
Yes that's right, but it assumes you're rotating about the origin Either way, the origin is a point, so, as hamrick said, you need two points in order to rotate something.
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,335
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 236
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: school's back, and so am i :D

 
0
  #6
Aug 28th, 2007
I like to do problems that are new to me. I found a few lines of trigonometry did just dandy.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 1,169
Reputation: Duki has a spectacular aura about Duki has a spectacular aura about Duki has a spectacular aura about 
Solved Threads: 9
Duki's Avatar
Duki Duki is offline Offline
Veteran Poster

Re: school's back, and so am i :D

 
0
  #7
Aug 28th, 2007
Thanks Dave; any tips as to which ones?

Hamrick: sorry I didn't clarify. There is an assumed point (i'm guessing) that is constant at (0,0).
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.

-Edsger Dijkstra
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 1,169
Reputation: Duki has a spectacular aura about Duki has a spectacular aura about Duki has a spectacular aura about 
Solved Threads: 9
Duki's Avatar
Duki Duki is offline Offline
Veteran Poster

Re: school's back, and so am i :D

 
0
  #8
Aug 28th, 2007
x' = x * cosine(90) + y * sine(90)
y' = x * sine(90) - y * cosine(90)

that look right?

edit] i think these are the right ones:

rx = x * cos(90) + y * sin(90) ;
ry = y * cos(90) - x * sin(90) ;
Last edited by Duki; Aug 28th, 2007 at 10:46 pm.
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.

-Edsger Dijkstra
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,335
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 236
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: school's back, and so am i :D

 
0
  #9
Aug 28th, 2007
  1. point(double x_ = 0, double y_ = 0)
  2. : x(x_), y(y_),
  3. radius(std::sqrt(x * x + y * y)),
  4. angle(std::atan(y / x))
  5. {
  6. }
  7. void rotate(double radians)
  8. {
  9. angle = std::fmod(angle + radians, 2 * pi);
  10. x = radius * cos(angle);
  11. y = radius * sin(angle);
  12. }
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 1,169
Reputation: Duki has a spectacular aura about Duki has a spectacular aura about Duki has a spectacular aura about 
Solved Threads: 9
Duki's Avatar
Duki Duki is offline Offline
Veteran Poster

Re: school's back, and so am i :D

 
0
  #10
Aug 28th, 2007
Ok, here's how I am doing it; is this wrong?

  
  1. #include <cmath>
  2. #include <iostream>
  3. using namespace std ;
  4.  
  5. int main ()
  6. {
  7. int x ;
  8. int y ;
  9. double angle ;
  10. int rx ;
  11. int ry ;
  12.  
  13. angle = 90 ;
  14. x = 3 ;
  15. y = 2 ;
  16. rx = x * cos(angle) + y * sin(angle) ;
  17. ry = y * cos(angle) - x * sin(angle) ;
  18.  
  19. cout << rx << " " << ry << endl ;
  20.  
  21. return 0 ;
  22. }

something is wrong, because for x i get 0 output, but when i do it in my calculator i get the right answer (2) !
Last edited by Duki; Aug 28th, 2007 at 10:59 pm.
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.

-Edsger Dijkstra
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC