### [SFML][Vector] Problem with Polar and Cartesian Coordinates convertion

In a testing SFML project of mine, I've made 3 `sf::CircleShape`'s: a big one, 2 small ones. The 2 small ones are supposed to be moving slowly around the center of the big one about 60px. They do move around but too fast. There must be something wrong with my calculations.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142`` `````` int direction = 0; sf::CircleShape ball(50); //the big one, radius: 50 ball.setPosition(100, 100); //position: 100, 100 ball.setFillColor(sf::Color(0, 165, 235)); ball.setOutlineThickness(2); ball.setOutlineColor(sf::Color::Black); sf::CircleShape arm[2]; //2 small ones for (int i = 0; i < 2; i++) { arm[i].setRadius(10); //radius: 10 arm[i].setFillColor(sf::Color(0, 165, 235)); arm[i].setOutlineThickness(2); arm[i].setOutlineColor(sf::Color::Black); } sf::Vector2f vector1, //vector from the big one's center to one of the small ones' center vector2(ball.getPosition() + sf::Vector2f(ball.getRadius(), ball.getRadius())), //location of the big one's center point vector3(arm[0].getRadius(), arm[0].getRadius()); //the center points of the 2 small ones move around not position while (Window.isOpen()) { // the loop sf::Event Event; if (Window.pollEvent(Event)) { if (Event.type = sf::Event::KeyPressed) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) direction++; else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) direction--; } //move the 2 small ones around with left and right arrow keys } if (direction == 360) direction = 0; else if (direction == -1) direction = 359; // I think there must be something wrong here vector1.x = (ball.getRadius() + ball.getOutlineThickness() + 5) * cos(direction); vector1.y = (ball.getRadius() + ball.getOutlineThickness() + 5) * sin(direction); arm[0].setPosition(vector2 + vector1 - vector3); //location center of the big one + vector to one of the small oness center - vector to one of the small ones' (0, 0) point arm[1].setPosition(vector2 - vector1 - vector3); }``````
Just a quick guess: you think that the arguments for sin and cos are degrees. They are radians. So cos(direction) should be replaced by cos(direction*M_PI/180.) Same for sin.
I `#include `d `math.h` but the compiler is complaining
 identifier 'M_PI' is undefined

Edit: Nevermind
Thanks. It works
Last edited on
Topic archived. No new replies allowed.