Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
phys_tp_elec
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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
boris.stefanov
phys_tp_elec
Commits
426c5804
Commit
426c5804
authored
2 years ago
by
JM
Browse files
Options
Downloads
Patches
Plain Diff
Affichage des charges
parent
513663b3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/draw.c
+8
-8
8 additions, 8 deletions
src/draw.c
src/field.c
+11
-10
11 additions, 10 deletions
src/field.c
src/field.h
+4
-0
4 additions, 0 deletions
src/field.h
src/main.c
+7
-7
7 additions, 7 deletions
src/main.c
with
30 additions
and
25 deletions
src/draw.c
+
8
−
8
View file @
426c5804
...
...
@@ -37,14 +37,14 @@ void gfx_draw_circle(struct gfx_context_t *ctxt, coordinates c, uint32_t r, uint
int
y
=
r
;
int
d
=
r
-
1
;
while
(
y
>=
x
){
gfx_putpixel
(
ctxt
,
c
.
row
+
x
,
c
.
column
+
y
,
color
);
gfx_putpixel
(
ctxt
,
c
.
row
+
y
,
c
.
column
+
x
,
color
);
gfx_putpixel
(
ctxt
,
c
.
row
-
x
,
c
.
column
+
y
,
color
);
gfx_putpixel
(
ctxt
,
c
.
row
-
y
,
c
.
column
+
x
,
color
);
gfx_putpixel
(
ctxt
,
c
.
row
+
x
,
c
.
column
-
y
,
color
);
gfx_putpixel
(
ctxt
,
c
.
row
+
y
,
c
.
column
-
x
,
color
);
gfx_putpixel
(
ctxt
,
c
.
row
-
x
,
c
.
column
-
y
,
color
);
gfx_putpixel
(
ctxt
,
c
.
row
-
y
,
c
.
column
-
x
,
color
);
gfx_putpixel
(
ctxt
,
c
.
column
+
x
,
c
.
row
+
y
,
color
);
gfx_putpixel
(
ctxt
,
c
.
column
+
y
,
c
.
row
+
x
,
color
);
gfx_putpixel
(
ctxt
,
c
.
column
-
x
,
c
.
row
+
y
,
color
);
gfx_putpixel
(
ctxt
,
c
.
column
-
y
,
c
.
row
+
x
,
color
);
gfx_putpixel
(
ctxt
,
c
.
column
+
x
,
c
.
row
-
y
,
color
);
gfx_putpixel
(
ctxt
,
c
.
column
+
y
,
c
.
row
-
x
,
color
);
gfx_putpixel
(
ctxt
,
c
.
column
-
x
,
c
.
row
-
y
,
color
);
gfx_putpixel
(
ctxt
,
c
.
column
-
y
,
c
.
row
-
x
,
color
);
if
(
d
>=
2
*
x
){
d
=
d
-
2
*
x
-
1
;
x
++
;
...
...
This diff is collapsed.
Click to expand it.
src/field.c
+
11
−
10
View file @
426c5804
...
...
@@ -57,22 +57,23 @@ bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_char
void
draw_charges
(
struct
gfx_context_t
*
context
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
)
{
for
(
int
i
=
0
;
i
<
num_charges
;
i
++
)
{
coordinates_t
charge_center
=
position_to_coordinates
(
CHARGE_R
,
CHARGE_R
,
x0
,
x1
,
y0
,
y1
,
charges
[
i
].
pos
);
coordinates_t
charge_center
=
position_to_coordinates
(
WID
,
HEI
,
x0
,
x1
,
y0
,
y1
,
charges
[
i
].
pos
);
gfx_draw_circle
(
context
,
charge_center
,
CHARGE_R
,
COLOR_WHITE
);
coordinates_t
sign_dst
;
coordinates_t
sign_src
=
charge_center
;
coordinates_t
sign_dst
=
charge_center
;
uint32_t
sign_color
=
COLOR_RED
;
if
(
charges
[
i
].
q
>
0
){
sign_color
=
COLOR_BLUE
;
sign_dst
.
row
=
charge_center
.
row
+
SIGN_SIZE
;
gfx_draw_line
(
context
,
charge_center
,
sign_dst
,
sign_color
);
sign_dst
.
row
=
charge_center
.
row
-
SIGN_SIZE
;
gfx_draw_line
(
context
,
charge_center
,
sign_dst
,
sign_color
);
sign_src
.
row
-=
SIGN_SIZE
;
sign_dst
.
row
+=
SIGN_SIZE
;
gfx_draw_line
(
context
,
sign_src
,
sign_dst
,
sign_color
);
sign_src
.
row
=
charge_center
.
row
;
sign_dst
.
row
=
charge_center
.
row
;
}
sign_dst
.
column
=
charge_center
.
column
+
SIGN_SIZE
;
gfx_draw_line
(
context
,
charge_center
,
sign_dst
,
sign_color
);
sign_dst
.
column
=
charge_center
.
column
-
SIGN_SIZE
;
gfx_draw_line
(
context
,
charge_center
,
sign_dst
,
sign_color
);
sign_src
.
column
-=
SIGN_SIZE
;
sign_dst
.
column
+=
SIGN_SIZE
;
gfx_draw_line
(
context
,
sign_src
,
sign_dst
,
sign_color
);
}
}
This diff is collapsed.
Click to expand it.
src/field.h
+
4
−
0
View file @
426c5804
...
...
@@ -6,6 +6,10 @@
#include
"../utils/utils.h"
#include
<stdio.h>
#define SIDE_LEN 1000
#define WID SIDE_LEN
#define HEI WID
// Compute E*qP/norm(qP)
// Return false if norm(qP) < eps
bool
compute_e
(
charge_t
c
,
vec2
p
,
double
eps
,
vec2
*
e
);
...
...
This diff is collapsed.
Click to expand it.
src/main.c
+
7
−
7
View file @
426c5804
...
...
@@ -4,9 +4,6 @@
#include
"../utils/utils.h"
#include
"field.h"
#define SIDE_LEN 1000
#define WID SIDE_LEN
#define HEI WID
#define NCHARGES 2
#define DX 0.0005
#define NPOINTS 32
...
...
@@ -18,11 +15,14 @@ int main() {
{.
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
);
}
//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
;
...
...
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