# How to get intersections between a polygon and a straight line?

I want to get intersections between a blob’s outline and a line. I find that I can draw out the intersection of the blob’s outline and a very thin rectangle by doing this:

``````int num = contours.nBlobs;//get blob's contour points number

if(num>0){
npts=contours.blobs.nPts;

ofSetHexColor(0xb5de10);
ofPushMatrix();
ofSetPolyMode(OF_POLY_WINDING_ABS_GEQ_TWO);

//ofSetPolyMode(OF_POLY_WINDING_NONZERO);
ofBeginShape();
for(int i=0; i<npts; i++){     //draw the blobs
int x = contours.blobs.pts[i].x;
int y = contours.blobs.pts[i].y+500;
ofVertex(x,y);

}

ofNextContour(true);
ofVertex(w/2,h+500);   // a very thin rectangle
ofVertex(w/2+2,h+500);
ofVertex(w/2+2,h/2);
ofVertex(w/2,h/2);

ofEndShape(true);
ofPopMatrix();

}
``````

But still cannot get the upper intersection point and lower intersection point’s coordinates. Any one have an idea how to do that??
Thank so much.

There are a bunch of ways to do this. A few references:

Check out the `clipLineToPath` method. It takes a path and chops a line up based on intersections.
https://github.com/bakercp/ofxFont/blob/master/src/ofFrameSetter.cpp#L204

You might also check https://github.com/alexiswolfish/ofxSweepLine