# Thread: skeet flight angle problem

1. ## skeet flight angle problem

Hi, I'm still new at programming but can anyone help sort out an angle problem I'm having. I'm trying to vary the launch angle of a skeet (ellipse) but the class is calculating the angle from coordinates (0,0) rather than from (520,350).

I'm using codeblocks to program in.

Code:
```#include <windows.h>
#include <math.h>
#define PI 3.14159265

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

int c;
int d;
int e;

class position {
int y;
int a;
public:
void set_values(int,int);
double x() {return (y*tan(a*PI/180));}
};

void position :: set_values(int b, int c){
y=b;
a= c;
}
// Windows build parameters

RESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
position pos1;
position pos2;
position pos3;
HDC hdc;
PAINTSTRUCT Ps;

switch (message)                  /* handle the messages */
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &Ps);
MoveToEx(hdc, 500, 350, NULL);
for (c=350; c>0; c--){
pos1.set_values(c,45);
d = (int)pos1.x();
LineTo(hdc,c,d);
}
for (c=350; c>0; c--){
pos2.set_values(c,50);
d = (int)pos2.x();
LineTo(hdc,c,d);
}
for (c=350; c>100; c--){
pos3.set_values(c,10);
d = (int)pos3.x();
LineTo(hdc,c,d);
EndPaint(hwnd, &Ps);
}
break;```
Can please someone help point me in the right direction?

2. Are you talking about your x() function? The formula you are using is the formula for the angle from (0,0), therefore you should be completely unsurprised that that's the result you're getting. If you want (520,350) to be the "origin", you need to do a translation by subtracting 520 from x and 350 from y to move that point to the origin.

3. Sorry my mistake, wrong formula.

Changed the formula to v*cos(angle)/time. a few adjustments here and there and it is working a treat now.

Thanks for the tip about resetting the x point of origin though it helped.

Popular pages Recent additions