Circle Problem

March 12th, 2012 experiment no comments

A friend left me this puzzle to solve.

Using openFrameworks here is a solution

ofEnableAlphaBlending();
ofBackground(255);
ofNoFill();

float   aRadius = 100;
ofVec2f a(ofGetWidth()/2, ofGetHeight()/2);
ofVec2f b, c;

// get two points along the circle a
b.x = a.x + cos(ofGetMouseNormal().x * TWO_PI) * aRadius;
b.y = a.y + sin(ofGetMouseNormal().x * TWO_PI) * aRadius;

c.x = a.x + cos(ofGetMouseNormal().y * TWO_PI) * aRadius;
c.y = a.y + sin(ofGetMouseNormal().y * TWO_PI) * aRadius;

ofSetHexColor(0xF52277);
ofCircle(a, aRadius);
ofCircle(a, 1);

ofFill();
ofSetHexColor(0x22A4F5);
ofCircle(b, 3);

ofSetHexColor(0xBCCC64);
ofCircle(c, 3);

// line from b -> c
ofSetColor(0, 30);
ofLine(b, c);

// get the perpendicular vectors from a -> c and a -> b
ofVec2f perpB = (a-b).perpendicular();
ofVec2f perpC = (a-c).perpendicular();

ofLine(b+(perpB*300), b-(perpB*300));
ofLine(c-(perpC*300), c+(perpC*300));

// now get the point where the two vectors intersect
ofVec2f pt1 = b-(perpB*200);  ofVec2f pt2 = b+(perpB*200);
ofVec2f pt3 = c-(perpC*200);  ofVec2f pt4 = c+(perpC*200);                                                  
ofVec2f intersectionPoint = GeometryUtils::getLineIntersection(pt1, pt2, pt3, pt4);

ofSetHexColor(0xF52277);
ofCircle(intersectionPoint, 3);

// get the distance from the new intersection
// point and the perp start point. this can be
// b or c
float intersectionRadius = b.distance(intersectionPoint);

ofSetHexColor(0xBCCC64);
ofNoFill();
ofCircle(intersectionPoint, intersectionRadius);

I have a few special function in there that I use you can grab them from my Tools on github. I am using this line intersection function GeometryUtils::getLineIntersection(…)

Say Something