Skip to content
Snippets Groups Projects
Commit 03d493f7 authored by bobarna's avatar bobarna
Browse files

not working circle calculation

parent a6617fc4
Branches
No related tags found
No related merge requests found
......@@ -185,17 +185,15 @@ public:
float r; //radius of the circle
Circle(vec2 p1, vec2 p2, vec2 p3) {
float m1 = (p2.y - p1.y) / (p2.x - p1.x);
float m2 = (p3.y - p2.y) / (p3.x - p2.x);
vec2 n12 = p2 - p1; //normal vector for perpendicular bisector of p1 and p2
float f12 = dot(n12,(p2+p1)/2);
float mf1 = -1 / m1;
float mf2 = -1 / m2;
vec2 n23 = p3 - p2; //normal vector for perpendicular bisector of p1 and p2
float f23 = dot(n23, (p2+p3)/2);
float cf1 = (p2.x * p2.x + p2.y * p2.y - p1.x * p1.x - p1.y * p1.y) / (2 * (p2.y - p1.y));
float cf2 = (p3.x * p3.x + p3.y * p3.y - p2.x * p2.x - p2.y * p2.y) / (2 * (p3.y - p2.y));
float cx = (cf2 - cf1) / (mf1 - mf2);
float cy = (mf1 * cf2 - mf2 * cf1) / (mf1 - mf2);
//coordinates for the circle's center
float cx = (f12*n23.y - f23*n12.y) / (n12.x*n23.y - n12.y*n23.x);
float cy = (f12/n12.y) - (n12.x/n12.y) * (f12*n23.y - n12.y*f23)/(n12.x*n23.y - n12.y*n23.x);
printf("%f %f\n", cx, cy);
c = vec2(cx, cy);
......@@ -227,7 +225,7 @@ public:
printf("%d\n", n);
if (n == 2) generateLineSegment(points[0], points[1]);
if (n == 3) generateLineSegment(points[1], points[2]);
// if(n == 3) circles.emplace_back(Circle(p, points[1].p, points[1].inversion()));
if (n == 3) generateLineSegment(points[2], points[0]);
}
void generateLineSegment(Point p1, Point p2) {
......@@ -297,7 +295,7 @@ public:
triangles[currTriangle].addPoint(p);
currPoints++;
if (currPoints == 3) currTriangle++, triangles.emplace_back(SiriusTriangle()), currPoints = 0;
if (currPoints == 3) currTriangle++, currPoints = 0;
}
void draw() {
......@@ -307,7 +305,6 @@ public:
};
BaseCircle baseCircle = BaseCircle::generate();
SiriusTriangleManager siriusTriangleManager = SiriusTriangleManager();
// Initialization, create an OpenGL context
......@@ -315,6 +312,9 @@ void onInitialization() {
glViewport(0, 0, windowWidth, windowHeight);
baseCircle.init();
siriusTriangleManager.addPoint(vec2(-0.6, 0.4));
siriusTriangleManager.addPoint(vec2(-0.8, 0.2));
siriusTriangleManager.addPoint(vec2(-0.2, -0.6));
// create program for the GPU
gpuProgram.create(vertexSource, fragmentSource, "outColor");
......@@ -382,10 +382,10 @@ void onMouse(int button, int state, int pX,
break;
}
siriusTriangleManager.addPoint(vec2(-.8f, -.4f));
siriusTriangleManager.addPoint(vec2(-.2f, -.6f));
siriusTriangleManager.addPoint(vec2(-.4f, .4f));
siriusTriangleManager.draw();
// siriusTriangleManager.addPoint(vec2(-.8f, -.4f));
// siriusTriangleManager.addPoint(vec2(-.2f, -.6f));
// siriusTriangleManager.addPoint(vec2(-.4f, .4f));
// siriusTriangleManager.draw();
if (state == GLUT_DOWN && button == GLUT_LEFT_BUTTON) {
siriusTriangleManager.addPoint(vec2(cX, cY));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment