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
8808ec3f
Commit
8808ec3f
authored
3 years ago
by
florian.burgener
Browse files
Options
Downloads
Patches
Plain Diff
Add more constants
parent
2055cda6
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/Simulation.c
+6
-6
6 additions, 6 deletions
src/Simulation.c
src/constants.c
+3
-0
3 additions, 0 deletions
src/constants.c
src/constants.h
+1
-0
1 addition, 0 deletions
src/constants.h
with
10 additions
and
6 deletions
src/Simulation.c
+
6
−
6
View file @
8808ec3f
#include
"Simulation.h"
#include
<math.h>
#include
<stdlib.h>
#include
"Charge.h"
...
...
@@ -25,7 +26,7 @@ static Charge *generate_random_charges(Rectangle *universe, int *charges_length)
Charge
charge
=
generate_random_charge
();
Vector2
position
=
charge
.
position
;
double
eps
=
(
double
)
CHARGE_CIRCLE_RADIUS
/
SCREEN_WIDTH
;
double
eps
=
RADIUS_TRESHOLD
;
if
(
is_out_of_bounds
(
universe
,
vector2_add
(
position
,
vector2_init
(
0
,
-
eps
))))
{
continue
;
}
...
...
@@ -106,13 +107,10 @@ static bool compute_next_point(Simulation *simulation, int direction, Vector2 cu
static
void
draw_field_line_with_direction
(
Simulation
*
simulation
,
Graphics
*
graphics
,
Vector2
starting_point
,
int
direction
)
{
Vector2
current_point
=
starting_point
;
// Represents the acceptable distance between the last point and the charge, this distance is calculated with
// the radius of the charge display circle and the width of the window.
double
eps
=
(
double
)
CHARGE_CIRCLE_RADIUS
/
SCREEN_WIDTH
;
while
(
true
)
{
Vector2
next_point
;
if
(
!
compute_next_point
(
simulation
,
direction
,
current_point
,
eps
,
&
next_point
))
{
if
(
!
compute_next_point
(
simulation
,
direction
,
current_point
,
RADIUS_TRESHOLD
,
&
next_point
))
{
break
;
}
...
...
@@ -159,7 +157,9 @@ void simulation_draw(Simulation *simulation, Graphics *graphics) {
double
angle
=
0
;
while
(
angle
<
2
*
M_PI
)
{
angle
+=
2
*
M_PI
/
64
;
Vector2
starting_point
=
vector2_add
(
position
,
vector2_init
(
cos
(
angle
)
*
0
.
1
,
sin
(
angle
)
*
0
.
1
));
double
x
=
cos
(
angle
)
*
RADIUS_TRESHOLD
*
1
.
1
;
double
y
=
sin
(
angle
)
*
RADIUS_TRESHOLD
*
1
.
1
;
Vector2
starting_point
=
vector2_add
(
position
,
vector2_init
(
x
,
y
));
draw_field_line
(
simulation
,
graphics
,
starting_point
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/constants.c
+
3
−
0
View file @
8808ec3f
...
...
@@ -15,3 +15,6 @@ const int MAX_CHARGES = 5;
const
double
K
=
8.988e9
;
const
double
ELEMENTARY_CHARGE
=
1.602e-19
;
// Represents the acceptable distance between the last point and the charge, this distance is calculated with
// the radius of the charge display circle and the width of the window.
const
double
RADIUS_TRESHOLD
=
(
double
)
CHARGE_CIRCLE_RADIUS
/
SCREEN_WIDTH
;
This diff is collapsed.
Click to expand it.
src/constants.h
+
1
−
0
View file @
8808ec3f
...
...
@@ -16,5 +16,6 @@ extern const int MAX_CHARGES;
extern
const
double
K
;
extern
const
double
ELEMENTARY_CHARGE
;
extern
const
double
RADIUS_TRESHOLD
;
#endif
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