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
Click For Summary
SUMMARY

The discussion focuses on adjusting C++ sine wave code to simulate projectile motion. The original code, which uses basic C++ libraries, generates a sine wave but requires modifications to invert the curve for a downward-facing projectile trajectory. Participants recommend utilizing OpenGL with GLUT for graphical representation, especially for users working with Microsoft Visual C++ (MSVC). Additionally, they suggest using GDI for simpler implementations through piecewise approximations.

PREREQUISITES
  • Familiarity with C++ programming, specifically with libraries like iostream and math.
  • Understanding of graphical programming concepts, particularly with OpenGL and GLUT.
  • Knowledge of projectile motion physics to accurately simulate the desired curve.
  • Experience with Microsoft Visual C++ (MSVC) and its graphical interfaces like GDI.
NEXT STEPS
  • Explore OpenGL and GLUT for advanced graphical simulations in C++.
  • Learn about GDI for simpler graphical representations in MSVC.
  • Study projectile motion physics to enhance the accuracy of the simulation.
  • Investigate piecewise approximation techniques for curve rendering in graphics programming.
USEFUL FOR

C++ developers, game developers, and anyone interested in simulating physics-based graphics, particularly those working with projectile motion and graphical libraries.

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;
}
 
Technology 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.
 

Similar threads

Replies
89
Views
7K
  • · Replies 30 ·
2
Replies
30
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
2K
  • · Replies 75 ·
3
Replies
75
Views
7K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 36 ·
2
Replies
36
Views
5K