Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ISC_126 - Travail Pratique 002 - Simulation de lignes de champ
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
florian.burgener
ISC_126 - Travail Pratique 002 - Simulation de lignes de champ
Commits
8f3cce37
Commit
8f3cce37
authored
3 years ago
by
gawen.ackerman
Browse files
Options
Downloads
Patches
Plain Diff
draw_line_field
parent
773499df
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/charge.c
+10
-5
10 additions, 5 deletions
src/charge.c
src/charge.h
+2
-2
2 additions, 2 deletions
src/charge.h
src/main.c
+1
-1
1 addition, 1 deletion
src/main.c
with
13 additions
and
8 deletions
src/charge.c
+
10
−
5
View file @
8f3cce37
...
...
@@ -17,10 +17,10 @@ double compute_delta_x(int width, int height) {
return
1
.
0
/
sqrt
((
width
*
width
)
+
(
height
*
height
));
}
bool
compute_next_point
(
charge_t
*
charges
,
int
num_charges
,
vector2_t
current_pos
,
double
eps
,
vector2_t
*
new_pos
,
double
dx
)
{
bool
compute_next_point
(
charge_t
*
charges
,
int
num_charges
,
vector2_t
current_pos
,
double
eps
,
vector2_t
*
new_pos
,
double
dx
,
int
orientation
)
{
vector2_t
electric_field
;
if
(
compute_total_normalized_e
(
charges
,
num_charges
,
current_pos
,
eps
,
&
electric_field
))
{
*
new_pos
=
vector2_add
(
current_pos
,
vector2_multiply
(
electric_field
,
dx
));
*
new_pos
=
vector2_add
(
current_pos
,
vector2_multiply
(
vector2_multiply
(
electric_field
,
dx
)
,
orientation
)
);
return
true
;
}
...
...
@@ -66,13 +66,13 @@ bool compute_total_normalized_e(charge_t *charges, int num_charges, vector2_t p,
return
true
;
}
void
draw_field_line
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
dx
,
vector2_t
pos0
,
double
x0
,
double
x1
,
double
y0
,
double
y1
)
{
void
draw_field_line
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
dx
,
vector2_t
pos0
,
double
x0
,
double
x1
,
double
y0
,
double
y1
,
int
orientation
)
{
vector2_t
current_pos
=
pos0
;
while
(
true
)
{
vector2_t
new_pos
;
if
(
!
compute_next_point
(
charges
,
num_charges
,
current_pos
,
4.5e-2
,
&
new_pos
,
dx
))
{
if
(
!
compute_next_point
(
charges
,
num_charges
,
current_pos
,
4.5e-2
,
&
new_pos
,
dx
,
orientation
))
{
break
;
}
...
...
@@ -82,11 +82,16 @@ void draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_char
coordinates_t
current_coordinates
=
position_to_coordinates
(
SCREEN_WIDTH
,
SCREEN_HEIGHT
,
x0
,
x1
,
y0
,
y1
,
current_pos
);
coordinates_t
new_coordinates
=
position_to_coordinates
(
SCREEN_WIDTH
,
SCREEN_HEIGHT
,
x0
,
x1
,
y0
,
y1
,
new_pos
);
gfx_draw_line
(
ctxt
,
current_coordinates
,
new_coordinates
,
COLOR_
BLU
E
);
gfx_draw_line
(
ctxt
,
current_coordinates
,
new_coordinates
,
COLOR_
WHIT
E
);
current_pos
=
new_pos
;
}
}
void
draw_field_lines
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
dx
,
vector2_t
pos0
,
double
x0
,
double
x1
,
double
y0
,
double
y1
){
draw_field_line
(
ctxt
,
charges
,
num_charges
,
dx
,
pos0
,
x0
,
x1
,
y0
,
y1
,
-
1
);
draw_field_line
(
ctxt
,
charges
,
num_charges
,
dx
,
pos0
,
x0
,
x1
,
y0
,
y1
,
1
);
}
void
draw_charges
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
)
{
for
(
int32_t
i
=
0
;
i
<
num_charges
;
i
+=
1
)
{
coordinates_t
c
=
position_to_coordinates
(
SCREEN_WIDTH
,
SCREEN_HEIGHT
,
x0
,
x1
,
y0
,
y1
,
charges
[
i
].
pos
);
...
...
This diff is collapsed.
Click to expand it.
src/charge.h
+
2
−
2
View file @
8f3cce37
...
...
@@ -22,7 +22,7 @@ charge_t charge_create(double q, vector2_t pos);
bool
compute_e
(
charge_t
c
,
vector2_t
p
,
double
eps
,
vector2_t
*
e
);
bool
compute_total_normalized_e
(
charge_t
*
charges
,
int
num_charges
,
vector2_t
p
,
double
eps
,
vector2_t
*
e
);
void
draw_field_line
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
dx
,
vector2_t
pos0
,
double
x0
,
double
x1
,
double
y0
,
double
y1
);
void
draw_field_line
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
dx
,
vector2_t
pos0
,
double
x0
,
double
x1
,
double
y0
,
double
y1
,
int
orientation
);
void
draw_charges
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
);
void
draw_field_lines
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
dx
,
vector2_t
pos0
,
double
x0
,
double
x1
,
double
y0
,
double
y1
);
#endif
This diff is collapsed.
Click to expand it.
src/main.c
+
1
−
1
View file @
8f3cce37
...
...
@@ -31,7 +31,7 @@ int main(int argc, char *argv[]) {
gfx_clear
(
canvas
,
COLOR_BLACK
);
draw_charges
(
canvas
,
charges
,
num_charges
,
x0
,
x1
,
y0
,
y1
);
draw_field_line
(
canvas
,
charges
,
num_charges
,
dx
,
vector2_create
(.
5
,
.
25
),
x0
,
x1
,
y0
,
y1
);
draw_field_line
s
(
canvas
,
charges
,
num_charges
,
dx
,
vector2_create
(.
5
,
.
25
),
x0
,
x1
,
y0
,
y1
);
gfx_present
(
canvas
);
while
(
true
)
{
...
...
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