Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
RÉSOLUTION NUMERIQUE
Information sur la source
Description
Il s'agit d'une source permettant de résoudre numériquement les systèmes de type df(x, y, z, t)/dt = g(x, y, z, t)/dt. Contrairement à d'autre source ici je n'utilise pas tel ou tel méthode d'intégration mais j'ai implémenté plusieurs méthodes et c'est à l'utilisateur de choisir laquelle il veut utiliser. J'ai implémenté : Euler Implicite Euler Explicite Euler Cauchy Explicite Adams Boford Molton Explicite t Implicite d'ordre 2, 3 et 4 Gear Implicite d'ordre 2, 3 et 4 Runge Kutta Explicite d'ordre 2, 4 et 6 Runge Kutta implicite d'ordre 3 Euler Ameliorer Explicite Crank Nicholson Explicite En gros j'ai fait une interface Integrator et les méthodes sont des enfants de cette interface. L'image montre un exemple de visualisation avec glut de l'attracteur de Lorentz...
Source
- #include <iostream>
- #include <list>
-
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- #include "Vector3D.h"
-
- #include "Integrator.h"
- #include "NS_Euler_I.h"
-
- using namespace std;
- using namespace eMV;
-
- Vector3D<float> Henon(const Vector3D<float> &v, const float t)
- {
- return Vector3D<float>( v.y + 1 - 1.4*v.x*v.x,
- 0.3*v.x,
- 0);
- }
-
- Vector3D<float> Lorentz(const Vector3D<float> &v, const float t)
- {
- return Vector3D<float>( 10*(v.y - v.x),
- 28*v.x - v.y - v.x*v.z,
- v.x*v.y - 8/3*v.z);
- }
-
- fIntegrator *euler = new fNS_Euler_I(Lorentz, fVector3D(0.1, 0.1, 0.1), 0, 0.003);
- list<fVector3D> data;
-
- void init(void)
- {
- glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
- glClearDepth(1.0); // Depth Buffer Setup
- glEnable(GL_DEPTH_TEST); // Enable Depth Buffer
- glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
- }
-
- void display(void)
- {
- fVector3D v;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glColor3f (1.0, 1.0, 1.0);
- glLoadIdentity (); // clear the matrix
- // viewing transformation
- gluLookAt (50.0, 50.0, 50.0, 0.1, 0.1, 20.0, 1.0, 0.0, 0.0);
- //
- glBegin(GL_LINES);
- glColor3ub(255, 0, 0);
- glVertex3f(0, 0, 0);
- glVertex3f(1, 0, 0);
- glColor3ub(0, 255, 0);
- glVertex3f(0, 0, 0);
- glVertex3f(0, 1, 0);
- glColor3ub(0, 0, 255);
- glVertex3f(0, 0, 0);
- glVertex3f(0, 0, 1);
- glEnd();
- data.push_back(euler->F);
- euler->next();
- //cout << euler->F << endl;
- glBegin(GL_LINE_STRIP);
- list<fVector3D>::iterator it;
- for (it = data.begin(); it != data.end(); ++it)
- {
- glColor3ub(255, 128, 0);
- glVertex3f((*it).x, (*it).y, (*it).z);
- }
- glEnd();
- //
- glFlush ();
- }
-
- void reshape (int w, int h)
- {
- glViewport(0, 0, (GLint)w, (GLint)h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.0, (float)w/(float)h, 0.1, 100.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
-
- void keyboard(unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 27 :
- exit(0);
- break;
- default :
- glutPostRedisplay();
- }
- }
-
- int main(int argc, char **argv)
- {
- try
- {
- glutInit(&argc, argv);
- glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize (500, 500);
- glutInitWindowPosition (100, 100);
- glutCreateWindow (argv[0]);
- init ();
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyboard);
- glutMainLoop();
- delete euler;
- return 0;
- }
- catch(std::exception& e)
- {
- cout << e.what() << endl;
- }
- catch(Error &e)
- {
- cout << e.GetMessage() << endl;
- }
- return 0;
- }
#include <iostream>
#include <list>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "Vector3D.h"
#include "Integrator.h"
#include "NS_Euler_I.h"
using namespace std;
using namespace eMV;
Vector3D<float> Henon(const Vector3D<float> &v, const float t)
{
return Vector3D<float>( v.y + 1 - 1.4*v.x*v.x,
0.3*v.x,
0);
}
Vector3D<float> Lorentz(const Vector3D<float> &v, const float t)
{
return Vector3D<float>( 10*(v.y - v.x),
28*v.x - v.y - v.x*v.z,
v.x*v.y - 8/3*v.z);
}
fIntegrator *euler = new fNS_Euler_I(Lorentz, fVector3D(0.1, 0.1, 0.1), 0, 0.003);
list<fVector3D> data;
void init(void)
{
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glClearDepth(1.0); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enable Depth Buffer
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
void display(void)
{
fVector3D v;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity (); // clear the matrix
// viewing transformation
gluLookAt (50.0, 50.0, 50.0, 0.1, 0.1, 20.0, 1.0, 0.0, 0.0);
//
glBegin(GL_LINES);
glColor3ub(255, 0, 0);
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 0);
glColor3ub(0, 255, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 1, 0);
glColor3ub(0, 0, 255);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, 1);
glEnd();
data.push_back(euler->F);
euler->next();
//cout << euler->F << endl;
glBegin(GL_LINE_STRIP);
list<fVector3D>::iterator it;
for (it = data.begin(); it != data.end(); ++it)
{
glColor3ub(255, 128, 0);
glVertex3f((*it).x, (*it).y, (*it).z);
}
glEnd();
//
glFlush ();
}
void reshape (int w, int h)
{
glViewport(0, 0, (GLint)w, (GLint)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (float)w/(float)h, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
exit(0);
break;
default :
glutPostRedisplay();
}
}
int main(int argc, char **argv)
{
try
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
delete euler;
return 0;
}
catch(std::exception& e)
{
cout << e.what() << endl;
}
catch(Error &e)
{
cout << e.GetMessage() << endl;
}
return 0;
}
Conclusion
Le but est de crée un moteur physique. Pas un moteur pour les jeux vidéos en temps réel mais un moteur de simulation physique. Ces méthodes de résolution servirons de base à la suite pour la simulation Physique. La prochaine fois j'implémenterais la gestion des corps indéformables déformable et les fluides.
Fichier Zip
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
Télécharger le zip
Historique
- 24 mars 2008 23:19:16 :
- ajout de screen
- 27 mars 2008 18:21:29 :
- Ajout d'un exemple utilisant l'API. Attracteur de Lorentz
Sources de la même categorie
Commentaires
Discussions en rapport avec ce code source
|
CalendriCode
| | | L | M | M | J | V | S | D |
| | | | 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 | |
|
Téléchargements
Logiciels à télécharger sur le même thème :
|