lib/toxi/geom/Polygon2D.js
function( x1, y1, x2, y2, x3, y3, distance, out ){
            var c1 = x2,
                d1 = y2,
                c2 = x2,
                d2 = y2;
            var dx1,
                dy1,
                dist1,
                dx2,
                dy2,
                dist2,
                insetX,
                insetY;

            dx1 = x2-x1;
            dy1 = y2-y1;
            dist1 = Math.sqrt(dx1*dx1 + dy1*dy1);
            dx2 = x3-x2;
            dy2 = y3-y2;
            dist2 = Math.sqrt(dx2*dx2 + dy2*dy2);

            if( dist1 < MathUtils.EPS || dist2 < MathUtils.EPS ){
                return;
            }

            dist1 = distance / dist1;
            dist2 = distance / dist2;

            insetX = dy1 * dist1;
            insetY = -dx1 * dist1;
            x1 += insetX;
            c1 += insetX;
            y1 += insetY;
            d1 += insetY;
            insetX = dy2 * dist2;
            insetY = -dx2 * dist2;
            x3 += insetX;
            c2 += insetX;
            y3 += insetY;
            d2 += insetY;

            if( c1 === c2 && d1 === d2 ){
                out.set(c1,d1);
                return;
            }

            var l1 = new Line2D( new Vec2D(x1,y1), new Vec2D(c1,d1) ),
                l2 = new Line2D( new Vec2D(c2,d2), new Vec2D(x3,y3) ),
                isec = l1.intersectLine(l2),
                ipos = isec.getPos();
            if( ipos !== null || ipos !== undefined ){
                out.set(ipos);
            }
        }
function( x1, y1, x2, y2, x3, y3, distance, out ){
            var c1 = x2,
                d1 = y2,
                c2 = x2,
                d2 = y2;
            var dx1,
                dy1,
                dist1,
                dx2,
                dy2,
                dist2,
                insetX,
                insetY;

            dx1 = x2-x1;
            dy1 = y2-y1;
            dist1 = Math.sqrt(dx1*dx1 + dy1*dy1);
            dx2 = x3-x2;
            dy2 = y3-y2;
            dist2 = Math.sqrt(dx2*dx2 + dy2*dy2);

            if( dist1 < MathUtils.EPS || dist2 < MathUtils.EPS ){
                return;
            }

            dist1 = distance / dist1;
            dist2 = distance / dist2;

            insetX = dy1 * dist1;
            insetY = -dx1 * dist1;
            x1 += insetX;
            c1 += insetX;
            y1 += insetY;
            d1 += insetY;
            insetX = dy2 * dist2;
            insetY = -dx2 * dist2;
            x3 += insetX;
            c2 += insetX;
            y3 += insetY;
            d2 += insetY;

            if( c1 === c2 && d1 === d2 ){
                out.set(c1,d1);
                return;
            }

            var l1 = new Line2D( new Vec2D(x1,y1), new Vec2D(c1,d1) ),
                l2 = new Line2D( new Vec2D(c2,d2), new Vec2D(x3,y3) ),
                isec = l1.intersectLine(l2),
                ipos = isec.getPos();
            if( ipos !== null || ipos !== undefined ){
                out.set(ipos);
            }
        }
function ( x1 , y1 , x2 , y2 , x3 , y3 , distance , out ) { var c1 = x2 , d1 = y2 , c2 = x2 , d2 = y2 ; var dx1 , dy1 , dist1 , dx2 , dy2 , dist2 , insetX , insetY ; dx1 = x2 - x1 ; dy1 = y2 - y1 ; dist1 = Math . sqrt ( dx1 * dx1 + dy1 * dy1 ) ; dx2 = x3 - x2 ; dy2 = y3 - y2 ; dist2 = Math . sqrt ( dx2 * dx2 + dy2 * dy2 ) ; if ( dist1 < MathUtils . EPS || dist2 < MathUtils . EPS ) { return ; } dist1 = distance / dist1 ; dist2 = distance / dist2 ; insetX = dy1 * dist1 ; insetY = - dx1 * dist1 ; x1 += insetX ; c1 += insetX ; y1 += insetY ; d1 += insetY ; insetX = dy2 * dist2 ; insetY = - dx2 * dist2 ; x3 += insetX ; c2 += insetX ; y3 += insetY ; d2 += insetY ; if ( c1 === c2 && d1 === d2 ) { out . set ( c1 , d1 ) ; return ; } var l1 = new Line2D ( new Vec2D ( x1 , y1 ) , new Vec2D ( c1 , d1 ) ) , l2 = new Line2D ( new Vec2D ( c2 , d2 ) , new Vec2D ( x3 , y3 ) ) , isec = l1 . intersectLine ( l2 ) , ipos = isec . getPos ( ) ; if ( ipos !== null || ipos !== undefined ) { out . set ( ipos ) ; } }
Given the sequentially connected points p1, p2, p3, this function returns
a bevel-offset replacement for point p2.

Note: If vectors p1->p2 and p2->p3 are exactly 180 degrees opposed, or if
either segment is zero then no offset will be applied.

@param x1
@param y1
@param x2
@param y2
@param x3
@param y3
@param distance
@param out

@see http://alienryderflex.com/polygon_inset/
Given the sequentially connected points p1 p2 p3 this function returns a bevel - offset replacement for point p2 .