Skip to content
Snippets Groups Projects
Commit de02a0d3 authored by mika's avatar mika
Browse files

improving circle

parent 8cde16f3
No related branches found
No related tags found
No related merge requests found
...@@ -89,6 +89,19 @@ double det2(double a, double b, double c, double d) { ...@@ -89,6 +89,19 @@ double det2(double a, double b, double c, double d) {
return a*d-b*c; 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://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/Cramersche_Regel
...@@ -97,15 +110,7 @@ double det2(double a, double b, double c, double d) { ...@@ -97,15 +110,7 @@ double det2(double a, double b, double c, double d) {
//TODO seperate radius from this function //TODO seperate radius from this function
circle circleFrom3Points(vertex v1, vertex v2, vertex v3) { circle circleFrom3Points(vertex v1, vertex v2, vertex v3) {
circle c; circle c;
double ax = 2*(v1.x-v2.x); circleCenter(&v1, &v2, &v3, &c.center);
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;
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 = sqrt((v1.x-c.center.x)*(v1.x-c.center.x)+(v1.y-c.center.y)*(v1.y-c.center.y));
return c; return c;
} }
......
...@@ -13,7 +13,7 @@ int main(int argc, char *argv[]) { ...@@ -13,7 +13,7 @@ int main(int argc, char *argv[]) {
//input: 1. function 0=cws_delaunay 2. # of points, 3. # of executions //input: 1. function 0=cws_delaunay 2. # of points, 3. # of executions
//create_image(); //create_image();
//write_ppm ( "sine.ppm" ); //write_ppm ( "sine.ppm" );
int numberOfPoints = 2000; int numberOfPoints = 10000;
int function = 0; int function = 0;
int executions = 1; int executions = 1;
if(argc > 0) { if(argc > 0) {
......
...@@ -83,7 +83,8 @@ void voronoiCws(vertex* S, int size) { ...@@ -83,7 +83,8 @@ void voronoiCws(vertex* S, int size) {
int isTriangle; int isTriangle;
clockwiseNextDelaunayEdge(&i, &j, &k, S, &size, &isTriangle); clockwiseNextDelaunayEdge(&i, &j, &k, S, &size, &isTriangle);
if(isTriangle == 2) { 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) { if(first) {
first = 0; first = 0;
firstV = currentV; firstV = currentV;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment