diff --git a/utils.c b/utils.c new file mode 100644 index 0000000000000000000000000000000000000000..b352979c761a1591a41b48b152a0d1735524eb6f --- /dev/null +++ b/utils.c @@ -0,0 +1,29 @@ +#include <math.h> +#include <stdlib.h> +#include "vector/vector.h" +#include "utils.h" + +coordinates_t coordinates_create(int row_, int column_) +{ + coordinates_t c = {.row = row_, .column = column_}; + return c; +} + +// Transform a position in the univers [x0,y0]x[x1,y1] to a screen position +coordinates_t position_to_coordinates(int width, int height, double x0, double x1, double y0, double y1, vector pos) +{ + double dx = x1 - x0; + double dy = y1 - y0; + return coordinates_create((int)round(height * (pos.y - y0) / dy), (int)round(width * (pos.x - x0) / dx)); +} + +double rand_one() +{ + return (double)rand() / (double)RAND_MAX; +} + +charge_t charge_create(double q, vector pos) +{ + charge_t c = {.q = q, .pos = pos}; + return c; +} \ No newline at end of file diff --git a/utils.h b/utils.h new file mode 100644 index 0000000000000000000000000000000000000000..0881c6e8e0b333b0f83c6d54cfbb4a9a05b4e078 --- /dev/null +++ b/utils.h @@ -0,0 +1,31 @@ +#ifndef _UTILS_H_ +#define _UTILS_H_ + +#define K 8.988e9; +#define E 1.602e-19; + +#include <stdint.h> +#include "vector/vector.h" + +typedef struct +{ + uint32_t row; + uint32_t column; +} coordinates_t; + +typedef struct +{ + double q; + vector pos; +} charge_t; + +coordinates_t coordinates_create(int row_, int column_); + +// Transform a position in the univers [x0,y0]x[x1,y1] to a screen position +coordinates_t position_to_coordinates(int width, int height, double x0, double x1, double y0, double y1, vector pos); + +double rand_one(); + +charge_t charge_create(double q, vector pos); + +#endif \ No newline at end of file