Thanks for the input guys. However i have wrote this and i have a problem, so any help would be great.
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
int main()
{
int x = 0;
int y = 380;
int clickX = 40;
int clickY = 360;
float angleRadians,angleDregees,maxVelocity;
float xVel,yVel;
int b;
maxVelocity = 100;
//The angle in radians
angleRadians = atan((y-clickY)/(clickX-x));
//The angle in degrees
angleDregees = (angleRadians * 180 / M_PI);
//velocitys
xVel = ceil(((90-angleDregees)/90)*maxVelocity);
yVel = ceil((angleDregees/90)*maxVelocity);
std::cout << "angle in radians :" << angleRadians << std::endl;
std::cout << "angle in degees :" << angleDregees << std::endl;
std::cout << "xVelocity :" << xVel << std::endl;
std::cout << "yVelocity :" << yVel << std::endl;
std::cin >> b;
}
It ethier gives me 100 xVel or 100 yVel or 50/50. When i change the values, thanks for any help
When working with floats or doubles, you should make your literals obviously floats; change 90 to 90.0f
However, why aren't you using sin and cos to determine the vector for y and x? 1st, look into using atan2, not atan. 2nd, don't convert from radians to degrees, 3rd, do this:
xVel = cos(angleDregees)*maxVelocity);
yVel = sin(angleDregees)*maxVelocity);
That should give you want you want.