Principal | Gráficos 3D | Gráficos 2D | Fractales | Math | Códigos | Tutoriales | Links
Otro sistema de ecuaciones diferenciales que presenta CAOS es el de Lorenz, el cual es una simplificación de las ecuaciones originales que encontró en la predicción del tiempo.
|
con los siguientes parametros p=10, r=28 y b=8/3
Utilizó el Método de Euler para resolver el sistema, las condiciones iniciales del sistema son x(0)=1.0, y(0)=1.0, z(0)=1.0 y utilizo un tamaño de paso h=0.001.
r1=0.0, r2=0.0, r3=0.0 |
---|
donde r1, r2, r3 son la rotación con respecto a los ejes x, y, z respectivamente en radianes.
Código que se encarga de resolver el sistema de ecuaciones y graficarlo en 3D lorenz.zip (2 Kb)
Option Explicit Const MaxPuntos = 100000 Const FactorDeEscala = 2 Dim r1, r2, r3 As Double Dim sr1, sr2, sr3, cr1, cr2, cr3 As Double Dim sx, sy As Double Dim ScreenX, ScreenY As Long Function dx(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double dx = 10# * (y - x) End Function Function dy(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double dy = -x * z + 28 * x - y End Function Function dz(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double dz = x * y - (8 / 3) * z End Function Sub SinCos() sr1 = Sin(r1) sr2 = Sin(r2) sr3 = Sin(r3) cr1 = Cos(r1) cr2 = Cos(r2) cr3 = Cos(r3) End Sub Sub Calc3D(ByVal x As Double, ByVal y As Double, ByVal z As Double) Dim xa, ya, za As Double x = FactorDeEscala * x y = FactorDeEscala * y z = FactorDeEscala * z x = (-1#) * x xa = cr1 * x - sr1 * z za = sr1 * x + cr1 * z x = cr2 * xa + sr2 * y ya = cr2 * y - sr2 * xa z = cr3 * za - sr3 * ya y = sr3 * za + cr3 * ya z = z - 350 sx = (1200 * x) / z sy = (1200 * y) / z End Sub Sub Lorenz() Dim x, y, z As Double Dim h As Double Dim nPuntos As Long Picture1.Cls Call SinCos x = 1# y = 1# z = 1# nPuntos = 0 h = 0.001 Do While (nPuntos < MaxPuntos) x = x + h * dx(x, y, z) y = y + h * dy(x, y, z) z = z + h * dz(x, y, z) Call Calc3D(x, y, z) sx = sx + ScreenX / 2# sy = sy + ScreenY / 2# Picture1.PSet (sx, ScreenY - sy), RGB(255, 0, 0) nPuntos = nPuntos + 1 Loop End Sub Private Sub cmdEjecutar_Click() r1 = 0# r2 = 0# r3 = 0# Call Lorenz End Sub Private Sub cmdSalir_Click() Unload Me End Sub Private Sub Form_Load() Picture1.ScaleMode = 3 ScreenX = Picture1.ScaleWidth ScreenY = Picture1.ScaleHeight End Sub |
Las condiciones iniciales son las mismas x(0)=1.0, y(0)=1.0, z(0)=1.0 y el tamañao de paso h=0.05, con 12.000 esferas.
![]() |
gluLookAt (15.0, -25.0, 0.0, 0.0, 0.0, 25.0, 0.0, 1.0, 0.0) |
---|
Los archivos necesarios para la compilacion del código se encuentan en lorenz_c.zip (3 Kb)
La libreria GLUT 3.6 se la puede enconotrar en http://reality.sgi.com/opengl/glut3/glut3.html
Acerca de la instalción de GLUT, se debe decomprimir el archivo glutdlls36.zip y copiar el archivo GLUT32.DLL en el directorio WINDOWS/SYSTEM, copiar el archivo GLUT32.LIB en el subdirectorio del compilador destinado a las librerias, y el archivo GLUT.H junto con el resto de los includes de OpenGL.
#include <GL/glut.h> #include <stdlib.h> GLfloat diffuseMaterial[4] = {0.75, 0.75, 0.75, 1.0}; void init(void) { GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); glEnable(GL_DEPTH_TEST); glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseMaterial); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialf(GL_FRONT, GL_SHININESS, 25.0); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glColorMaterial(GL_FRONT, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); } void display(void) { GLfloat x0, y0, z0, x1, y1, z1; GLfloat h; int Puntos, MaxPuntos=12000; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glLoadIdentity (); gluLookAt (15.0, -25.0, 0.0, 0.0, 0.0, 25.0, 0.0, 1.0, 0.0); glColor3f(1.0f, 0.4f, 0.4f); x0=1.0f; y0=1.0f; z0=1.0f; Puntos=0; h=0.005f; while (Puntos<MaxPuntos) { x1=x0+h*(10.0f*(y0-x0)); y1=y0+h*(x0*(28.0f-z0)-y0); z1=z0+h*(x0*y0-(8.0f/3.0f)*z0); x0=x1; y0=y1; z0=z1; glPushMatrix(); glTranslatef(x0, y0, z0); glutSolidSphere(0.5, 12.0, 12.0); glPopMatrix(); Puntos=Puntos+1; } glFlush (); } void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 200.0); glMatrixMode (GL_MODELVIEW); } /* ARGSUSED1 */ void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (600, 600); glutInitWindowPosition (0, 0); glutCreateWindow (argv[0]); init (); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; } |
valcoey@hotmail.com
Ramiro Alcocer, 2001
Principal | Gráficos 3D | Gráficos 2D | Fractales | Math | Códigos | Tutoriales | Links