Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
constant-workspace-algorithms-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mikadelor
constant-workspace-algorithms-c
Commits
eb3c9dca
Commit
eb3c9dca
authored
6 years ago
by
mika
Browse files
Options
Downloads
Patches
Plain Diff
weiteres Code-Clean-up und verbesserte Implementierung
parent
cd8f9e97
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/delaunay.c
+12
-105
12 additions, 105 deletions
src/delaunay.c
src/delaunay.h
+0
-1
0 additions, 1 deletion
src/delaunay.h
src/helper.c
+1
-1
1 addition, 1 deletion
src/helper.c
src/helper.h
+3
-3
3 additions, 3 deletions
src/helper.h
src/main.c
+3
-2
3 additions, 2 deletions
src/main.c
with
19 additions
and
112 deletions
src/delaunay.c
+
12
−
105
View file @
eb3c9dca
...
...
@@ -13,78 +13,23 @@
int
comparePointsByX
(
const
void
*
a
,
const
void
*
b
)
{
vertex
*
pointA
=
(
vertex
*
)
a
;
vertex
*
pointB
=
(
vertex
*
)
b
;
if
(
pointA
->
x
>
pointB
->
x
)
return
1
;
if
(
pointA
->
x
<
pointB
->
x
)
return
-
1
;
return
0
;
double
distanceSquared
(
vertex
p1
,
vertex
p2
)
{
double
x
=
p1
.
x
-
p2
.
x
;
double
y
=
p1
.
y
-
p2
.
y
;
return
(
x
*
x
+
y
*
y
);
}
/*int reportLine(vertex* p, int size, FILE *out) {
line l = {p[0], p[1]};
svgDrawLine(l, out);
l.a = p[0];
l.b = p[2];
svgDrawLine(l, out);
return 1;
}*/
void
reportTriangle
(
vertex
a
,
vertex
b
,
vertex
c
)
{
// qsort (p, size, sizeof(*p), comparePointsByX);
//
// char *color = "255,0,0";
#ifdef OUTPUTFILE
svgDrawTriangle
(
a
,
b
,
c
);
#endif
// edge l = {p[0], p[1]};
// svgDrawLine(l, out, color);
// l.b = p[2];
// svgDrawLine(l, out, color);
// l.a = p[1];
// svgDrawLine(l, out, color);
}
//http://mathforum.org/library/drmath/view/54323.html
circle
circle_vvv
(
vertex
v1
,
vertex
v2
,
vertex
v3
)
{
circle
c
;
double
bx
=
v1
.
x
;
double
by
=
v1
.
y
;
double
cx
=
v2
.
x
;
double
cy
=
v2
.
y
;
double
dx
=
v3
.
x
;
double
dy
=
v3
.
y
;
double
temp
=
cx
*
cx
+
cy
*
cy
;
double
bc
=
(
bx
*
bx
+
by
*
by
-
temp
)
/
2
.
0
;
double
cd
=
(
temp
-
dx
*
dx
-
dy
*
dy
)
/
2
.
0
;
double
det
=
(
bx
-
cx
)
*
(
cy
-
dy
)
-
(
cx
-
dx
)
*
(
by
-
cy
);
if
(
fabs
(
det
)
<
1.0e-6
)
{
c
.
center
.
x
=
c
.
center
.
y
=
1
.
0
;
return
c
;
}
det
=
1
/
det
;
c
.
center
.
x
=
(
bc
*
(
cy
-
dy
)
-
cd
*
(
by
-
cy
))
*
det
;
c
.
center
.
y
=
((
bx
-
cx
)
*
cd
-
(
cx
-
dx
)
*
bc
)
*
det
;
cx
=
c
.
center
.
x
;
cy
=
c
.
center
.
y
;
c
.
radius
=
distance
(
v1
,
c
.
center
);
return
c
;
}
double
det2
(
double
a
,
double
b
,
double
c
,
double
d
)
{
return
a
*
d
-
b
*
c
;
}
...
...
@@ -102,34 +47,14 @@ void circleCenter(const vertex* v1, const vertex* v2, const vertex* v3,
center
->
y
=
det2
(
ax
,
cx
,
ay
,
cy
)
/
det
;
}
/*
* https://stackoverflow.com/questions/22791951/algorithm-to-find-an-arc-its-center-radius-and-angles-given-3-points
* https://de.wikipedia.org/wiki/Cramersche_Regel
* https://de.wikipedia.org/wiki/Determinante
*/
//TODO seperate radius from this function
circle
circleFrom3Points
(
vertex
v1
,
vertex
v2
,
vertex
v3
)
{
circle
c
;
circleCenter
(
&
v1
,
&
v2
,
&
v3
,
&
c
.
center
);
c
.
radius
=
sqrt
((
v1
.
x
-
c
.
center
.
x
)
*
(
v1
.
x
-
c
.
center
.
x
)
+
(
v1
.
y
-
c
.
center
.
y
)
*
(
v1
.
y
-
c
.
center
.
y
));
c
.
radius
=
distanceSquared
((
v1
),(
c
.
center
));
return
c
;
}
/*void reportTriangle(struct Triangle triangle) {
printf("%f, %f - %f, %f - %f, %f\n", triangle.a.x, triangle.a.y, triangle.b.x, triangle.b.y, triangle.c.x, triangle.c.y);
}*/
void
printPoint
(
vertex
point
)
{
//printf("%f, %f\n", point.x, point.y);
}
double
calcArea
(
vertex
p
,
vertex
q
,
vertex
r
)
{
//return 0.5*(-q.x*p.y+r.x*p.y+p.x*q.y-r.x*q.y-p.x*r.y+q.x*r.y);
return
0
.
5
*
(
p
.
x
*
(
q
.
y
-
r
.
y
)
-
p
.
y
*
(
q
.
x
-
r
.
x
)
+
(
q
.
x
*
r
.
y
-
q
.
y
*
r
.
x
));
}
/**
*
...
...
@@ -141,8 +66,8 @@ double distance(vertex p1, vertex p2) {
return
hypot
(
p1
.
x
-
p2
.
x
,
p1
.
y
-
p2
.
y
);
}
//https://math.stackexchange.com/questions/1232773/is-the-point-on-the-left-or-the-right-of-the-vector-in-2d-space
//https://betterexplained.com/articles/cross-product/
/**
*
* @param p
...
...
@@ -172,8 +97,6 @@ vertex vector(vertex a, vertex b) {
}
/**
* law of cosines https://www.mathsisfun.com/algebra/trig-cosine-law.html
* other solutions https://stackoverflow.com/questions/1211212/how-to-calculate-an-angle-from-three-points
* @param q
* @param p
* @param r
...
...
@@ -191,15 +114,15 @@ int firstDelaunayEdgeIncidentTo(int j, vertex* S, int size) {
double
minDist
,
dist
;
if
(
j
!=
0
)
{
k
=
0
;
minDist
=
distance
(
S
[
j
],
S
[
0
]);
minDist
=
distance
Squared
(
S
[
j
],
S
[
0
]);
}
else
/*if(j != 1)*/
{
k
=
1
;
minDist
=
distance
(
S
[
j
],
S
[
1
]);
minDist
=
distance
Squared
(
S
[
j
],
S
[
1
]);
}
//TODO erst bei j anfangen? problem: es ist nicht unbedingt die kleinste seite, wenn wir spaeter anfangen
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
if
(
j
!=
i
)
{
dist
=
distance
(
S
[
j
],
S
[
i
]);
dist
=
distance
Squared
(
S
[
j
],
S
[
i
]);
if
(
dist
<
minDist
)
{
k
=
i
;
minDist
=
dist
;
...
...
@@ -209,14 +132,6 @@ int firstDelaunayEdgeIncidentTo(int j, vertex* S, int size) {
return
k
;
}
int
arrayContains
(
int
*
jAlreadyUsed
,
int
numberOfJ
,
int
j
){
for
(
int
i
=
0
;
i
<
numberOfJ
;
i
++
)
{
if
(
jAlreadyUsed
[
i
]
==
j
)
{
return
1
;
}
}
return
0
;
}
void
clockwiseNextDelaunayEdge
(
const
int
*
p
,
const
int
*
q
,
int
*
r
,
const
vertex
*
S
,
const
int
*
size
,
int
*
right
)
{
//0: r not initialized, 1: r is left, 2: r is right
...
...
@@ -238,7 +153,7 @@ void clockwiseNextDelaunayEdge(const int *p, const int *q, int *r, const vertex
c
=
circleFrom3Points
(
S
[
*
p
],
S
[
*
q
],
S
[
*
r
]);
}
else
{
//if inside circle: calculate new circle, else: do nothing
if
(
distance
(
c
.
center
,
S
[
i
])
<
c
.
radius
)
{
if
(
distance
Squared
(
c
.
center
,
S
[
i
])
<
c
.
radius
)
{
*
r
=
i
;
c
=
circleFrom3Points
(
S
[
*
p
],
S
[
*
q
],
S
[
*
r
]);
}
...
...
@@ -289,11 +204,3 @@ void delaunayCws(vertex* S, int size) {
}
}
//https://stackoverflow.com/questions/29762048/c-structure-to-string
char
*
vertexToString
(
vertex
v
)
{
int
len
=
0
;
len
=
snprintf
(
NULL
,
len
,
"%f,%f"
,
v
.
x
,
v
.
y
);
char
*
str
=
malloc
(
sizeof
(
char
)
*
len
+
1
);
snprintf
(
str
,
sizeof
(
str
),
"%f,%f"
,
v
.
x
,
v
.
y
);
return
str
;
}
This diff is collapsed.
Click to expand it.
src/delaunay.h
+
0
−
1
View file @
eb3c9dca
...
...
@@ -18,7 +18,6 @@
void
reportTriangle
(
vertex
,
vertex
,
vertex
);
circle
circle_vvv
(
vertex
,
vertex
,
vertex
);
vertex
vector
(
vertex
,
vertex
);
double
distance
(
vertex
,
vertex
);
void
printPoint
(
vertex
);
...
...
This diff is collapsed.
Click to expand it.
src/helper.c
+
1
−
1
View file @
eb3c9dca
...
...
@@ -23,7 +23,7 @@ void svgDrawCircle(circle c) {
void
svgDrawTriangle
(
vertex
a
,
vertex
b
,
vertex
c
)
{
#ifdef OUTPUTFILE
fprintf
(
out
,
"<polygon vector-effect=
\"
non-scaling-stroke
\"
points=
\"
%f,%f %f,%f %f,%f
\"
style=
\"
fill:none;stroke:
black
;stroke-width:1
\"
/>
\n
"
,
a
.
x
,
a
.
y
,
b
.
x
,
b
.
y
,
c
.
x
,
c
.
y
);
fprintf
(
out
,
"<polygon vector-effect=
\"
non-scaling-stroke
\"
points=
\"
%f,%f %f,%f %f,%f
\"
style=
\"
fill:none;stroke:
red
;stroke-width:1
\"
/>
\n
"
,
a
.
x
,
a
.
y
,
b
.
x
,
b
.
y
,
c
.
x
,
c
.
y
);
#endif
}
...
...
This diff is collapsed.
Click to expand it.
src/helper.h
+
3
−
3
View file @
eb3c9dca
...
...
@@ -11,7 +11,7 @@
/**
* use if you want to have an output
*/
#define OUTPUTFILE "output.html"
//
#define OUTPUTFILE "output.html"
#include
<stdio.h>
...
...
@@ -22,8 +22,8 @@ double viewboxMinX;
double
viewboxMinY
;
double
viewboxMaxX
;
double
viewboxMaxY
;
#define W
4
00 //size of the svg-File
#define R
1.0
//Point size
#define W
10
00 //size of the svg-File
#define R
.2
//Point size
#endif
...
...
This diff is collapsed.
Click to expand it.
src/main.c
+
3
−
2
View file @
eb3c9dca
...
...
@@ -2,12 +2,13 @@
/**
* use if you want to use command line input
*/
#define INPUT
//
#define INPUT
/**
* used for doing the Runtimetest
*/
//#define RUNTIMETEST
#define RUNTIMETEST
/*
* main.c
*
...
...
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