How Can I Adjust My C++ Sine Wave Code to Simulate Projectile Motion?

  • Context: C/C++ 
  • Thread starter Thread starter Badboy
  • Start date Start date
  • Tags Tags
    C++ Graphing
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 4K views
Badboy
Messages
6
Reaction score
0
hey. i want to graph a projectile motion. i got the code of a sine wave but the x and y axis' are in the opposite sides. i want the curve to look like a projectile with the curve facing down. thanx. here's my code

#include <iostream.h>
#include <iomanip.h>
#include <math.h>
#include <cstdlib>

void main()
{
const float PI = 3.1416;
const int STEPS = 16;
const int SIZE = 15;
const char STAR = '*';
const char BLANK = ' ';
int step;
float angle;
int indent;

char again = 'n';

do
{
system("cls");

count << " SINEWAVE SAMPLE PROGRAM\n\n";
cin.get();
angle = 0;
indent = 0;

for (step=0; step<=STEPS; step++)
{
angle = (PI) * step / STEPS;
indent = 5.5 + SIZE + SIZE * sin(angle);
count << setiosflags(ios::showpoint|ios::fixed)
<<setprecision(2)
<< setw(6) << angle/PI << "pi";
for (int i = 1; i <= indent; i++)
count << BLANK;
count << STAR << "\n";
}
count << "Angle\n(radians)\n\n";
cin.get();

system("cls");
count << "Do you want to run the program again (y/n) ? ";
cin >> again;
}
while ((again == 'y') || (again == 'Y'));
return;
}
 
Physics news on Phys.org
u should have just put this in the other thread you started.

what languages/software do you have at your disposal?

Excel? Matlab? Maple? If you can write to a file you can use these programs.

if you need to use C/C++ i suggest looking into either opengl/glut or opengl/SDL, the former being the easier of the two to learn. I believe you posted that u were using MSVC, in which case you can use MFC or forms or GDI. GDI is easy to use if you perform piecewise approximations of your curve with the line or lots of points. Else i'd look into using opengl/glut.