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
d9ec08d2
Commit
d9ec08d2
authored
2 years ago
by
JM
Browse files
Options
Downloads
Patches
Plain Diff
Stop line
parent
63bee7c6
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
+20
-13
20 additions, 13 deletions
src/field.c
src/main.c
+3
-3
3 additions, 3 deletions
src/main.c
with
23 additions
and
16 deletions
src/field.c
+
20
−
13
View file @
d9ec08d2
...
...
@@ -49,23 +49,30 @@ static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int n
vec2
pos_sum
;
vec2
pos_next
;
vec2
e
;
bool
stop
=
false
;
double
delta
=
compute_delta_x
();
// Remplacer par une boucle qui s'arrête lorsqu'on atteint une charge
for
(
int
i
=
0
;
i
<
100
;
i
++
)
uint32_t
color
=
COLOR_YELLOW
;
for
(
int
i
=
0
;
i
<
100
&&
!
stop
;
i
++
)
{
compute_total_normalized_e
(
charges
,
num_charges
,
pos
,
0
.
01
,
&
e
);
pos_next
.
x
=
pos
.
x
+
delta
*
(
e
.
x
/
vec2_normalize
(
e
).
x
);
pos_next
.
y
=
pos
.
y
+
delta
*
(
e
.
y
/
vec2_normalize
(
e
).
y
);
for
(
int
j
=
0
;
j
<
num_charges
&&
!
stop
;
j
++
){
if
(
vec2_norm
(
vec2_sub
(
pos
,
charges
[
j
].
pos
))
<
dx
/
HEI
){
color
=
COLOR_RED
;
stop
=
true
;
}
}
if
(
!
stop
){
compute_total_normalized_e
(
charges
,
num_charges
,
pos
,
0
.
01
,
&
e
);
pos_next
.
x
=
pos
.
x
+
delta
*
(
e
.
x
/
vec2_normalize
(
e
).
x
);
pos_next
.
y
=
pos
.
y
+
delta
*
(
e
.
y
/
vec2_normalize
(
e
).
y
);
//printf("%f + %f * (%f / %f)\n", pos.x, delta, e.x, vec2_normalize(e).x
);
//printf("%f %f\n", pos_next.x
, pos_next
.y
);
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
);
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
);
//printf("%d %d\n", charge_1.column, charge_1.row);
//printf("%d %d\n\n", charge_2.column, charge_2.row);
gfx_draw_line
(
ctxt
,
coordinate_pos
,
coordinate_pos_next
,
COLOR_YELLOW
);
pos
=
pos_next
;
gfx_draw_line
(
ctxt
,
coordinate_pos
,
coordinate_pos_next
,
color
);
pos
=
pos_next
;
}
}
return
EXIT_SUCCESS
;
...
...
@@ -109,7 +116,7 @@ void draw_everything(
srand
(
time
(
NULL
));
draw_charges
(
ctxt
,
charges
,
num_charges
,
x0
,
x1
,
y0
,
y1
);
for
(
int
i
=
0
;
i
<
num_lines
;
++
i
)
{
vec2
pos0
=
vec2_create
(
(
double
)
rand
()
/
RAND_MAX
,
(
double
)
rand
()
/
RAND_MAX
);
vec2
pos0
=
vec2_create
(
rand_one
(),
rand_one
()
);
draw_field_line
(
ctxt
,
charges
,
num_charges
,
dx
,
pos0
,
x0
,
x1
,
y0
,
y1
);
}
}
This diff is collapsed.
Click to expand it.
src/main.c
+
3
−
3
View file @
d9ec08d2
...
...
@@ -7,14 +7,14 @@
#include
"field.h"
#define NCHARGES 2
#define DX
0.000
5
#define DX
2
5
#define NLINES 32
int
main
()
{
charge_t
charges
[
NCHARGES
]
=
{
{.
q
=
-
0
.
25
,
.
pos
=
vec2_create
(
0
.
25
,
0
.
5
)
}
,
{.
q
=
0
.
25
,
.
pos
=
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
);
...
...
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