Tp1 II B2.c : Différence entre versions
m |
m |
||
| (Une révision intermédiaire par le même utilisateur non affichée) | |||
| Ligne 1 : | Ligne 1 : | ||
{{RetourVers/TpII}} | {{RetourVers/TpII}} | ||
| − | + | <source lang="c"> | |
| − | + | #include <stdio.h> | |
| − | + | #include <math.h> | |
| − | + | #include "SVGlib.h" | |
| − | + | #define N 100 | |
| − | + | void tracerFenetre(int xdeb,int ydeb,int xfin, int yfin,float x[N],float y[N]); | |
| − | + | ||
| − | + | main(){ | |
| − | + | int i; | |
| − | + | float xmin,xmax,x[N],y[N]; | |
| − | + | xmin=0; | |
| − | + | xmax=4; | |
| − | + | // génération de points | |
| − | + | for (i=0;i<N;i++) { | |
| − | + | x[i]=xmin + i*(xmax-xmin)/N; | |
| − | + | y[i]=sin(x[i]*x[i]); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| + | SVGopen(640,480); | ||
| + | tracerFenetre(10,10,329,240,x,y); | ||
| + | SVGClose(); | ||
| + | return 0; | ||
| + | } | ||
| + | |||
| + | void tracerFenetre(int xdeb,int ydeb,int xfin, int yfin,float x[N],float y[N]){ | ||
| + | int i,xp1,yp1,xp2,yp2; | ||
| + | float xmin,xmax,ymin,ymax; | ||
| + | xmin = x[0]; | ||
| + | xmax = x[N-1]; | ||
| + | // calcul des min max de la fonction | ||
| + | ymin=ymax=y[0]; | ||
| + | for (i=1;i<N;i++) { | ||
| + | if (y[i] > ymax) ymax = y[i]; | ||
| + | if (y[i] < ymin) ymin = y[i]; | ||
| + | } | ||
| + | // tracé de courbe + fenetre | ||
| + | SVGrectangleVide(xdeb, ydeb, xfin-xdeb, yfin-ydeb); | ||
| + | for (i=1;i<N;i++) { | ||
| + | xp1=xdeb+(xfin-xdeb)*(x[i-1]-xmin)/(xmax-xmin); | ||
| + | yp1=yfin-(yfin-ydeb)*(y[i-1]-ymin)/(ymax-ymin);//-ydeb ajouté ici | ||
| + | xp2=xdeb+(xfin-xdeb)*(x[i]-xmin)/(xmax-xmin); | ||
| + | yp2=yfin-(yfin-ydeb)*(y[i]-ymin)/(ymax-ymin);//-ydeb ajouté ici | ||
| + | SVGline(xp1,yp1,xp2,yp2,0xFF0000); | ||
| + | } | ||
| + | } | ||
| + | </source> | ||
{{RetourVers/TpII}} | {{RetourVers/TpII}} | ||
Version actuelle datée du 15 décembre 2012 à 19:17
retour vers la page des Tps II
#include <stdio.h>
#include <math.h>
#include "SVGlib.h"
#define N 100
void tracerFenetre(int xdeb,int ydeb,int xfin, int yfin,float x[N],float y[N]);
main(){
int i;
float xmin,xmax,x[N],y[N];
xmin=0;
xmax=4;
// génération de points
for (i=0;i<N;i++) {
x[i]=xmin + i*(xmax-xmin)/N;
y[i]=sin(x[i]*x[i]);
}
SVGopen(640,480);
tracerFenetre(10,10,329,240,x,y);
SVGClose();
return 0;
}
void tracerFenetre(int xdeb,int ydeb,int xfin, int yfin,float x[N],float y[N]){
int i,xp1,yp1,xp2,yp2;
float xmin,xmax,ymin,ymax;
xmin = x[0];
xmax = x[N-1];
// calcul des min max de la fonction
ymin=ymax=y[0];
for (i=1;i<N;i++) {
if (y[i] > ymax) ymax = y[i];
if (y[i] < ymin) ymin = y[i];
}
// tracé de courbe + fenetre
SVGrectangleVide(xdeb, ydeb, xfin-xdeb, yfin-ydeb);
for (i=1;i<N;i++) {
xp1=xdeb+(xfin-xdeb)*(x[i-1]-xmin)/(xmax-xmin);
yp1=yfin-(yfin-ydeb)*(y[i-1]-ymin)/(ymax-ymin);//-ydeb ajouté ici
xp2=xdeb+(xfin-xdeb)*(x[i]-xmin)/(xmax-xmin);
yp2=yfin-(yfin-ydeb)*(y[i]-ymin)/(ymax-ymin);//-ydeb ajouté ici
SVGline(xp1,yp1,xp2,yp2,0xFF0000);
}
}