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
76e544a8
Commit
76e544a8
authored
2 years ago
by
JM
Browse files
Options
Downloads
Patches
Plain Diff
Programme fonctionnel
parent
5fec85a2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/field.c
+23
-9
23 additions, 9 deletions
src/field.c
src/main.c
+5
-4
5 additions, 4 deletions
src/main.c
with
28 additions
and
13 deletions
src/field.c
+
23
−
9
View file @
76e544a8
...
...
@@ -55,11 +55,19 @@ bool draw_field_line_point(struct gfx_context_t *ctxt, charge_t *charges, int nu
compute_total_normalized_e
(
charges
,
num_charges
,
pos
,
0
.
01
,
&
e
);
double
norm_e
=
vec2_norm
(
e
);
// Problème ici
pos_next
->
x
=
pos
.
x
+
delta
*
(
e
.
x
/
norm_e
);
pos_next
->
y
=
pos
.
y
+
delta
*
(
e
.
y
/
norm_e
);
if
(
pos_next
->
x
<=
0
||
pos_next
->
x
>=
1
||
pos_next
->
y
<=
0
||
pos_next
->
y
>=
1
)
return
false
;
coordinates_t
coordinate_pos
=
position_to_coordinates
(
WID
,
HEI
,
x0
,
x1
,
y0
,
y1
,
pos
);
coordinates_t
coordinate_pos_next
=
position_to_coordinates
(
WID
,
HEI
,
x0
,
x1
,
y0
,
y1
,
*
pos_next
);
if
(
coordinate_pos_next
.
column
<=
0
||
coordinate_pos_next
.
row
<=
0
)
return
false
;
gfx_draw_line
(
ctxt
,
coordinate_pos
,
coordinate_pos_next
,
COLOR_YELLOW
);
return
!
is_in_screen
(
coordinate_pos
);
...
...
@@ -84,22 +92,28 @@ static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int n
vec2
pos_negative
=
vec2_create
(
pos0
.
x
,
pos0
.
y
);
vec2
pos_next_positive
;
vec2
pos_next_negative
;
bool
stop
=
false
;
bool
stop_positive
=
false
;
bool
stop_negative
=
false
;
// * 5 à supprimer lorsque le code est optimisé
double
delta
=
compute_delta_x
()
*
5
;
int
max_for
=
5
0
;
for
(
int
i
=
0
;
i
<
max_for
&&
!
stop
;
i
++
)
double
delta
=
compute_delta_x
();
int
max_for
=
10000
0
;
for
(
int
i
=
0
;
i
<
max_for
&&
(
!
stop
_positive
||
!
stop_negative
)
;
i
++
)
{
stop
=
line_reach_charge
(
pos_positive
,
charges
,
num_charges
,
dx
)
||
line_reach_charge
(
pos_negative
,
charges
,
num_charges
,
dx
);
if
(
!
stop
){
stop
=
draw_field_line_point
(
ctxt
,
charges
,
num_charges
,
x0
,
x1
,
y0
,
y1
,
pos_positive
,
&
pos_next_positive
,
delta
)
||
draw_field_line_point
(
ctxt
,
charges
,
num_charges
,
x0
,
x1
,
y0
,
y1
,
pos_negative
,
&
pos_next_negative
,
-
delta
);
stop_positive
=
line_reach_charge
(
pos_positive
,
charges
,
num_charges
,
dx
);
stop_negative
=
line_reach_charge
(
pos_negative
,
charges
,
num_charges
,
dx
);
if
(
!
stop_positive
){
stop_positive
=
draw_field_line_point
(
ctxt
,
charges
,
num_charges
,
x0
,
x1
,
y0
,
y1
,
pos_positive
,
&
pos_next_positive
,
delta
);
pos_positive
=
pos_next_positive
;
}
if
(
!
stop_negative
){
stop_negative
=
draw_field_line_point
(
ctxt
,
charges
,
num_charges
,
x0
,
x1
,
y0
,
y1
,
pos_negative
,
&
pos_next_negative
,
-
delta
);
pos_negative
=
pos_next_negative
;
}
}
return
!
stop
;
return
!
stop
_positive
||
!
stop_negative
;
}
// Draw all the charges
...
...
This diff is collapsed.
Click to expand it.
src/main.c
+
5
−
4
View file @
76e544a8
...
...
@@ -8,19 +8,20 @@
#define NCHARGES 2
#define DX 25
#define NLINES 5
#define NLINES 5
0
int
main
()
{
charge_t
charges
[
NCHARGES
]
=
{
charge_create
(
-
0
.
25
,
vec2_create
(
0
.
25
,
0
.
5
)),
charge_create
(
0
.
25
,
vec2_create
(
0
.
75
,
0
.
5
))
charge_create
(
0
.
25
,
vec2_create
(
0
.
25
,
0
.
5
)),
charge_create
(
-
0
.
25
,
vec2_create
(
0
.
75
,
0
.
5
))
};
struct
gfx_context_t
*
ctxt
=
gfx_create
(
"elec"
,
WID
,
HEI
);
draw_everything
(
ctxt
,
charges
,
NCHARGES
,
NLINES
,
DX
,
0
.
0
,
1
.
0
,
0
.
0
,
1
.
0
);
gfx_present
(
ctxt
);
while
(
gfx_keypressed
()
!=
SDLK_ESCAPE
)
gfx_present
(
ctxt
)
;
while
(
gfx_keypressed
()
!=
SDLK_ESCAPE
);
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