Found a very old geometry book that had an algorithm for a line circle intersection, try the code below, the circle will be centred over the mouse position.
Code:float x1,y1,x2,y2,cx,cy,r;
boolean intersect;
void setup(){
size(200,300);
cx = width/2;
cy = height/2;
r = 20;
x1 = 50;
y1 = 50;
x2 = width - 60;
y2 = height - 60;
intersect = false;
}
void draw(){
background(255);
ellipseMode(CENTER);
strokeWeight(1);
stroke(0,255,0);
fill(255,240,240);
if(intersect)
stroke(255,0,0);
ellipse(cx,cy,2*r,2*r);
line(x1,y1,x2,y2);
cx = mouseX;
cy = mouseY;
intersect = line2Circle(x1,y1,x2,y2,cx,cy,r);
}
boolean line2Circle(float x0, float y0, float x1, float y1, float cx, float cy, float r){
float fxgy,t;
float f = (x1 - x0);
float g = (y1 - y0);
float f2 = f*f;
float g2 = g*g;
float fg2 = f2 + g2;
float r2 = r*r;
float xc0 = cx - x0;
float yc0 = cy - y0;
float xj1 = cx - x1;
float yj1 = cy - y1;
float fygx = f*yc0 - g*xc0;
float root = r*r*fg2 - fygx*fygx;
if(root >= 0){
fxgy = f*xc0 + g*yc0;
t = fxgy / fg2;
return ((t >= 0 && t <= 1) || (xc0*xc0 + yc0*yc0 < r2) || (xj1*xj1 + yj1*yj1 < r2) );
}
return false;
}
Of course you would repeat for each side of the triangle stopping if the function returns true. If all sides return false there is no intersection or the circle is inside the triangle!