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
787ca098
Commit
787ca098
authored
3 years ago
by
JM
Browse files
Options
Downloads
Plain Diff
merge
parents
fb6b4fbc
a26003e4
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/field.c
+18
-2
18 additions, 2 deletions
src/field.c
src/field.h
+9
-0
9 additions, 0 deletions
src/field.h
src/main.c
+5
-2
5 additions, 2 deletions
src/main.c
with
32 additions
and
4 deletions
src/field.c
+
18
−
2
View file @
787ca098
#include
<math.h>
#include
<stdbool.h>
#include
<stdlib.h>
#include
"draw.h"
#include
"field.h"
#include
"draw.h"
#include
"../utils/utils.h"
...
...
@@ -9,6 +9,7 @@
#define SIGN_SIZE 10
#define CHARGE_R 25
// Compute E*qP/norm(qP)
// Return false if norm(qP) < eps
/// qP = vectoriel(P-q)
...
...
@@ -63,7 +64,7 @@ void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_char
coordinates_t
sign_src
=
charge_center
;
coordinates_t
sign_dst
=
charge_center
;
uint32_t
sign_color
=
COLOR_RED
;
if
(
charges
[
i
].
q
>
0
){
if
(
charges
[
i
].
q
>
0
)
{
sign_color
=
COLOR_BLUE
;
sign_src
.
row
-=
SIGN_SIZE
;
sign_dst
.
row
+=
SIGN_SIZE
;
...
...
@@ -77,3 +78,18 @@ void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_char
gfx_draw_line
(
context
,
sign_src
,
sign_dst
,
sign_color
);
}
}
void
draw_everything
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
int
num_lines
,
double
dx
,
double
x0
,
double
x1
,
double
y0
,
double
y1
)
{
draw_charges
(
ctxt
,
charges
,
num_charges
,
x0
,
x1
,
y0
,
y1
);
for
(
int
i
=
0
;
i
<
num_lines
;
++
i
)
{
vec2
pos0
=
vec2_normalize
(
vec2_create
(
rand
(),
rand
()));
draw_field_line
(
ctxt
,
charges
,
num_charges
,
dx
,
pos0
,
x0
,
x1
,
y0
,
y1
);
}
}
This diff is collapsed.
Click to expand it.
src/field.h
+
9
−
0
View file @
787ca098
...
...
@@ -29,4 +29,13 @@ bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_char
// A circle with a plus sign for positive charges
void
draw_charges
(
struct
gfx_context_t
*
context
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
);
void
draw_everything
(
struct
gfx_context_t
*
ctxt
,
charge_t
*
charges
,
int
num_charges
,
int
num_lines
,
double
dx
,
double
x0
,
double
x1
,
double
y0
,
double
y1
);
#endif
This diff is collapsed.
Click to expand it.
src/main.c
+
5
−
2
View file @
787ca098
#include
<stdlib.h>
#include
<time.h>
#include
"draw.h"
#include
"field.h"
#include
"../utils/utils.h"
#include
"field.h"
#define NCHARGES 2
#define DX 0.0005
#define NPOINTS 32
#define NLINES 32
int
main
()
{
srand
(
time
(
NULL
));
...
...
@@ -18,7 +21,7 @@ int main() {
draw_charges
(
ctxt
,
charges
,
NCHARGES
,
0
.
0
,
1
.
0
,
0
.
0
,
1
.
0
);
for
(
int
i
=
0
;
i
<
N
POINT
S
;
++
i
)
{
for
(
int
i
=
0
;
i
<
N
CHARGE
S
;
++
i
)
{
vec2
start
=
vec2_normalize
(
vec2_create
(
rand
(),
rand
()));
draw_field_line
(
ctxt
,
charges
,
NCHARGES
,
DX
,
start
,
0
.
0
,
1
.
0
,
0
.
0
,
1
.
0
);
}
...
...
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