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

  • Thread starter Thread starter Badboy
  • Start date Start date
  • Tags Tags
    C++ Graphing
Click For Summary
The discussion centers around a user seeking assistance to graph projectile motion, specifically wanting to modify existing code that currently generates a sine wave. The user notes that the x and y axes are reversed and desires the curve to face downward, resembling a projectile's trajectory. Suggestions are made regarding programming languages and software options available for this task, including Excel, Matlab, and Maple, which can be utilized if file writing is possible. For C/C++ users, recommendations include using OpenGL with GLUT for easier implementation or GDI for simpler graphics handling, particularly through piecewise approximations. The conversation emphasizes the need for appropriate tools to achieve the desired graphical representation of projectile motion.
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");

cout << " 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);
cout << setiosflags(ios::showpoint|ios::fixed)
<<setprecision(2)
<< setw(6) << angle/PI << "pi";
for (int i = 1; i <= indent; i++)
cout << BLANK;
cout << STAR << "\n";
}
cout << "Angle\n(radians)\n\n";
cin.get();

system("cls");
cout << "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.
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

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