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
835bca55
Commit
835bca55
authored
3 years ago
by
JM
Browse files
Options
Downloads
Patches
Plain Diff
ADD: draw_charges(...) RM: field.h: struct charge
parent
0ea1da04
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/draw.c
+0
-6
0 additions, 6 deletions
src/draw.c
src/field.c
+24
-6
24 additions, 6 deletions
src/field.c
src/field.h
+0
-5
0 additions, 5 deletions
src/field.h
src/main.c
+1
-0
1 addition, 0 deletions
src/main.c
utils/gfx/gfx.h
+1
-1
1 addition, 1 deletion
utils/gfx/gfx.h
with
26 additions
and
18 deletions
src/draw.c
+
0
−
6
View file @
835bca55
#include
"../utils/gfx/gfx.h"
#include
"../utils/gfx/gfx.h"
#include
"field.h"
#include
"field.h"
/*
(50, 50) → (75, 50)1 , (50, 50) → (72, 62), (50, 50) → (62, 72)
(50, 50) → (50, 75), (50, 50) → (38, 72), (50, 50) → (28, 62)
(50, 50) → (25, 50), (50, 50) → (28, 38), (50, 50) → (37, 28)
(50, 50) → (50, 25), (50, 50) → (62, 28), (50, 50) → (72, 37)
*/
void
gfx_draw_line
(
struct
gfx_context_t
*
ctxt
,
coordinates_t
p0
,
coordinates_t
p1
,
uint32_t
color
)
{
void
gfx_draw_line
(
struct
gfx_context_t
*
ctxt
,
coordinates_t
p0
,
coordinates_t
p1
,
uint32_t
color
)
{
int
dx
=
abs
(
p1
.
column
-
p0
.
column
);
int
dx
=
abs
(
p1
.
column
-
p0
.
column
);
...
...
This diff is collapsed.
Click to expand it.
src/field.c
+
24
−
6
View file @
835bca55
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
#include
"field.h"
#include
"field.h"
#include
"../utils/utils.h"
#include
"../utils/utils.h"
#define SIGN_SIZE 10
#define CHARGE_R 25
// Compute E*qP/norm(qP)
// Compute E*qP/norm(qP)
// Return false if norm(qP) < eps
// Return false if norm(qP) < eps
...
@@ -36,16 +38,32 @@ bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p, doub
...
@@ -36,16 +38,32 @@ bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p, doub
// starting from pos0.
// starting from pos0.
// Returns false if pos0 is not a valid position
// Returns false if pos0 is not a valid position
// (for example if pos0 is too close to a charge).
// (for example if pos0 is too close to a charge).
static
bool
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_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
)
{
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
// Draw all the charges
// Draw all the charges
// A circle with minus sign for negative charges
// A circle with minus sign for negative charges
// A circle with a plus sign for positive charges
// A circle with a plus sign for positive charges
static
void
static
void
draw_charges
(
struct
gfx_context_t
*
context
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
double
y1
)
{
draw_charges
(
struct
gfx_context_t
*
context
,
charge_t
*
charges
,
int
num_charges
,
double
x0
,
double
x1
,
double
y0
,
for
(
int
i
=
0
;
i
<
num_charges
;
i
++
)
double
y1
)
{
{
coordinates_t
charge_center
=
position_to_coordinates
(
CHARGE_R
,
CHARGE_R
,
x0
,
x1
,
y0
,
y1
,
charges
[
i
].
pos
);
gfx_draw_circle
(
context
,
charge_center
,
CHARGE_R
,
COLOR_WHITE
);
coordinates_t
sign_dst
;
uint32_t
sign_color
=
COLOR_RED
;
if
(
charges
[
i
].
q
>
0
){
sign_color
=
COLOR_BLUE
;
sign_dst
.
row
=
charge_center
.
row
+
SIGN_SIZE
;
gfx_draw_line
(
context
,
charge_center
,
sign_dst
,
sign_color
);
sign_dst
.
row
=
charge_center
.
row
-
SIGN_SIZE
;
gfx_draw_line
(
context
,
charge_center
,
sign_dst
,
sign_color
);
}
sign_dst
.
column
=
charge_center
.
column
+
SIGN_SIZE
;
gfx_draw_line
(
context
,
charge_center
,
sign_dst
,
sign_color
);
sign_dst
.
column
=
charge_center
.
column
-
SIGN_SIZE
;
gfx_draw_line
(
context
,
charge_center
,
sign_dst
,
sign_color
);
}
}
}
This diff is collapsed.
Click to expand it.
src/field.h
+
0
−
5
View file @
835bca55
...
@@ -5,11 +5,6 @@
...
@@ -5,11 +5,6 @@
#include
"../utils/utils.h"
#include
"../utils/utils.h"
#include
<stdio.h>
#include
<stdio.h>
typedef
struct
_charge_t
{
double
q
;
vec2
pos
;
}
charge_t
;
// Compute E*qP/norm(qP)
// Compute E*qP/norm(qP)
// Return false if norm(qP) < eps
// Return false if norm(qP) < eps
bool
compute_e
(
charge_t
c
,
vec2
p
,
double
eps
,
vec2
*
e
);
bool
compute_e
(
charge_t
c
,
vec2
p
,
double
eps
,
vec2
*
e
);
...
...
This diff is collapsed.
Click to expand it.
src/main.c
+
1
−
0
View file @
835bca55
...
@@ -2,5 +2,6 @@
...
@@ -2,5 +2,6 @@
#include
"draw.h"
#include
"draw.h"
int
main
()
{
int
main
()
{
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
This diff is collapsed.
Click to expand it.
utils/gfx/gfx.h
+
1
−
1
View file @
835bca55
...
@@ -31,7 +31,7 @@ struct gfx_context_t
...
@@ -31,7 +31,7 @@ struct gfx_context_t
extern
void
gfx_putpixel
(
extern
void
gfx_putpixel
(
struct
gfx_context_t
*
ctxt
,
uint32_t
column
,
uint32_t
row
,
uint32_t
color
);
struct
gfx_context_t
*
ctxt
,
uint32_t
column
,
uint32_t
row
,
uint32_t
color
);
extern
void
gfx_clear
(
struct
gfx_context_t
*
ctxt
,
uint32_t
color
);
extern
void
gfx_clear
(
struct
gfx_context_t
*
ctxt
,
uint32_t
color
);
extern
struct
gfx_context_t
*
gfx_create
(
char
*
text
,
uint32_t
width
,
uint32_t
height
);
extern
struct
gfx_context_t
*
gfx_create
(
char
*
text
,
uint32_t
width
,
uint32_t
height
);
extern
void
gfx_destroy
(
struct
gfx_context_t
*
ctxt
);
extern
void
gfx_destroy
(
struct
gfx_context_t
*
ctxt
);
...
...
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