Added the derivative + graph is responsive

This commit is contained in:
ALittlePatate
2022-09-03 15:06:48 +02:00
parent 7c6fdb0664
commit e624b56624
4 changed files with 74 additions and 27 deletions

View File

@@ -3,7 +3,7 @@ I was bored so i made this tool, it allows you to calculate :
* the delta * the delta
* x1, x2, x0 * x1, x2, x0
* vertex coordinates * 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. The names of the functions/variables are in French, uhh use google translate to read the code i guess, sorry for that.

View File

@@ -52,7 +52,7 @@ enum STATUS Calcul_Sommet(Poly* poly) {
} }
enum STATUS Calcul_Fonction(Poly* poly, float x, float *out) { enum STATUS Calcul_Fonction(Poly* poly, float x, float *out) {
if (poly == NULL) { if (poly == NULL || out == NULL) {
return FAIL; return FAIL;
} }
@@ -60,36 +60,55 @@ enum STATUS Calcul_Fonction(Poly* poly, float x, float *out) {
return OK; 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) { enum STATUS Dessiner_Graph(Poly* poly) {
if (poly == NULL) { if (poly == NULL) {
return FAIL; return FAIL;
} }
printf("\n"); printf("\n");
printf("+-----+---------------------------------------------+\n"); Dessiner_Separateur();
for (int j = LONGUEUR_Y; j >= -LONGUEUR_Y; j--) { for (int j = LONGUEUR_Y; j >= -LONGUEUR_Y; j--) {
if (j == -10) { if (j < -9) {
printf("| %d | ",j); printf("| %d | ",j);
} }
else if (j == 10 || j < 0) { else if (j > 9 || j < 0) {
printf("| %d | ",j); printf("| %d | ",j);
} }
else if (j == 0) { else if (j == 0) {
printf("| %d |--",j); printf("| %d |-",j);
} }
else { else {
printf("| %d | ",j); printf("| %d | ",j);
} }
for (int i = -LONGUEUR_X; i <= LONGUEUR_X+1; i++) { for (int i = -LONGUEUR_X; i <= LONGUEUR_X+1; i++) {
if (i > LONGUEUR_X) { if (i > LONGUEUR_X) {
if (j == 0) { printf("|");
printf("-|");
}
else {
printf(" |");
}
continue; continue;
} }
@@ -98,35 +117,61 @@ enum STATUS Dessiner_Graph(Poly* poly) {
return FAIL; return FAIL;
} }
if (roundf(y) == j) { float y2;
printf("o "); if (Calcul_Derivee(poly, i, &y2) == FAIL) {
return FAIL;
} }
else if (i == 0) {
if (roundf(y) == j) {
if (j == 0) { if (j == 0) {
printf("+-"); printf("-o--");
} }
else { 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) { else if (roundf(y) != j && j != 0) {
printf(" "); printf(" ");
} }
else { else {
printf("--"); printf("----");
} }
} }
printf("\n"); printf("\n");
} }
// | 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 // | 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("| | "); printf("| | ");
for (int k = -LONGUEUR_Y; k <= LONGUEUR_Y; k++) { 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");
printf("+-----+---------------------------------------------+\n"); Dessiner_Separateur();
return OK; return OK;
} }

View File

@@ -23,8 +23,10 @@ enum STATUS Calcul_x1_x2(Poly* poly);
enum STATUS Calcul_x0(Poly* poly); enum STATUS Calcul_x0(Poly* poly);
enum STATUS Calcul_Sommet(Poly* poly); enum STATUS Calcul_Sommet(Poly* poly);
enum STATUS Calcul_Fonction(Poly* poly, float x, float *out); 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_X 20
#define LONGUEUR_Y 10 #define LONGUEUR_Y 20
void Dessiner_Separateur();
enum STATUS Dessiner_Graph(Poly* poly); enum STATUS Dessiner_Graph(Poly* poly);
int main(); int main();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 33 KiB