i'm working on a robotics project, to move the robot from it's current position to target position i need to calculate the angle first before i can move the robot.this the code I use to calculate the angle:
double cal_angle ( int current_x , int current_y , int tar_x , int tar_y )
{
return atan2(tar_y - current_y, tar_x - current_x);
}
int main ()
[code]....
as u can see the angle between x4,y4 to x1,y1 should be 3.14 (180)however , the result are correct as long as the distance from the current position to target position > 1 (not sure actually).
I am making a game and I am trying to rotate an image so that it is always pointing at the player. I have two lines, the first point of both of them is on the image and the second point of one line is on the last position of the player, and the second point of the other one is on the current position of the player. To rotate the image I need to get the angle between the two lines. how I can get that angle with only the points from the lines?
I'm trying to make a bullet bounce after it hits a wall. I think bouncing on the top and bottom wall works perfectly, but it won't bounce off of the left and right walls. How would I get it to bounce? This is how I get the direction the bullet it going whenever I shoot.
On a right angled triangle, if the user inputs only ONE side length (not the hypotenuse) and only ONE angle, what code is required to work out the hypotenuse? I know how to work out the final side and the remaining angle once I have this.
Let (x,y) be the center of the circle. (x,y) will not be (0,0). I have radius of the circle. Now i want to find the angle and radius of the given point inside the circle.
In a cartesian coordinate system, I want to be able to predict a compass angle of an object. So I have a base position of (0,0) and then a distance and compass angle to an object. This object also has a heading and a speed. How can I predict the new compass angle of the object with that information?
my coordinate system is like this:
Code: 0 y | | 270-------------- 90 x | | 180
I think the first step would be to compute the cartesian coordinates of the object:
float degs_to_rads = 3.141592653589793 / 180.0; x = distance * sin(angle*degs_to_rads); y = distance * cos(angle*degs_to_rads);
then the next step would be to compute the predicted x and y from the speed and heading of the object:
predictedx = ?? predictedy = ??
then finally convert back to an angle, and distance:
I have completed the codes for the interface part. Before I proceed with the formula for the trigonometric functions, I would like to make sure the program is Error-free, which if there is accidental invalid input from the user, the program would the user to enter another input until it is a valid response.
The only problem I have encountered for this matter was in menu(value)
If I enter an integer, the program will proceed without error. However, If I enter a character, the program will slip into an endless loop which constantly shows this
*****Trigonometry Program***** Please enter an angle value => Is the angle in Degree or Radian? Type D if it is in Degree Type R if it is in Radian Your response=> 0 //my initial input for value
Do you want to continue? Type Y to continue Type any other key to stop Your response =>
Where is the source of the problem? I'm pretty sure it's the loop, but I don't know what to do.
I want to make an object, which moves from x1,y1 to x2,y2 in a straight line, also make a sinus over the line (so the x,0 is the line itself, and cux,cury is the object. So the object will move as a sinus over the line. How do I do this in c++?
Write a program that creates the output shown in the Output Layout section below. The program should create 2 points with x and y coordinates as integers, prompt the user to input the x and y values for one of the points and randomly set the other (-99 to 99 range) and output the length of the radius line segment and the area of the circle that radius defines. The program should then end. Include an SDM for the program and any other appropriate documentation.
Special Calculations: Distance between 2 points equation: √((p0x – p1x)2 + (p0y – p1y)2) (This requires use of the math library)
Output Layout: (bold text represents user input)
Please enter the location of your first point. Enter a value from -99 to 99 for your x coordinate: -2 Enter a value from -99 to 99 for your y coordinate: 17
The location of your second randomly set point. Your x coordinate: 45 Your y coordinate: -89
The length of the radius line segment from point one to point two is 115. The area of the circle with a radius of 115 is 41546.33.
I'm implementing a quad tree for an assignment, and I'm not sure if every node should contain a list of pointers to every Point in its sub tree (implying the root node will contain all Points), or if only leaf nodes should contain the Points.
Today i am going find out solution of two ellipses intersection points using C programming, I solved using geometry equation substitute method but i am not unable to do same thing in C programming.I am talking example as following two ellipses (x^2)/4+y^2=1 , ((x-2)^2)/4+y^2=1
As homework we were assigned to enter the following code to calculate the distance between two points on the x and y plane. The program should ask the user to enter two points then should calculate the distance between two points and print the distance on the screen.
My program will compile correctly but when attempting to run the actual program it doesnt do anything and some how completely skips over my main function...
I have a program that is trying to find all factors of an integer given. It needs to be done in a recursion function. Right now i have code similar to just getting the prime factors of a integer.
unsigned int * find_factors_using_recursion(unsigned int x ) { unsigned int * factor = new unsigned int[];//do i put x in here ? for(unsigned int i = 2; i < x; ++i) { if(x % i == 0) { find_factors_using_recursion(x / i); *factor = (factor[i] = i); } } return factor; delete [] factor; }
When i cout the *factor = (factor[i] = i) it gives me the prime numbers of the integer passed into the function but when I return the pointer it only returns one of the prime numbers. I'm new to c++, how to return pointers from functions that would be great with an example to go with it.
I'm creating a quick program to calculate midpoint and distance between two points. I'm having a little trouble. This is the program:
//This program is a start to solve basic coordinatre plane distances and midpoints #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> using namespace std; int main(int nNumberofArgs, char* pszArgs[]){ cout << "This is a calculator to find distance and the midpoint between two points. " ;
[Code]...
the problem is that the output for both equations is wrong, it doesn't do the math properly and I assume it has to do with the variable types I'm using but am not sure. P.S. I am using the latest version of DEV-C++