Skip to content
Snippets Groups Projects
Commit 5a0a8bea authored by Boris Stefanovic's avatar Boris Stefanovic
Browse files

ADD: main

parent 0ea1da04
No related branches found
No related tags found
No related merge requests found
#ifndef _PHYSIQUE_H_
#define _PHYSIQUE_H_
#include "../utils/vec2/vec2.h"
#include "../utils/gfx/gfx.h"
#include "../utils/utils.h"
#include <stdio.h>
typedef struct _charge_t {
double q;
vec2 pos;
} charge_t;
// Compute E*qP/norm(qP)
// Return false if norm(qP) < eps
bool compute_e(charge_t c, vec2 p, double eps, vec2 *e);
......@@ -22,11 +18,15 @@ bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p, doub
// starting from pos0.
// Returns false if pos0 is not a valid position
// (for example if pos0 is too close to a charge).
static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double dx, vec2 pos0, double x0, double x1, double y0, double y1);
static bool
draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double dx, vec2 pos0, double x0,
double x1, double y0, double y1);
// Draw all the charges
// A circle with minus sign for negative charges
// A circle with a plus sign for positive charges
static void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1);
static void
draw_charges(struct gfx_context_t *context, charge_t *charges, int num_charges, double x0, double x1, double y0,
double y1);
#endif
#include <stdlib.h>
#include <time.h>
#include "draw.h"
#include "../utils/utils.h"
#define SIDE_LEN 1000
#define WID SIDE_LEN
#define HEI WID
#define NCHARGES 2
#define DX 0.0005
#define NPOINTS 32
int main() {
srand(time(NULL));
charge_t charges[NCHARGES] = {
{.q=-0.25, .pos=vec2_create(0.25, 0.5)},
{.q=0.25, .pos=vec2_create(0.75, 0.5)},
};
struct gfx_context_t *ctxt = gfx_create("elec", WID, HEI);
draw_charges(ctxt, charges, NCHARGES, 0.0, 1.0, 0.0, 1.0);
for (int i = 0; i < NPOINTS; ++i) {
vec2 start = vec2_normalize(vec2_create(rand(), rand()));
draw_field_line(ctxt, charges, NCHARGES, DX, start, 0.0, 1.0, 0.0, 1.0);
}
while (gfx_keypressed() != SDLK_ESCAPE) gfx_present(ctxt);
gfx_destroy(ctxt);
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment