From de02a0d31234490c656f95d1f50bf4dd74c96464 Mon Sep 17 00:00:00 2001
From: mika <mika@mika-ideacentre-Y710-Cube-15ISH>
Date: Wed, 5 Dec 2018 05:57:12 +0100
Subject: [PATCH] improving circle

---
 src/delaunay.c | 23 ++++++++++++++---------
 src/main.c     |  2 +-
 src/voronoi.c  |  3 ++-
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/delaunay.c b/src/delaunay.c
index fcdcca8..812294e 100644
--- a/src/delaunay.c
+++ b/src/delaunay.c
@@ -89,6 +89,19 @@ double det2(double a, double b, double c, double d) {
 	return a*d-b*c;
 }
 
+void circleCenter(const vertex* v1, const vertex* v2, const vertex* v3,
+		vertex* center) {
+	double ax = 2 * (v1->x - v2->x);
+	double bx = 2 * (v1->y - v2->y);
+	double cx = v1->x * v1->x - v2->x * v2->x + v1->y * v1->y - v2->y * v2->y;
+	double ay = 2 * (v1->x - v3->x);
+	double by = 2 * (v1->y - v3->y);
+	double cy = v1->x * v1->x - v3->x * v3->x + v1->y * v1->y - v3->y * v3->y;
+	double det = det2(ax, bx, ay, by);
+	center->x = det2(cx, bx, cy, by) / det;
+	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
@@ -97,15 +110,7 @@ double det2(double a, double b, double c, double d) {
 //TODO seperate radius from this function
 circle circleFrom3Points(vertex v1, vertex v2, vertex v3) {
 	circle c;
-	double ax = 2*(v1.x-v2.x);
-	double bx = 2*(v1.y-v2.y);
-	double cx = v1.x*v1.x - v2.x*v2.x + v1.y*v1.y - v2.y*v2.y;
-	double ay = 2*(v1.x-v3.x);
-	double by = 2*(v1.y-v3.y);
-	double cy = v1.x*v1.x - v3.x*v3.x + v1.y*v1.y - v3.y*v3.y;
-	double det = det2(ax, bx, ay, by);
-	c.center.x = det2(cx, bx, cy, by)/det;
-	c.center.y = det2(ax, cx, ay, cy)/det;
+	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));
 	return c;
 }
diff --git a/src/main.c b/src/main.c
index 845c941..4964086 100644
--- a/src/main.c
+++ b/src/main.c
@@ -13,7 +13,7 @@ int main(int argc, char *argv[]) {
 	//input: 1. function 0=cws_delaunay 2. # of points, 3. # of executions
     //create_image();
     //write_ppm ( "sine.ppm" );
-	int numberOfPoints = 2000;
+	int numberOfPoints = 10000;
 	int function = 0;
 	int executions = 1;
 	if(argc > 0) {
diff --git a/src/voronoi.c b/src/voronoi.c
index 250a769..15bafae 100644
--- a/src/voronoi.c
+++ b/src/voronoi.c
@@ -83,7 +83,8 @@ void voronoiCws(vertex* S, int size) {
 			int isTriangle;
 			clockwiseNextDelaunayEdge(&i, &j, &k, S, &size, &isTriangle);
 			if(isTriangle == 2) {
-				currentV = vertexCircle2vertex((vertexCircle){S[i], S[j], S[k]});
+				//currentV = vertexCircle2vertex((vertexCircle){S[i], S[j], S[k]});
+				circleCenter(S[i], S[j], S[k], currentV);
 				if(first) {
 					first = 0;
 					firstV = currentV;
-- 
GitLab