diff --git a/README.md b/README.md index 979b8bc..304e168 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ I was bored so i made this tool, it allows you to calculate : * the delta * x1, x2, x0 * vertex coordinates -* Drawing the graph +* Drawing the graph of the function and its derivative The names of the functions/variables are in French, uhh use google translate to read the code i guess, sorry for that. diff --git a/polynome.c b/polynome.c index cfce450..c4f5a78 100644 --- a/polynome.c +++ b/polynome.c @@ -52,7 +52,7 @@ enum STATUS Calcul_Sommet(Poly* poly) { } enum STATUS Calcul_Fonction(Poly* poly, float x, float *out) { - if (poly == NULL) { + if (poly == NULL || out == NULL) { return FAIL; } @@ -60,36 +60,55 @@ enum STATUS Calcul_Fonction(Poly* poly, float x, float *out) { return OK; } +enum STATUS Calcul_Derivee(Poly* poly, float x, float *out) { + //f'(x)=2ax+b + + if (poly == NULL || out == NULL) { + return FAIL; + } + + *out = (2 * poly->a * x) + poly->b; + return OK; +} + +void Dessiner_Separateur() { + printf("+-----+"); + for (int i = 0; i <= LONGUEUR_X*2; i++) { + if (i == LONGUEUR_X) { + printf("--+-"); + } + else { + printf("----"); + } + } + printf("-+\n"); +} + enum STATUS Dessiner_Graph(Poly* poly) { if (poly == NULL) { return FAIL; } printf("\n"); - printf("+-----+---------------------------------------------+\n"); + Dessiner_Separateur(); for (int j = LONGUEUR_Y; j >= -LONGUEUR_Y; j--) { - if (j == -10) { - printf("| %d | ",j); + if (j < -9) { + printf("| %d | ",j); } - else if (j == 10 || j < 0) { - printf("| %d | ",j); + else if (j > 9 || j < 0) { + printf("| %d | ",j); } else if (j == 0) { - printf("| %d |--",j); + printf("| %d |-",j); } else { - printf("| %d | ",j); + printf("| %d | ",j); } for (int i = -LONGUEUR_X; i <= LONGUEUR_X+1; i++) { if (i > LONGUEUR_X) { - if (j == 0) { - printf("-|"); - } - else { - printf(" |"); - } + printf("|"); continue; } @@ -98,35 +117,61 @@ enum STATUS Dessiner_Graph(Poly* poly) { return FAIL; } - if (roundf(y) == j) { - printf("o "); + float y2; + if (Calcul_Derivee(poly, i, &y2) == FAIL) { + return FAIL; } - else if (i == 0) { + + if (roundf(y) == j) { if (j == 0) { - printf("+-"); + printf("-o--"); } else { - printf(": "); + printf(" o "); + } + continue; + } + if (roundf(y2) == j) { + if (j == 0) { + printf("-u--"); + } + else { + printf(" u "); + } + continue; + } + + if (i == 0) { + if (j == 0) { + printf("-+--"); + } + else { + printf(" : "); } } else if (roundf(y) != j && j != 0) { - printf(" "); + printf(" "); } else { - printf("--"); + printf("----"); } } printf("\n"); } // | 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 - printf("+-----+---------------------------------------------+\n"); + Dessiner_Separateur(); printf("| | "); for (int k = -LONGUEUR_Y; k <= LONGUEUR_Y; k++) { - printf("%d ",abs(k)); + if (k < 10 && k > -10) { + printf("00%d ",abs(k)); + } + else if (k < 100 && k > -100) { + printf("0%d ",abs(k)); + } } printf("|\n"); - printf("+-----+---------------------------------------------+\n"); + Dessiner_Separateur(); return OK; } diff --git a/polynome.h b/polynome.h index 9dab2b8..9723a7c 100644 --- a/polynome.h +++ b/polynome.h @@ -23,8 +23,10 @@ enum STATUS Calcul_x1_x2(Poly* poly); enum STATUS Calcul_x0(Poly* poly); enum STATUS Calcul_Sommet(Poly* poly); enum STATUS Calcul_Fonction(Poly* poly, float x, float *out); +enum STATUS Calcul_Derivee(Poly* poly, float x, float *out); -#define LONGUEUR_X 10 -#define LONGUEUR_Y 10 +#define LONGUEUR_X 20 +#define LONGUEUR_Y 20 +void Dessiner_Separateur(); enum STATUS Dessiner_Graph(Poly* poly); int main(); \ No newline at end of file diff --git a/screenshot/screenshot.png b/screenshot/screenshot.png index b1d0fce..3031d4c 100644 Binary files a/screenshot/screenshot.png and b/screenshot/screenshot.png differ