Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
electric-field
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
repos.tanguy.cavagna
physics
electric-field
Commits
d140ffbc
Commit
d140ffbc
authored
3 years ago
by
Tanguy Cavagna
Browse files
Options
Downloads
Patches
Plain Diff
File reorder
parent
9b987a33
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#14863
failed
3 years ago
Stage: build
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
charge/charge.c
+22
-12
22 additions, 12 deletions
charge/charge.c
charge/charge.h
+8
-8
8 additions, 8 deletions
charge/charge.h
main.c
+10
-6
10 additions, 6 deletions
main.c
utilities/utils.c
+1
-1
1 addition, 1 deletion
utilities/utils.c
utilities/utils.h
+2
-2
2 additions, 2 deletions
utilities/utils.h
with
43 additions
and
29 deletions
charge.c
→
charge/
charge.c
+
22
−
12
View file @
d140ffbc
...
...
@@ -8,21 +8,25 @@
* @copyright Copyright (c) 2021
*
*/
#include
"draw/draw.h"
#include
"vector/vector.h"
#include
"utils.h"
#include
"
../
draw/draw.h"
#include
"
../
vector/vector.h"
#include
"
../utilities/
utils.h"
#include
"charge.h"
bool
compute_e
(
charge_t
c
,
vec2
p
,
double
eps
,
vec2
*
e
)
{
bool
compute_e
(
charge_t
c
,
vec2
p
,
double
eps
,
vec2
*
e
)
{
}
bool
compute_total_normalized_e
(
charge_t
*
charges
,
int
num_charges
,
vec2
p
,
double
eps
,
vec2
*
e
)
{
bool
compute_total_normalized_e
(
charge_t
*
charges
,
int
num_charges
,
vec2
p
,
double
eps
,
vec2
*
e
)
{
}
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
)
{
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
)
{
}
void
draw_charges
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
)
{
void
draw_charges
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
)
{
// Center coordinates
coordinates_t
c
;
...
...
@@ -34,13 +38,17 @@ void draw_charges(struct gfx_context_t *ctxt, charge_t *charges, int num_charges
int
chargePadding
=
10
;
// Draw charges
for
(
int
i
=
0
;
i
<
num_charges
;
i
++
)
{
for
(
int
i
=
0
;
i
<
num_charges
;
i
++
)
{
coordinates_t
chCoord
=
position_to_coordinates
(
ctxt
->
width
,
ctxt
->
height
,
x0
,
x1
,
y0
,
y1
,
charges
[
i
].
pos
);
// Draw sign according to charge value
if
(
charges
[
i
].
q
<
0
)
{
if
(
charges
[
i
].
q
<
0
)
{
gfx_draw_line
(
ctxt
,
coordinates_create
(
chCoord
.
row
,
chCoord
.
column
-
chargePadding
),
coordinates_create
(
chCoord
.
row
,
chCoord
.
column
+
chargePadding
),
COLOR_BLUE
);
}
else
{
}
else
{
gfx_draw_line
(
ctxt
,
coordinates_create
(
chCoord
.
row
,
chCoord
.
column
-
chargePadding
),
coordinates_create
(
chCoord
.
row
,
chCoord
.
column
+
chargePadding
),
COLOR_RED
);
gfx_draw_line
(
ctxt
,
coordinates_create
(
chCoord
.
row
-
chargePadding
,
chCoord
.
column
),
coordinates_create
(
chCoord
.
row
+
chargePadding
,
chCoord
.
column
),
COLOR_RED
);
}
...
...
@@ -49,11 +57,13 @@ void draw_charges(struct gfx_context_t *ctxt, charge_t *charges, int num_charges
}
}
void
generate_points
(
vec2
points
[],
int
nb_points
)
{
void
generate_points
(
vec2
points
[],
int
nb_points
)
{
double
x
=
0
;
double
y
=
0
;
for
(
int
i
=
0
;
i
<
nb_points
;
i
++
)
{
for
(
int
i
=
0
;
i
<
nb_points
;
i
++
)
{
x
=
rand_one
();
y
=
rand_one
();
...
...
This diff is collapsed.
Click to expand it.
charge.h
→
charge/
charge.h
+
8
−
8
View file @
d140ffbc
...
...
@@ -13,9 +13,9 @@
#include
<stdlib.h>
#include
<stdbool.h>
#include
"utils.h"
#include
"vector/vector.h"
#include
"gfx/gfx.h"
#include
"
../utilities/
utils.h"
#include
"
../
vector/vector.h"
#include
"
../
gfx/gfx.h"
/**
* @brief Compute E*qP/norm(qP)
...
...
@@ -38,7 +38,7 @@ bool compute_e(charge_t c, vec2 p, double eps, vec2 *e);
* @param e Electric field
* @return bool false for some qiP, norm(qiP) < eps
*/
bool
compute_total_normalized_e
(
charge_t
*
charges
,
int
num_charges
,
vec2
p
,
bool
compute_total_normalized_e
(
charge_t
*
charges
,
int
num_charges
,
vec2
p
,
double
eps
,
vec2
*
e
);
/**
...
...
@@ -56,9 +56,9 @@ bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p,
* @param y1 Maximal y of the universe
* @return bool false if pos0 not a valid pos (e.g. too close to a charge)
*/
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
);
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
);
/**
* @brief Draw all charges
...
...
@@ -74,7 +74,7 @@ bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges,
* @param y1 Maximal y of the universe
*/
void
draw_charges
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
);
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
);
/**
* @brief Generate a given amount of points
...
...
This diff is collapsed.
Click to expand it.
main.c
+
10
−
6
View file @
d140ffbc
...
...
@@ -13,7 +13,7 @@
#include
<time.h>
#include
<math.h>
#include
"gfx/gfx.h"
#include
"charge.h"
#include
"charge
/charge
.h"
#define WINDOW_WIDTH 500
#define WINDOW_HEIGHT 500
...
...
@@ -24,12 +24,14 @@
#define NB_CHARGES 2
#define NB_POINTS 100
int
main
(
void
)
{
int
main
(
void
)
{
srand
(
time
(
NULL
));
// GFX initialization
struct
gfx_context_t
*
ctxt
=
gfx_create
(
"draw"
,
WINDOW_WIDTH
,
WINDOW_HEIGHT
);
if
(
!
ctxt
)
{
if
(
!
ctxt
)
{
fprintf
(
stderr
,
"Graphics initialization failed !
\n
"
);
return
EXIT_FAILURE
;
}
...
...
@@ -41,13 +43,15 @@ int main(void) {
vec2
points
[
NB_POINTS
];
generate_points
(
points
,
NB_POINTS
);
for
(
int
i
=
0
;
i
<
NB_POINTS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
NB_POINTS
;
i
++
)
{
coordinates_t
c
=
position_to_coordinates
(
WINDOW_WIDTH
,
WINDOW_HEIGHT
,
x0
,
x1
,
y0
,
y1
,
points
[
i
]);
gfx_putpixel
(
ctxt
,
c
.
column
,
c
.
row
,
COLOR_WHITE
);
}
}
// GFX Draw loop
while
(
gfx_keypressed
()
!=
SDLK_ESCAPE
){
while
(
gfx_keypressed
()
!=
SDLK_ESCAPE
)
{
gfx_present
(
ctxt
);
}
...
...
This diff is collapsed.
Click to expand it.
utils.c
→
utilities/
utils.c
+
1
−
1
View file @
d140ffbc
#include
<math.h>
#include
<stdlib.h>
#include
"vector/vector.h"
#include
"
../
vector/vector.h"
#include
"utils.h"
// Transform a position in the univers [x0,y0]x[x1,y1] to a screen position
...
...
This diff is collapsed.
Click to expand it.
utils.h
→
utilities/
utils.h
+
2
−
2
View file @
d140ffbc
...
...
@@ -5,8 +5,8 @@
#define E 1.602e-19;
#include
<stdint.h>
#include
"vector/vector.h"
#include
"draw/draw.h"
#include
"
../
vector/vector.h"
#include
"
../
draw/draw.h"
typedef
struct
_charge_t
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment