Open GL - ¿Como se graficaría la siguiente funcion con rangos definidos?

 
Vista:

¿Como se graficaría la siguiente funcion con rangos definidos?

Publicado por Grafica Opengl (1 intervención) el 13/04/2023 01:20:41
como harian el codigo para graficar la siguiente funcion en opengl con rangos establecidos
y = 12 ((sen √x^2 + z^2) / (√x^2 + z^2))
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

¿Como se graficaría la siguiente funcion con rangos definidos?

Publicado por funcion (1 intervención) el 13/04/2023 03:24:26
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#include <unistd.h>
//Funciones de color extraidas de:
//https://stackoverflow.com/questions/46928277/trying-to-convert-integer-rangeto-rgb-color
//Fast inverse square root:
//https://en.wikipedia.org/wiki/Fast_inverse_square_root
//**Resulta que ya no es mas rapido debido a los avances en hardware :(
float zoom=-34;
GLfloat girax = 30, giray = -30;
int gx, gy;
GLboolean clic=GL_FALSE;
void ajusta(int ancho, int alto){
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-11,11,-12,12,11,-11);
gluPerspective(45,1,10,100);
//glFrustum(-11,11,-12,12,11,-11);
//glMatrixMode(GL_MODELVIEW);
 //glLoadIdentity();
 glEnable(GL_DEPTH_TEST);
}
void dibuja(void){
float x,y,z,k;
//y = 12*( (sin(sqrt(x*x + z*z)))/sqrt(x*x + z*z) );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0,0,zoom);
glRotatef(girax,1,0,0);
glRotatef(giray,0,1,0);
for(x=-8;x<=8;x+=0.2){
glBegin(GL_LINE_STRIP);
for(z=-8;z<=8;z+=0.2){
if((x*x + z*z)==0)continue;
y = 12*( (sin(sqrt(x*x + z*z)))/sqrt(x*x + z*z) );
//printf("y: %.2f, x: %.2f, z: %.2f\n",y,x,z);
glColor3ub(255,0,255);
glVertex3f(x,y,z);
}
glEnd();
}
for(z=-8;z<=8;z+=0.2){
glBegin(GL_LINE_STRIP);
for(x=-8;x<=8;x+=0.2){
if((x*x + z*z)==0)continue;
y = 12*( (sin(sqrt(x*x + z*z)))/sqrt(x*x + z*z) );
//printf("y: %.2f, x: %.2f, z: %.2f\n",y,x,z);
glColor3ub(255,0,255);
glVertex3f(x,y,z);
}
glEnd();
}
glPopMatrix();
//glFlush();
glutSwapBuffers();
}
void teclado(unsigned char key, int x, int y) {
 switch(key) {
 case 27: exit (0);
 case '+': zoom++; break;
 case '-': zoom--; break;
 default: break;
 }
 glutPostRedisplay();
}
void raton(int boton, int estado, int xv, int yv) {
 clic= boton==GLUT_LEFT_BUTTON && estado==GLUT_DOWN;
 if(clic){
 gx = xv;
 gy = yv;
 }
 if (boton==3 || boton==4) // scroll up => 3 scroll down=>4
 zoom+=(boton==3)?0.1:-0.1;
 glutPostRedisplay();
}
void girar(int xv, int yv){
if (clic){ // inicia circulos con centro
 girax -= (gy - yv);
 giray -= (gx - xv);
 gx = xv;
 gy = yv;
 }
 glutPostRedisplay();
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(640,480);
glutInitWindowPosition(100, 150);
glutCreateWindow("Ecuacion");
glutReshapeFunc(ajusta);
glutDisplayFunc(dibuja);
glutKeyboardFunc(teclado);
glutMouseFunc(raton);
glutMotionFunc(girar);
glutMainLoop();
return 0;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar