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
773499df
Commit
773499df
authored
3 years ago
by
florian.burgener
Browse files
Options
Downloads
Patches
Plain Diff
Draw half field line
parent
a3a7dc05
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/charge.c
+5
-11
5 additions, 11 deletions
src/charge.c
src/main.c
+2
-3
2 additions, 3 deletions
src/main.c
src/utils.c
+2
-2
2 additions, 2 deletions
src/utils.c
src/vector2.c
+1
-1
1 addition, 1 deletion
src/vector2.c
with
10 additions
and
17 deletions
src/charge.c
+
5
−
11
View file @
773499df
...
...
@@ -14,15 +14,13 @@ const double THRESHOLD_CHARGES_DISTANCES = 0.5;
const
double
EPSILON
=
0
.
05
;
double
compute_delta_x
(
int
width
,
int
height
)
{
printf
(
"aaa %lf
\n
"
,
1
.
0
/
sqrt
((
width
*
width
)
+
(
height
*
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
)
{
vector2_t
electric_field
;
if
(
!
compute_total_normalized_e
(
charges
,
num_charges
,
current_pos
,
eps
,
&
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
));
printf
(
"adf %lf
\n
"
,
dx
);
return
true
;
}
...
...
@@ -49,10 +47,12 @@ bool compute_e(charge_t c, vector2_t p, double eps, vector2_t *e) {
*
e
=
vector2_multiply
(
*
e
,
-
1
);
}
return
norm_r
<
eps
;
return
norm_r
>=
eps
;
}
bool
compute_total_normalized_e
(
charge_t
*
charges
,
int
num_charges
,
vector2_t
p
,
double
eps
,
vector2_t
*
e
)
{
*
e
=
vector2_create_zero
();
for
(
int
i
=
0
;
i
<
num_charges
;
i
+=
1
)
{
vector2_t
tmp
;
if
(
!
compute_e
(
charges
[
i
],
p
,
eps
,
&
tmp
))
{
...
...
@@ -72,24 +72,18 @@ void draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_char
while
(
true
)
{
vector2_t
new_pos
;
if
(
!
compute_next_point
(
charges
,
num_charges
,
current_pos
,
EPSILON
,
&
new_pos
,
dx
))
{
if
(
!
compute_next_point
(
charges
,
num_charges
,
current_pos
,
4.5e-2
,
&
new_pos
,
dx
))
{
break
;
}
vector2_print
(
current_pos
);
vector2_print
(
new_pos
);
if
(
is_out_of_bounds
(
new_pos
,
x0
,
x1
,
y0
,
y1
))
{
break
;
}
coordinates_t
current_coordinates
=
position_to_coordinates
(
SCREEN_WIDTH
,
SCREEN_HEIGHT
,
x0
,
x1
,
y0
,
y1
,
current_pos
);
printf
(
"%d %d
\n
"
,
current_coordinates
.
row
,
current_coordinates
.
column
);
coordinates_t
new_coordinates
=
position_to_coordinates
(
SCREEN_WIDTH
,
SCREEN_HEIGHT
,
x0
,
x1
,
y0
,
y1
,
new_pos
);
printf
(
"%d %d
\n
"
,
new_coordinates
.
row
,
new_coordinates
.
column
);
gfx_draw_line
(
ctxt
,
current_coordinates
,
new_coordinates
,
COLOR_BLUE
);
current_pos
=
new_pos
;
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main.c
+
2
−
3
View file @
773499df
...
...
@@ -24,15 +24,14 @@ int main(int argc, char *argv[]) {
int
num_charges
=
2
;
charge_t
*
charges
=
(
charge_t
*
)
malloc
(
sizeof
(
charge_t
)
*
num_charges
);
charges
[
0
]
=
charge_create
(
-
ELEMENTARY_CHARGE
,
vector2_create
(.
5
,
.
5
));
charges
[
0
]
=
charge_create
(
-
ELEMENTARY_CHARGE
,
vector2_create
(.
2
5
,
.
5
));
charges
[
1
]
=
charge_create
(
ELEMENTARY_CHARGE
,
vector2_create
(.
75
,
.
5
));
double
dx
=
compute_delta_x
(
SCREEN_WIDTH
,
SCREEN_HEIGHT
);
gfx_clear
(
canvas
,
COLOR_BLACK
);
draw_charges
(
canvas
,
charges
,
num_charges
,
x0
,
x1
,
y0
,
y1
);
printf
(
"adadf a %lf
\n
"
,
dx
);
draw_field_line
(
canvas
,
charges
,
num_charges
,
dx
,
vector2_create
(.
5
,
.
2
),
x0
,
x1
,
y0
,
y1
);
draw_field_line
(
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.
src/utils.c
+
2
−
2
View file @
773499df
...
...
@@ -5,8 +5,8 @@
#include
"vector2.h"
const
int
SCREEN_WIDTH
=
10
00
;
const
int
SCREEN_HEIGHT
=
10
00
;
const
int
SCREEN_WIDTH
=
5
00
;
const
int
SCREEN_HEIGHT
=
5
00
;
coordinates_t
coordinates_create
(
int
row_
,
int
column_
)
{
coordinates_t
c
=
{.
row
=
row_
,
.
column
=
column_
};
...
...
This diff is collapsed.
Click to expand it.
src/vector2.c
+
1
−
1
View file @
773499df
...
...
@@ -49,5 +49,5 @@ vector2_t vector2_fit_canvas(vector2_t v, int32_t width, int32_t height) {
}
void
vector2_print
(
vector2_t
v
)
{
printf
(
"(%lf, %lf)
\n
"
,
v
.
x
,
v
.
y
);
printf
(
"(%
.40
lf, %
.40
lf)
\n
"
,
v
.
x
,
v
.
y
);
}
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