| | |
Max Height formula
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
0
#13 Nov 3rd, 2009
I'm getting 373.402
Using:
Using:
C++ Syntax (Toggle Plain Text)
Solve [0 == -9.82*(-(Sqrt[Sin[35]^2*200^2 - 2*9.82*(x)] - Sin[35]*200)/9.82) + Sin[35]*200, x]
0
#14 Nov 3rd, 2009
Why wouldn't you just build the project in OpenGL? - And like plot in the a lot of points? - Maybe even making the program calculate while drawing using parallel programming? - That would create a sweet effect
EDIT: You could find the top point using like derivative calculations as it's given, that in the toppoint of "y", there will be no slope.
EDIT: You could find the top point using like derivative calculations as it's given, that in the toppoint of "y", there will be no slope.
Last edited by Skeen; Nov 3rd, 2009 at 4:27 pm.
0
#15 Nov 3rd, 2009
Okay I'm getting 670 now, basically then the problem isn't the fomula, it's the number for "distance" you're using in it, you should be using; "1915.79" which is where the peak in height is, instead of "3831.57" which is where the impact is.
So I think that you should make a derivative calculation based upon the function with (d/d(distance))(function), and solve with 0=(d/d(distance))(function), then use the result in "d" in the formula to find the height, just tested it, and it works in my program
EDIT: instead of programming a derivative function you could just make a simple test algoritm, like;
Something like that. (wont be as effecient as the derivative function at all, but will work)
So I think that you should make a derivative calculation based upon the function with (d/d(distance))(function), and solve with 0=(d/d(distance))(function), then use the result in "d" in the formula to find the height, just tested it, and it works in my program

EDIT: instead of programming a derivative function you could just make a simple test algoritm, like;
C++ Syntax (Toggle Plain Text)
double Distance=0; double Y-values[1000]; double Impact=(ImpactPointCalculatedEarlier); while (Distance<Impact) { Y-values[Distance]=function(Distance); if (Y-values[Distance]>Y-values[Distance-1] { distance++; } else { distance-=0.01 } }
Last edited by Skeen; Nov 3rd, 2009 at 5:01 pm.
0
#16 Nov 3rd, 2009
Just plotted the Graphs and like, the highest point in height is right in the middle off all of them, so like, you could simply use this;
I'm not sure that the point right in the middle would apply with a different speed and angle, so you'll need to do some testing, or simply make the derivative function as described above.
C++ Syntax (Toggle Plain Text)
double mars_gravity = 3.77; // Fixed value, you used the wrong one. double earthx = distance_earth (angtorad(angle,pi),mps,earth_gravity)/2; // Divided by 2 (midpoint) double marsx = distance_mars (angtorad(angle,pi),mps,mars_gravity)/2; // Divided by 2 (midpoint) double moonx = distance_moon (angtorad(angle,pi),mps,moon_gravity)/2; // Divided by 2 (midpoint)
0
#18 Nov 4th, 2009
•
•
•
•
You my friend are a genius, I get it now...
Or atleast I think so lol
C++ Syntax (Toggle Plain Text)
#include <GL/glut.h> #include <stdlib.h> #include <stdio.h> #include <cmath> #include <windows.h> #define MAXIMUM 25000 GLdouble yEarth[MAXIMUM]; GLdouble yMars[MAXIMUM]; GLdouble yMoon[MAXIMUM]; GLint InitGL(GLvoid) // All Setup For OpenGL Goes Here { glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearColor(1.0f, 1.0f, 1.0f, 0.5f); // Black Background glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations return TRUE; // Initialization Went OK } GLvoid resize(GLint width, GLint height) // Resize And Initialize The GL Window { if (height==0) // Prevent A Divide By Zero By { height=1; // Making Height Equal One } glViewport(0,0,width,height); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect Ratio Of The Window gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,MAXIMUM); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix } double HeightOfY(double distance, double angle, double gravity, double speed) { double height=0; const double Pi = 3.141592653589793238462643383279502884197169399375105820974944592, Conversion = Pi/180; double Temp0 = distance * tan(angle*Conversion); double Temp1 = gravity * (distance*distance); double Temp2 = 2*(((speed*cos(angle*Conversion))*(speed*cos(angle*Conversion)))); height = Temp0-(Temp1/Temp2); return height; } GLvoid FPS(GLvoid) { static GLint FramesPerSecond = 0; // Create a var, to hold the frame per second static GLfloat lastTime = 0.0f; // Create a var, to hold the last time (ticks from last second) static char strFrameRate[256] = {0}; // Create a string, needed to post the new title GLfloat currentTime = GetTickCount() * 0.001f; // Get the current time, in ticks ++FramesPerSecond; // Raise framerate in the static var if ((currentTime - lastTime) > 1.0f) // When a second has elasped { lastTime = currentTime; // Base on new time sprintf(strFrameRate, "Space (running at: FPS: %d)", FramesPerSecond); // Update the string glutSetWindowTitle(strFrameRate); // Update window title FramesPerSecond = 0; // Start counting form 0, FramesPerSecond } } GLvoid display(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-(MAXIMUM/2),-(MAXIMUM/5),-MAXIMUM); glBegin (GL_LINES); int xvalue=0; glColor3f(1,0,0); glVertex2f(0, 0); glVertex2f(MAXIMUM, 0); glVertex2f(0, MAXIMUM); glVertex2f(0, 0); glColor3f(0,0,1); for (xvalue=1; xvalue<=MAXIMUM && yEarth[xvalue]>0 ; xvalue++) { glVertex2f((xvalue-1), yEarth[(xvalue-1)]); glVertex2f(xvalue, yEarth[xvalue]); } glColor3f(0,1,1); for (xvalue=1; xvalue<=MAXIMUM && yMars[xvalue]>0 ; xvalue++) { glVertex2f((xvalue-1), yMars[(xvalue-1)]); glVertex2f(xvalue, yMars[xvalue]); } glColor3f(0,1,0); for (xvalue=1; xvalue<=MAXIMUM && yMoon[xvalue]>0 ; xvalue++) { glVertex2f((xvalue-1), yMoon[(xvalue-1)]); glVertex2f(xvalue, yMoon[xvalue]); } glEnd(); glutSwapBuffers(); } GLvoid key(unsigned char key, GLint x, GLint y) { switch (key) { case 27 : exit(0); break; } glutPostRedisplay(); } GLvoid idle(GLvoid) { FPS(); glutPostRedisplay(); } GLvoid Initialization(int argc, char *argv[]) { glutInit(&argc, argv); // Initialization of glut glutInitWindowSize(800,600); // Set WindowSize (based upon the var loaded) glutInitWindowPosition(0,0); // Set default window position glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); // Initialate DisplayMode } GLint main(GLint argc, char *argv[]) { for (int xuse=0; xuse<MAXIMUM; xuse++) { yEarth[xuse]=HeightOfY(xuse, 35, 9.81, 200); // Earth } for (int xuse=0; xuse<MAXIMUM; xuse++) { yMars[xuse]=HeightOfY(xuse, 35, 3.77, 200); // Mars } for (int xuse=0; xuse<MAXIMUM; xuse++) { yMoon[xuse]=HeightOfY(xuse, 35, 1.62, 200); // The Moon } Initialization(argc, argv); glutCreateWindow("Space"); glutReshapeFunc(resize); // Check if windows is being resized glutDisplayFunc(display); glutKeyboardFunc(key); glutIdleFunc(idle); glClearColor(1,1,1,1); glEnable(GL_DEPTH_TEST); // Enable Depth testing glDepthFunc(GL_LESS); // Choose Depth function glutMainLoop(); return EXIT_SUCCESS; }
The program is VERY inefficient, and you should easily be able to make it more efficient

As the program is right now, it simply lots the parable for the Earth (blue), Mars (teal), Moon (green).
With 35degrees angle, and like 200mps.
Hope it's helping you out, let me know if theres something else

EDIT: You could simply make a console program using the:
C++ Syntax (Toggle Plain Text)
for (int xuse=0; xuse<MAXIMUM; xuse++) { yEarth[xuse]=HeightOfY(xuse, 35, 9.81, 200); // Earth } for (int xuse=0; xuse<MAXIMUM; xuse++) { yMars[xuse]=HeightOfY(xuse, 35, 3.77, 200); // Mars } for (int xuse=0; xuse<MAXIMUM; xuse++) { yMoon[xuse]=HeightOfY(xuse, 35, 1.62, 200); // The Moon }
. // Skeen
0
#19 Nov 4th, 2009
There an update GLUT code:
C++ Syntax (Toggle Plain Text)
... for (xvalue=1; xvalue<=counter*MAXIMUM/1000 && yEarth[xvalue]>0 ; xvalue++) { glVertex2f((xvalue-1), yEarth[(xvalue-1)]); glVertex2f(xvalue, yEarth[xvalue]); } glColor3f(0,1,1); for (xvalue=1; xvalue<=counter*MAXIMUM/1000 && yMars[xvalue]>0 ; xvalue++) { glVertex2f((xvalue-1), yMars[(xvalue-1)]); glVertex2f(xvalue, yMars[xvalue]); } glColor3f(0,1,0); for (xvalue=1; xvalue<=counter*MAXIMUM/1000 && yMoon[xvalue]>0 ; xvalue++) { glVertex2f((xvalue-1), yMoon[(xvalue-1)]); glVertex2f(xvalue, yMoon[xvalue]); } counter++; Sleep(1); ...
Last edited by Skeen; Nov 4th, 2009 at 6:42 am.
// Skeen
![]() |
Similar Threads
- 4 short programs (Java)
- Table height (HTML and CSS)
- min height (HTML and CSS)
- how to maximize table cell height (JavaScript / DHTML / AJAX)
- How do I add a vertical scroll bar to a form? (Visual Basic 4 / 5 / 6)
- finding height of a binary search tree without using recursion (Java)
- How do i load a image on the same page ? (Site Layout and Usability)
- urgent help!!! (C++)
- A question on an error in a SpringLayout example program (Java)
- binary trees (C)
Other Threads in the C++ Forum
- Previous Thread: (Beginner) How can make it slower?
- Next Thread: Disabling fullscreen using GLUT
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings temperature template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





