| | |
school's back, and so am i :D
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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.
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
-Edsger Dijkstra
Don't they teach simple geometry in schools any more?
http://mathworld.wolfram.com/RotationMatrix.html
http://mathworld.wolfram.com/RotationMatrix.html
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.
•
•
•
•
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.
Either way, the origin is a point, so, as hamrick said, you need two points in order to rotate something.
¿umop apisdn upside down? 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
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).

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
-Edsger Dijkstra
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) ;
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
-Edsger Dijkstra
C++ Syntax (Toggle Plain Text)
point(double x_ = 0, double y_ = 0) : x(x_), y(y_), radius(std::sqrt(x * x + y * y)), angle(std::atan(y / x)) { } void rotate(double radians) { angle = std::fmod(angle + radians, 2 * pi); x = radius * cos(angle); y = radius * sin(angle); }
"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
Ok, here's how I am doing it; is this wrong?
something is wrong, because for x i get 0 output, but when i do it in my calculator i get the right answer (2) !
c++ Syntax (Toggle Plain Text)
#include <cmath> #include <iostream> using namespace std ; int main () { int x ; int y ; double angle ; int rx ; int ry ; angle = 90 ; x = 3 ; y = 2 ; rx = x * cos(angle) + y * sin(angle) ; ry = y * cos(angle) - x * sin(angle) ; cout << rx << " " << ry << endl ; return 0 ; }
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
-Edsger Dijkstra
![]() |
Similar Threads
- To Degree or not to Degree - that is my question (IT Professionals' Lounge)
- Which of these current affairs most worries you? (IT Professionals' Lounge)
- Ramm (Motherboards, CPUs and RAM)
- Sleep (Geeks' Lounge)
- What Certifications do You Have? (IT Professionals' Lounge)
- Random Files (Introduction) (Visual Basic 4 / 5 / 6)
- OK im restarting (C++)
- Something wrong with windows XP (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: binary code
- Next Thread: please help
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






