Commit dc962544 authored by nicolas.albanesi's avatar nicolas.albanesi
Browse files

Kinda working?

parent da224dfe
#include "../includes/elec_charge.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
// Compute E*qP/norm(qP)
// Return false if norm(qP) < eps
bool compute_e(charge_t c, vec2 p, double eps, vec2 *e)
{
// ! MIGHT BE WRONG ORDER
vec2_print(p, "p : ");
vec2_print(c.pos, "c : ");
// Vecteur allant de la particule c au point p
vec2 qP = vec2_sub(c.pos, p);
double norm_qp = vec2_norm(qP);
vec2_print(qP, "qP : ");
printf("norm_qp = %.4f\n", norm_qp);
// Constante
double k = 1 / (4 * M_PI * 8.85E-12);
// Distance entre la particule c et le point p
double r = vec2_dist(c.pos, p);
// INTENSITÉ DU CHAMP
......@@ -18,7 +28,7 @@ bool compute_e(charge_t c, vec2 p, double eps, vec2 *e)
*e = vec2_add(*e, vec2_mul(E, qP));
return !(vec2_norm(qP) < eps);
return !(norm_qp < eps);
}
// Compute the normalized sum of Ei*qiP/norm(qiP)
......
......@@ -18,10 +18,12 @@
#define WIDTH 500
#define HEIGHT 500
#define X_CHARGE_1 WIDTH/3
#define Y_CHARGE_1 HEIGHT/2
#define X_CHARGE_2 WIDTH*2/3
#define Y_CHARGE_2 HEIGHT/2
// #define X_CHARGE_1 WIDTH/3
// #define Y_CHARGE_1 HEIGHT/2
#define X_CHARGE_1 0.3
#define Y_CHARGE_1 0.5
#define X_CHARGE_2 0.6
#define Y_CHARGE_2 0.5
int32_t SDL_SpawnAll(SDL_Window ** pp_win_, SDL_Renderer ** pp_ren);
void SDL_killAll(SDL_Window ** pp_win_, SDL_Renderer ** pp_ren);
......@@ -45,16 +47,58 @@ int main()
// ! INIT CHARGES
charge_t *charges = malloc(2 * sizeof(*charges));
charges[0].pos = (vec2){X_CHARGE_1, Y_CHARGE_1};
charges[0].q = -5;
charges[0].q = 1.6E-19;
charges[1].pos = (vec2){X_CHARGE_2, Y_CHARGE_2};
charges[1].q = -10;
charges[1].q = 1.6E-19;
vec2 p = {.x = (double)(rand() % 10)/10.0 , .y = (double)(rand() % 10)/10.0};
vec2 p = {.x = (double)(rand() % 10)/10.0+0.01 , .y = (double)(rand() % 10)/10.0+0.01};
vec2_print(p, "p :");
vec2 next_p;
vec2 e;
// DRAW
// GFX_ClearScreen(renderer, COLOR_BLACK);
// DESSINE LES CHARGES
GFX_DrawCircle(renderer, vec2_to_coordinates((vec2){X_CHARGE_1, Y_CHARGE_1}, WIDTH, HEIGHT), 25, COLOR_RED);
GFX_DrawCircle(renderer, vec2_to_coordinates((vec2){X_CHARGE_2, Y_CHARGE_2}, WIDTH, HEIGHT), 25, COLOR_BLUE);
while (p.x < 1.0 && p.x > 0 && p.y < 1.0 && p.y > 0)
{
// COMPUTE LA POSITION DES POINTS
e.x = 0;
e.y = 0;
if (compute_total_normalized_e(charges, 2, p, 0.02, &e) == false)
{
// Break si trop proche de la charge
break;
}
// vec2_print(e, "e_normalized :");
e = vec2_div(vec2_norm(e), e);
double tmp = 1.0 / sqrt(WIDTH * WIDTH + HEIGHT * HEIGHT);
// vec2_print(e, "e/norm(e) = ");
// printf("tmp : %.4f\n", tmp);
next_p = vec2_mul(tmp, e);
next_p = vec2_add(p, next_p);
// vec2_print(e, "e :");
// vec2_print(p, "p :");
// vec2_print(next_p, "next_p :");
// printf("x : %.4f y : %.4f\n", next_p.x - p.x, next_p.y - p.y);
printf("-------------------------------------\n");
GFX_DrawLine(renderer, vec2_to_coordinates(p, WIDTH, HEIGHT), vec2_to_coordinates(next_p, WIDTH, HEIGHT), COLOR_WHITE);
p = next_p;
}
SDL_RenderPresent(renderer);
while(running_loop)
{
while(SDL_PollEvent(&event))
......@@ -71,31 +115,6 @@ int main()
}
}
// DRAW
// GFX_ClearScreen(renderer, COLOR_BLACK);
// DESSINE LES CHARGES
GFX_DrawCircle(renderer, (coordinates_t){X_CHARGE_1, Y_CHARGE_1}, 25, COLOR_RED);
GFX_DrawCircle(renderer, (coordinates_t){X_CHARGE_2, Y_CHARGE_2}, 25, COLOR_BLUE);
// COMPUTE LA POSITION DES POINTS
e.x = 0;
e.y = 0;
compute_total_normalized_e(charges, 2, p, 0.5, &e);
// printf("%s\n", ? "TRUE" : "FALSE");
e = vec2_div(vec2_norm(e), e);
next_p = vec2_mul(1 / sqrt(WIDTH * WIDTH + HEIGHT * HEIGHT), e);
next_p = vec2_add(p, next_p);
vec2_print(e, "e :");
vec2_print(p, "p :");
vec2_print(next_p, "next_p :");
GFX_DrawLine(renderer, vec2_to_coordinates(p, WIDTH, HEIGHT), vec2_to_coordinates(next_p, WIDTH, HEIGHT), COLOR_WHITE);
p = next_p;
SDL_RenderPresent(renderer);
}
SDL_killAll(&window, &renderer);
SDL_Quit();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment