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
5a0a8bea
Commit
5a0a8bea
authored
2 years ago
by
Boris Stefanovic
Browse files
Options
Downloads
Patches
Plain Diff
ADD: main
parent
0ea1da04
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/field.h
+7
-7
7 additions, 7 deletions
src/field.h
src/main.c
+22
-0
22 additions, 0 deletions
src/main.c
with
29 additions
and
7 deletions
src/field.h
+
7
−
7
View file @
5a0a8bea
#ifndef _PHYSIQUE_H_
#define _PHYSIQUE_H_
#include
"../utils/vec2/vec2.h"
#include
"../utils/gfx/gfx.h"
#include
"../utils/utils.h"
#include
<stdio.h>
typedef
struct
_charge_t
{
double
q
;
vec2
pos
;
}
charge_t
;
// Compute E*qP/norm(qP)
// Return false if norm(qP) < eps
bool
compute_e
(
charge_t
c
,
vec2
p
,
double
eps
,
vec2
*
e
);
...
...
@@ -22,11 +18,15 @@ bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p, doub
// starting from pos0.
// Returns false if pos0 is not a valid position
// (for example if pos0 is too close to a charge).
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
);
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
);
// Draw all the charges
// A circle with minus sign for negative charges
// A circle with a plus sign for positive charges
static
void
draw_charges
(
struct
gfx_context_t
*
context
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
);
static
void
draw_charges
(
struct
gfx_context_t
*
context
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
);
#endif
This diff is collapsed.
Click to expand it.
src/main.c
+
22
−
0
View file @
5a0a8bea
#include
<stdlib.h>
#include
<time.h>
#include
"draw.h"
#include
"../utils/utils.h"
#define SIDE_LEN 1000
#define WID SIDE_LEN
#define HEI WID
#define NCHARGES 2
#define DX 0.0005
#define NPOINTS 32
int
main
()
{
srand
(
time
(
NULL
));
charge_t
charges
[
NCHARGES
]
=
{
{.
q
=-
0
.
25
,
.
pos
=
vec2_create
(
0
.
25
,
0
.
5
)},
{.
q
=
0
.
25
,
.
pos
=
vec2_create
(
0
.
75
,
0
.
5
)},
};
struct
gfx_context_t
*
ctxt
=
gfx_create
(
"elec"
,
WID
,
HEI
);
draw_charges
(
ctxt
,
charges
,
NCHARGES
,
0
.
0
,
1
.
0
,
0
.
0
,
1
.
0
);
for
(
int
i
=
0
;
i
<
NPOINTS
;
++
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
);
}
while
(
gfx_keypressed
()
!=
SDLK_ESCAPE
)
gfx_present
(
ctxt
);
gfx_destroy
(
ctxt
);
return
EXIT_SUCCESS
;
}
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