Cosine Equation

Hey Having trouble with a cosine graph. I know what cosine equation is
y= A cos(2 PI x / B + P) but when i put it into my code I dont get the right thing. here is the code it have:

for(double yPos = -150; yPos <=150; yPos+=.25)
{
xPos = (int) (constA * cos*(2 PI * yPos) / B + P;
//y = A cos(2 PI x / B + P)
PGraphics->AddPoint(xPos,yPos,color);
}


// draw the points
PGraphics->Draw();
check this part: cos*(2 PI the * is in a wrong position
and you are not closing all the parentheses

Another thing is that you swapped x and y
Last edited on
yeah i saw that little mistake. Thanks. Now when i went to run the program for my framework I just get a straight line ?!?!?!. I hv #include<cmath> . xPos = y and yPos mean how far up and down the framework is........... any other suggestions on y im getting a straight line up and down?

here is modified equation:
GetDlgItemText(HDialog, IDC_EDIT_1, str, 32);
B = atoi(str);
GetDlgItemText(HDialog, IDC_EDIT_2, str, 32);
P = atoi(str);
GetDlgItemText(HDialog, IDC_EDIT_3, str, 32);
constA = atoi(str);


// clear the scene and add an axis
PGraphics->ClearScene(RGB(0, 0, 0));
PGraphics->AddAxis(RGB(150, 150, 150), 10);

// draw some pixels around the points entered by the user

for(double yPos = -150; yPos <=150; yPos+=.25)
{
xPos = (int) (constA * cos(2 * PI * yPos) / B + P);
//y = A cos(2 PI x / B + P)
PGraphics->AddPoint(xPos,yPos,color);
}


// draw the points
PGraphics->Draw();

mabye i need another loop or my for loop is completely wrong. In my framework you enter in Amplitude(constA) , Period, and Phase Angle. and then press draw and it is supposed to draw a cosine graph
Last edited on
1
2
3
4
5
6
7
int yPosInt, xPosInt;
for(double xPos = -150; xPos <=150; xPos+=.25)
{ yPosInt= (int) (constA * cos(2 * PI * xPos / B + P));//the brackets were wrong
  xPosInt= (int) xPos;
  //y = A cos(2 PI x / B + P)
  PGraphics->AddPoint(xPosInt,yPosInt,color);
}
Last edited on
http://i206.photobucket.com/albums/bb172/cghicks16/untitled.jpg
[IMG]http://i206.photobucket.com/albums/bb172/cghicks16/untitled.jpg[/IMG]

This is what I am trying to get my output to look like. and once again I get a line but this time its a horizontal line instead of a vertical. my editied code looks like now:

void DrawStuff() {
COLORREF color = RGB(205, 0, 13); // purple color to draw with
char str[32]; // string to store user input
int h,k,yPosInt,xPosInt;
double constA;
double PI = 3.142;

// get the user input from the edit boxes and
// convert string input to integer
GetDlgItemText(HDialog, IDC_EDIT_h, str, 32);
h = atoi(str);
GetDlgItemText(HDialog, IDC_EDIT_k, str, 32);
k = atoi(str);
GetDlgItemText(HDialog, IDC_EDIT_constA, str, 32);
constA = atof(str);

// clear the scene and add an axis
PGraphics->ClearScene(RGB(0, 0, 0));
PGraphics->AddAxis(RGB(150, 150, 150), 10);

// draw some pixels around the points entered by the user

for(double xPos = -360; xPos <=360; xPos+=.25)
{
yPosInt = (int) (constA * cos(2 * PI * xPos / h + k)); //h & k are B and P
xPosInt = (int) xPos;
PGraphics->AddPoint(xPos,yPosInt,color);
}


// draw the points
PGraphics->Draw();
Topic archived. No new replies allowed.