Skip to content
Snippets Groups Projects
Commit 787ca098 authored by JM's avatar JM
Browse files

merge

parents fb6b4fbc a26003e4
Branches
No related tags found
No related merge requests found
#include <math.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include "draw.h"
#include "field.h" #include "field.h"
#include "draw.h" #include "draw.h"
#include "../utils/utils.h" #include "../utils/utils.h"
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#define SIGN_SIZE 10 #define SIGN_SIZE 10
#define CHARGE_R 25 #define CHARGE_R 25
// Compute E*qP/norm(qP) // Compute E*qP/norm(qP)
// Return false if norm(qP) < eps // Return false if norm(qP) < eps
/// qP = vectoriel(P-q) /// qP = vectoriel(P-q)
...@@ -63,7 +64,7 @@ void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_char ...@@ -63,7 +64,7 @@ void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_char
coordinates_t sign_src = charge_center; coordinates_t sign_src = charge_center;
coordinates_t sign_dst = charge_center; coordinates_t sign_dst = charge_center;
uint32_t sign_color = COLOR_RED; uint32_t sign_color = COLOR_RED;
if (charges[i].q > 0){ if (charges[i].q > 0) {
sign_color = COLOR_BLUE; sign_color = COLOR_BLUE;
sign_src.row -= SIGN_SIZE; sign_src.row -= SIGN_SIZE;
sign_dst.row += SIGN_SIZE; sign_dst.row += SIGN_SIZE;
...@@ -77,3 +78,18 @@ void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_char ...@@ -77,3 +78,18 @@ void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_char
gfx_draw_line(context, sign_src, sign_dst, sign_color); gfx_draw_line(context, sign_src, sign_dst, sign_color);
} }
} }
void draw_everything(
struct gfx_context_t *ctxt,
charge_t *charges,
int num_charges,
int num_lines,
double dx,
double x0, double x1,
double y0, double y1) {
draw_charges(ctxt, charges, num_charges, x0, x1, y0, y1);
for (int i = 0; i < num_lines; ++i) {
vec2 pos0 = vec2_normalize(vec2_create(rand(), rand()));
draw_field_line(ctxt, charges, num_charges, dx, pos0, x0, x1, y0, y1);
}
}
...@@ -29,4 +29,13 @@ bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_char ...@@ -29,4 +29,13 @@ bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_char
// A circle with a plus sign for positive charges // A circle with a plus sign for positive charges
void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1); void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1);
void draw_everything(
struct gfx_context_t *ctxt,
charge_t *charges,
int num_charges,
int num_lines,
double dx,
double x0, double x1,
double y0, double y1);
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include "draw.h" #include "draw.h"
#include "field.h"
#include "../utils/utils.h" #include "../utils/utils.h"
#include "field.h" #include "field.h"
#define NCHARGES 2 #define NCHARGES 2
#define DX 0.0005 #define DX 0.0005
#define NPOINTS 32 #define NLINES 32
int main() { int main() {
srand(time(NULL)); srand(time(NULL));
...@@ -18,7 +21,7 @@ int main() { ...@@ -18,7 +21,7 @@ int main() {
draw_charges(ctxt, charges, NCHARGES, 0.0, 1.0, 0.0, 1.0); draw_charges(ctxt, charges, NCHARGES, 0.0, 1.0, 0.0, 1.0);
for (int i = 0; i < NPOINTS; ++i) { for (int i = 0; i < NCHARGES; ++i) {
vec2 start = vec2_normalize(vec2_create(rand(), rand())); vec2 start = vec2_normalize(vec2_create(rand(), rand()));
draw_field_line(ctxt, charges, NCHARGES, DX, start, 0.0, 1.0, 0.0, 1.0); draw_field_line(ctxt, charges, NCHARGES, DX, start, 0.0, 1.0, 0.0, 1.0);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment