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
a881dd4a
Commit
a881dd4a
authored
2 years ago
by
JM
Browse files
Options
Downloads
Patches
Plain Diff
Creation fonctions pour draw_field_line
parent
21f81f18
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/field.c
+30
-34
30 additions, 34 deletions
src/field.c
with
30 additions
and
34 deletions
src/field.c
+
30
−
34
View file @
a881dd4a
...
...
@@ -50,6 +50,31 @@ bool is_in_screen(coordinates_t pos){
return
true
;
}
bool
draw_field_line_point
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
,
vec2
pos
,
vec2
*
pos_next
,
double
delta
){
vec2
e
;
compute_total_normalized_e
(
charges
,
num_charges
,
pos
,
0
.
01
,
&
e
);
double
norm_e
=
vec2_norm
(
e
);
pos_next
->
x
=
pos
.
x
+
delta
*
(
e
.
x
/
norm_e
);
pos_next
->
y
=
pos
.
y
+
delta
*
(
e
.
y
/
norm_e
);
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
);
gfx_draw_line
(
ctxt
,
coordinate_pos
,
coordinate_pos_next
,
COLOR_YELLOW
);
return
!
is_in_screen
(
coordinate_pos
);
}
bool
line_reach_charge
(
vec2
pos
,
charge_t
*
charges
,
double
num_charges
,
double
dx
){
for
(
int
j
=
0
;
j
<
num_charges
;
j
++
){
if
(
vec2_norm
(
vec2_sub
(
pos
,
charges
[
j
].
pos
))
<
dx
/
HEI
){
return
true
;
}
}
return
false
;
}
// Compute and then draw all the points belonging to a field line,
// starting from pos0.
// Returns false if pos0 is not a valid position
...
...
@@ -57,56 +82,27 @@ bool is_in_screen(coordinates_t pos){
static
bool
draw_field_line
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
double
dx
,
vec2
pos0
,
double
x0
,
double
x1
,
double
y0
,
double
y1
)
{
vec2
pos
=
vec2_create
(
pos0
.
x
,
pos0
.
y
);
vec2
pos_next
;
vec2
e
;
bool
stop
=
false
;
double
delta
=
compute_delta_x
()
*
5
;
int
max_for
=
30
0
;
int
max_for
=
5
0
;
for
(
int
i
=
0
;
i
<
max_for
&&
!
stop
;
i
++
)
{
for
(
int
j
=
0
;
j
<
num_charges
&&
!
stop
;
j
++
){
if
(
vec2_norm
(
vec2_sub
(
pos
,
charges
[
j
].
pos
))
<
dx
/
HEI
){
stop
=
true
;
}
}
stop
=
line_reach_charge
(
pos
,
charges
,
num_charges
,
dx
);
if
(
!
stop
){
compute_total_normalized_e
(
charges
,
num_charges
,
pos
,
0
.
01
,
&
e
);
double
norm_e
=
vec2_norm
(
e
);
pos_next
.
x
=
pos
.
x
+
delta
*
(
e
.
x
/
norm_e
);
pos_next
.
y
=
pos
.
y
+
delta
*
(
e
.
y
/
norm_e
);
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
);
gfx_draw_line
(
ctxt
,
coordinate_pos
,
coordinate_pos_next
,
COLOR_YELLOW
);
stop
=
draw_field_line_point
(
ctxt
,
charges
,
num_charges
,
x0
,
x1
,
y0
,
y1
,
pos
,
&
pos_next
,
-
delta
);
pos
=
pos_next
;
if
(
!
is_in_screen
(
coordinate_pos
))
stop
=
false
;
}
}
pos
=
vec2_create
(
pos0
.
x
,
pos0
.
y
);
stop
=
false
;
for
(
int
i
=
0
;
i
<
max_for
&&
!
stop
;
i
++
)
{
for
(
int
j
=
0
;
j
<
num_charges
&&
!
stop
;
j
++
){
if
(
vec2_norm
(
vec2_sub
(
pos
,
charges
[
j
].
pos
))
<
dx
/
HEI
){
stop
=
true
;
}
}
stop
=
line_reach_charge
(
pos
,
charges
,
num_charges
,
dx
);
if
(
!
stop
){
compute_total_normalized_e
(
charges
,
num_charges
,
pos
,
0
.
01
,
&
e
);
double
norm_e
=
vec2_norm
(
e
);
pos_next
.
x
=
pos
.
x
-
delta
*
(
e
.
x
/
norm_e
);
pos_next
.
y
=
pos
.
y
-
delta
*
(
e
.
y
/
norm_e
);
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
);
gfx_draw_line
(
ctxt
,
coordinate_pos
,
coordinate_pos_next
,
COLOR_YELLOW
);
stop
=
draw_field_line_point
(
ctxt
,
charges
,
num_charges
,
x0
,
x1
,
y0
,
y1
,
pos
,
&
pos_next
,
delta
);
pos
=
pos_next
;
if
(
!
is_in_screen
(
coordinate_pos
))
stop
=
false
;
}
}
...
...
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