Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Convert path line to polyline?

Guest
Nov 12, 2010 Nov 12, 2010

Hello,

anyone here know it's it's possible to convert a path into a polyline?

I need to save SVG (but polyline, not path)

Many thanks!

r.

TOPICS
Scripting
4.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Contributor ,
Nov 12, 2010 Nov 12, 2010
LATEST

Hi

this is not the best way to do that, but all you need to do it better is inside this stuff (i hope).

have a look at the examples at the bottom.

cheers chris

//11:28 12.03.2010
//      www.ogebab.de
//-------------------------------------------
//Extension for Illustrator javascript (CS+)
/* ----------------------------------------------
------OBJ---- overview----------
----------------------------------------------
     Point()
          x, y
          many functions...

     Line()
          many functions...
     
     Bezier()
          A, B, C, D
          isLine()
          more functions...
     
     XpPoint()
          lDir, an, rDir | type: Point
          isCurvePoint()
     
     Xpath()
          pPoints |type: XpPoint
          beziers
          SetPath()
     
     Xitem()
          center
          setToCenter()
          ...
*/
//----------------------------------------------
//---------- little HELPERS----------------------
var fmm = 72 / 25.4;
// ---
function NumSort(a, b) {
     return a - b;
}
fibonacci = function(n) {
     return Math.round(Math.pow((Math.sqrt(5) + 1) / 2, Math.abs(n))
               / Math.sqrt(5))
               * (n < 0 && n % 2 ? -1 : 1);
};
function InVal(tx) {
     var inp, pt, t, num, d;
     inp = prompt(tx, "5");
     if (inp != "" && inp != null) {
          t = inp.search(",");
          if (t >= 0) {
               inp = inp.replace(",", ".");
          }
          t = inp.search("pt");
          if (t >= 0) {
               pt = 1;
               num = inp.slice(0, t);
          } else {
               t = inp.search("mm");
               if (t >= 0) {
                    pt = 0;
                    num = inp.slice(0, t);
               } else {
                    t = inp.search("in");
                    if (t >= 0) {
                         pt = 2;
                         num = inp.slice(0, t);
                    } else {
                         pt = 0;
                         num = inp;
                    }
               }
               d = eval(num);
               if (pt == 0) {
                    d = d * 72.0 / 25.4
               } else {
                    if (pt == 2) {
                         d = d * 72.0
                    }
               }
               return (d);
          }
          return (null);
     }
}
function InNum(tx, n) {
     var inp = prompt(tx, n), t = inp.search(",");
     if (t >= 0) {
          inp = inp.replace(",", ".");
     }
     return eval(inp);
}
function GetSelPaths() {
     var pf = app.activeDocument.pathItems, p = new Array();
     for ( var i68 = 0; i68 < pf.length; i68++) {
          if (pf[i68].selected == true) {
               p.push(pf[i68]);
          }
     }
     return p;
}
equate = function(a, b) {
     if (b >= 0)
          return a - b;
     return a + Math.abs(b)
};

Array.prototype.turn1 = function() {
     var a = this.shift();
     return this.push(a);
};
Array.prototype.insert = function(wert, stelle) {
     var a = this.slice(0, stelle), b = this.slice(stelle);
     b.unshift(wert);
     return (a.concat(b));
};

//--------------------------------------------------------------------------------------------------------------------------------------
//-----------------------OBJECTS---------------------------------------------------------------------------------------------------
////----------intersection section-----
//--------ignore it until you understand the rest
//--usage:       Var = new Intersection();
//--               Var.IfIntersect(bezier,bezier); > if bezier is a line(and you know that), use Line.intersect() instead
//--               returns Status and (if) Points/Vector2Ds
//--
//--- a tangent is not a intersection! similar points are SOMETIMES a intersection! ?
//--------KevLinDev.com--------*  copyright 2002-2003, Kevin Lindsey-----
Array.prototype.foreach=function(func){for(var i=0;i<this.length;i++)func(this);};
Array.prototype.map=function(func){var result=new Array();for(var i=0;i<this.length;i++)result.push(func(this));return result;};
Array.prototype.min=function(){var min=this[0];for(var i=0;i<this.length;i++)if(this<min)min=this;return min;}
Array.prototype.max=function(){var max=this[0];for(var i=0;i<this.length;i++)if(this>max)max=this;return max;}
Polynomial.TOLERANCE=1e-6;
Polynomial.ACCURACY=6;
function Polynomial(){this.init(arguments);}
Polynomial.prototype.init=function(coefs){this.coefs=new Array();for(var i=coefs.length-1;i>=0;i--)this.coefs.push(coefs);};
Polynomial.prototype.eval=function(x){var result=0;for(var i=this.coefs.length-1;i>=0;i--)result=result*x+this.coefs;return result;};
Polynomial.prototype.multiply=function(that){var result=new Polynomial();for(var i=0;i<=this.getDegree()+that.getDegree();i++)result.coefs.push(0);for(var i=0;i<=this.getDegree();i++)for(var j=0;j<=that.getDegree();j++)result.coefs[i+j]+=this.coefs*that.coefs;return result;};
Polynomial.prototype.divide_scalar=function(scalar){for(var i=0;i<this.coefs.length;i++)this.coefs/=scalar;};
Polynomial.prototype.simplify=function(){for(var i=this.getDegree();i>=0;i--){if(Math.abs(this.coefs)<=Polynomial.TOLERANCE)this.coefs.pop();else break;}};
Polynomial.prototype.bisection=function(min,max){var minValue=this.eval(min);var maxValue=this.eval(max);var result;if(Math.abs(minValue)<=Polynomial.TOLERANCE)result=min;else if(Math.abs(maxValue)<=Polynomial.TOLERANCE)result=max;else if(minValue*maxValue<=0){var tmp1=Math.log(max-min);var tmp2=Math.log(10)*Polynomial.ACCURACY;var iters=Math.ceil((tmp1+tmp2)/Math.log(2));for(var i=0;i<iters;i++){result=0.5*(min+max);var value=this.eval(result);if(Math.abs(value)<=Polynomial.TOLERANCE){break;}if(value*minValue<0){max=result;maxValue=value;}else{min=result;minValue=value;}}}return result;};
Polynomial.prototype.toString=function(){var coefs=new Array();var signs=new Array();for(var i=this.coefs.length-1;i>=0;i--){var value=this.coefs;if(value!=0){var sign=(value<0)?" - ":" + ";value=Math.abs(value);if(i>0)if(value==1)value="x";else value+="x";if(i>1)value+="^"+i;signs.push(sign);coefs.push(value);}}signs[0]=(signs[0]==" + ")?"":"-";var result="";for(var i=0;i<coefs.length;i++)result+=signs+coefs;return result;};
Polynomial.prototype.getDegree=function(){return this.coefs.length-1;};
Polynomial.prototype.getDerivative=function(){var derivative=new Polynomial();for(var i=1;i<this.coefs.length;i++){derivative.coefs.push(i*this.coefs);}return derivative;};
Polynomial.prototype.getRoots=function(){var result;this.simplify();switch(this.getDegree()){case 0:result=new Array();break;case 1:result=this.getLinearRoot();break;case 2:result=this.getQuadraticRoots();break;case 3:result=this.getCubicRoots();break;case 4:result=this.getQuarticRoots();break;default:result=new Array();}return result;};
Polynomial.prototype.getRootsInInterval=function(min,max){var roots=new Array();var root;if(this.getDegree()==1){root=this.bisection(min,max);if(root!=null)roots.push(root);}else{var deriv=this.getDerivative();var droots=deriv.getRootsInInterval(min,max);if(droots.length>0){root=this.bisection(min,droots[0]);if(root!=null)roots.push(root);for(var i=0;i<=droots.length-2;i++){root=this.bisection(droots,droots[i+1]);if(root!=null)roots.push(root);}root=this.bisection(droots[droots.length-1],max);if(root!=null)roots.push(root);}else{root=this.bisection(min,max);if(root!=null)roots.push(root);}}return roots;};
Polynomial.prototype.getLinearRoot=function(){var result=new Array();var a=this.coefs[1];if(a!=0)result.push(-this.coefs[0]/a);return result;};
Polynomial.prototype.getQuadraticRoots=function(){var results=new Array();if(this.getDegree()==2){var a=this.coefs[2];var b=this.coefs[1]/a;var c=this.coefs[0]/a;var d=b*b-4*c;if(d>0){var e=Math.sqrt(d);results.push(0.5*(-b+e));results.push(0.5*(-b-e));}else if(d==0){results.push(0.5*-b);}}return results;};
Polynomial.prototype.getCubicRoots=function(){var results=new Array();if(this.getDegree()==3){var c3=this.coefs[3];var c2=this.coefs[2]/c3;var c1=this.coefs[1]/c3;var c0=this.coefs[0]/c3;var a=(3*c1-c2*c2)/3;var b=(2*c2*c2*c2-9*c1*c2+27*c0)/27;var offset=c2/3;var discrim=b*b/4 + a*a*a/27;var halfB=b/2;if(Math.abs(discrim)<=Polynomial.TOLERANCE)disrim=0;if(discrim>0){var e=Math.sqrt(discrim);var tmp;var root;tmp=-halfB+e;if(tmp>=0)root=Math.pow(tmp,1/3);else root=-Math.pow(-tmp,1/3);tmp=-halfB-e;if(tmp>=0)root+=Math.pow(tmp,1/3);else root-=Math.pow(-tmp,1/3);results.push(root-offset);}else if(discrim<0){var distance=Math.sqrt(-a/3);var angle=Math.atan2(Math.sqrt(-discrim),-halfB)/3;var cos=Math.cos(angle);var sin=Math.sin(angle);var sqrt3=Math.sqrt(3);results.push(2*distance*cos-offset);results.push(-distance*(cos+sqrt3*sin)-offset);results.push(-distance*(cos-sqrt3*sin)-offset);}else{var tmp;if(halfB>=0)tmp=-Math.pow(halfB,1/3);else tmp=Math.pow(-halfB,1/3);results.push(2*tmp-offset);results.push(-tmp-offset);}}return results;};
Polynomial.prototype.getQuarticRoots=function(){var results=new Array();if(this.getDegree()==4){var c4=this.coefs[4];var c3=this.coefs[3]/c4;var c2=this.coefs[2]/c4;var c1=this.coefs[1]/c4;var c0=this.coefs[0]/c4;var resolveRoots=new Polynomial(1,-c2,c3*c1-4*c0,-c3*c3*c0+4*c2*c0-c1*c1).getCubicRoots();var y=resolveRoots[0];var discrim=c3*c3/4-c2+y;if(Math.abs(discrim)<=Polynomial.TOLERANCE)discrim=0;if(discrim>0){var e=Math.sqrt(discrim);var t1=3*c3*c3/4-e*e-2*c2;var t2=(4*c3*c2-8*c1-c3*c3*c3)/(4*e);var plus=t1+t2;var minus=t1-t2;if(Math.abs(plus)<=Polynomial.TOLERANCE)plus=0;if(Math.abs(minus)<=Polynomial.TOLERANCE)minus=0;if(plus>=0){var f=Math.sqrt(plus);results.push(-c3/4 + (e+f)/2);results.push(-c3/4 + (e-f)/2);}if(minus>=0){var f=Math.sqrt(minus);results.push(-c3/4 + (f-e)/2);results.push(-c3/4 - (f+e)/2);}}else if(discrim<0){}else{var t2=y*y-4*c0;if(t2>=-Polynomial.TOLERANCE){if(t2<0)t2=0;t2=2*Math.sqrt(t2);t1=3*c3*c3/4-2*c2;if(t1+t2>=Polynomial.TOLERANCE){var d=Math.sqrt(t1+t2);results.push(-c3/4 + d/2);results.push(-c3/4 - d/2);}if(t1-t2>=Polynomial.TOLERANCE){var d=Math.sqrt(t1-t2);results.push(-c3/4 + d/2);results.push(-c3/4 - d/2);}}}}return results;};
function Vector2D(x,y){if(arguments.length>0){this.init(x,y);}}
Vector2D.prototype.init=function(x,y){this.x=x;this.y=y;};
Vector2D.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y);};
Vector2D.prototype.dot=function(that){return this.x*that.x+this.y*that.y;};
Vector2D.prototype.cross=function(that){return this.x*that.y-this.y*that.x;}
Vector2D.prototype.unit=function(){return this.divide(this.length());};
Vector2D.prototype.unitEquals=function(){this.divideEquals(this.length());return this;};
Vector2D.prototype.add=function(that){return new Vector2D(this.x+that.x,this.y+that.y);};
Vector2D.prototype.addEquals=function(that){this.x+=that.x;this.y+=that.y;return this;};
Vector2D.prototype.subtract=function(that){return new Vector2D(this.x-that.x,this.y-that.y);};
Vector2D.prototype.subtractEquals=function(that){this.x-=that.x;this.y-=that.y;return this;};
Vector2D.prototype.multiply=function(scalar){return new Vector2D(this.x*scalar,this.y*scalar);};
Vector2D.prototype.multiplyEquals=function(scalar){this.x*=scalar;this.y*=scalar;return this;};
Vector2D.prototype.divide=function(scalar){return new Vector2D(this.x/ scalar, this.y /scalar);};
Vector2D.prototype.divideEquals=function(scalar){this.x/=scalar;this.y/=scalar;return this;};
Vector2D.prototype.perp=function(){return new Vector2D(-this.y,this.x);};
Vector2D.fromPoints=function(p1,p2){return new Vector2D(p2.x-p1.x,p2.y-p1.y);};
Vector2D.prototype.Dot=function (d){
     var ell=app.activeDocument.pathItems.ellipse(this.y + d/2 , this.x - d/2 ,d,d);
     ell.selected=false; return ell
};

function Intersection(status){if(arguments.length>0){this.init(status);}}
Intersection.prototype.init=function(status){this.status=status;this.points=new Array();};
Intersection.prototype.appendPoint=function(point){this.points.push(point);};
Intersection.prototype.appendPoints=function(points){this.points=this.points.concat(points);};
//-by ogebab---Gibt zurück: IntersectionObjekt (Obj.status / Obj.points / Obj.points.t1 / Obj.points.t2)
Intersection.prototype.IfInterSect=function(seg1,seg2){
     var result;
     if(seg1.type=="bez"){
          if(seg2.type=="line"){
               result=Intersection.intersectBezier3Line(seg1,seg2);
          }else{
               result=Intersection.intersectBezier3Bezier3(seg1,seg2);
          }
     }else{
          if(seg2.type=="bez"){
               result=Intersection.intersectBezier3Line(seg2,seg1);
          }else{
               result=Intersection.intersectLineLine(seg2,seg1);
          }
     }
     if(result.status=="Intersection"){
          for(var i=0;i<result.points.length ;i++){
               if(seg1.type=="line"){
                    result.points.t1=getTOfPointOnLine(result.points, seg1);
               }else{
                    result.points.t1=getTOfPointOnCubicCurve(result.points, seg1);
               }
               if(seg2.type=="line"){
                    result.points.t2=getTOfPointOnLine(result.points, seg2);
               }else{
                    result.points.t2=getTOfPointOnCubicCurve(result.points, seg2);
               }
          }
     }
     return result
};
//--(bez, bez)
Intersection.intersectBezier3Bezier3=function(seg1,seg2){var a,b,c,d;var c13,c12,c11,c10;var c23,c22,c21,c20;var result=new Intersection("No Intersection");a=seg1.A.multiply(-1);b=seg1.B.multiply(3);c=seg1.C.multiply(-3);d=a.add(b.add(c.add(seg1.D)));c13=new Vector2D(d.x,d.y);a=seg1.A.multiply(3);b=seg1.B.multiply(-6);c=seg1.C.multiply(3);d=a.add(b.add(c));c12=new Vector2D(d.x,d.y);a=seg1.A.multiply(-3);b=seg1.B.multiply(3);c=a.add(b);c11=new Vector2D(c.x,c.y);c10=new Vector2D(seg1.A.x,seg1.A.y);a=seg2.A.multiply(-1);b=seg2.B.multiply(3);c=seg2.C.multiply(-3);d=a.add(b.add(c.add(seg2.D)));c23=new Vector2D(d.x,d.y);a=seg2.A.multiply(3);b=seg2.B.multiply(-6);c=seg2.C.multiply(3);d=a.add(b.add(c));c22=new Vector2D(d.x,d.y);a=seg2.A.multiply(-3);b=seg2.B.multiply(3);c=a.add(b);c21=new Vector2D(c.x,c.y);c20=new Vector2D(seg2.A.x,seg2.A.y);var c10x2=c10.x*c10.x;var c10x3=c10.x*c10.x*c10.x;var c10y2=c10.y*c10.y;var c10y3=c10.y*c10.y*c10.y;var c11x2=c11.x*c11.x;var c11x3=c11.x*c11.x*c11.x;var c11y2=c11.y*c11.y;var c11y3=c11.y*c11.y*c11.y;var c12x2=c12.x*c12.x;var c12x3=c12.x*c12.x*c12.x;var c12y2=c12.y*c12.y;var c12y3=c12.y*c12.y*c12.y;var c13x2=c13.x*c13.x;var c13x3=c13.x*c13.x*c13.x;var c13y2=c13.y*c13.y;var c13y3=c13.y*c13.y*c13.y;var c20x2=c20.x*c20.x;var c20x3=c20.x*c20.x*c20.x;var c20y2=c20.y*c20.y;var c20y3=c20.y*c20.y*c20.y;var c21x2=c21.x*c21.x;var c21x3=c21.x*c21.x*c21.x;var c21y2=c21.y*c21.y;var c22x2=c22.x*c22.x;var c22x3=c22.x*c22.x*c22.x;var c22y2=c22.y*c22.y;var c23x2=c23.x*c23.x;var c23x3=c23.x*c23.x*c23.x;var c23y2=c23.y*c23.y;var c23y3=c23.y*c23.y*c23.y;var poly=new Polynomial(-c13x3*c23y3+c13y3*c23x3-3*c13.x*c13y2*c23x2*c23.y+3*c13x2*c13.y*c23.x*c23y2,-6*c13.x*c22.x*c13y2*c23.x*c23.y+6*c13x2*c13.y*c22.y*c23.x*c23.y+3*c22.x*c13y3*c23x2-3*c13x3*c22.y*c23y2-3*c13.x*c13y2*c22.y*c23x2+3*c13x2*c22.x*c13.y*c23y2,-6*c21.x*c13.x*c13y2*c23.x*c23.y-6*c13.x*c22.x*c13y2*c22.y*c23.x+6*c13x2*c22.x*c13.y*c22.y*c23.y+3*c21.x*c13y3*c23x2+3*c22x2*c13y3*c23.x+3*c21.x*c13x2*c13.y*c23y2-3*c13.x*c21.y*c13y2*c23x2-3*c13.x*c22x2*c13y2*c23.y+c13x2*c13.y*c23.x*(6*c21.y*c23.y+3*c22y2)+c13x3*(-c21.y*c23y2-2*c22y2*c23.y-c23.y*(2*c21.y*c23.y+c22y2)),c11.x*c12.y*c13.x*c13.y*c23.x*c23.y-c11.y*c12.x*c13.x*c13.y*c23.x*c23.y+6*c21.x*c22.x*c13y3*c23.x+3*c11.x*c12.x*c13.x*c13.y*c23y2+6*c10.x*c13.x*c13y2*c23.x*c23.y-3*c11.x*c12.x*c13y2*c23.x*c23.y-3*c11.y*c12.y*c13.x*c13.y*c23x2-6*c10.y*c13x2*c13.y*c23.x*c23.y-6*c20.x*c13.x*c13y2*c23.x*c23.y+3*c11.y*c12.y*c13x2*c23.x*c23.y-2*c12.x*c12y2*c13.x*c23.x*c23.y-6*c21.x*c13.x*c22.x*c13y2*c23.y-6*c21.x*c13.x*c13y2*c22.y*c23.x-6*c13.x*c21.y*c22.x*c13y2*c23.x+6*c21.x*c13x2*c13.y*c22.y*c23.y+2*c12x2*c12.y*c13.y*c23.x*c23.y+c22x3*c13y3-3*c10.x*c13y3*c23x2+3*c10.y*c13x3*c23y2+3*c20.x*c13y3*c23x2+c12y3*c13.x*c23x2-c12x3*c13.y*c23y2-3*c10.x*c13x2*c13.y*c23y2+3*c10.y*c13.x*c13y2*c23x2-2*c11.x*c12.y*c13x2*c23y2+c11.x*c12.y*c13y2*c23x2-c11.y*c12.x*c13x2*c23y2+2*c11.y*c12.x*c13y2*c23x2+3*c20.x*c13x2*c13.y*c23y2-c12.x*c12y2*c13.y*c23x2-3*c20.y*c13.x*c13y2*c23x2+c12x2*c12.y*c13.x*c23y2-3*c13.x*c22x2*c13y2*c22.y+c13x2*c13.y*c23.x*(6*c20.y*c23.y+6*c21.y*c22.y)+c13x2*c22.x*c13.y*(6*c21.y*c23.y+3*c22y2)+c13x3*(-2*c21.y*c22.y*c23.y-c20.y*c23y2-c22.y*(2*c21.y*c23.y+c22y2)-c23.y*(2*c20.y*c23.y+2*c21.y*c22.y)),6*c11.x*c12.x*c13.x*c13.y*c22.y*c23.y+c11.x*c12.y*c13.x*c22.x*c13.y*c23.y+c11.x*c12.y*c13.x*c13.y*c22.y*c23.x-c11.y*c12.x*c13.x*c22.x*c13.y*c23.y-c11.y*c12.x*c13.x*c13.y*c22.y*c23.x-6*c11.y*c12.y*c13.x*c22.x*c13.y*c23.x-6*c10.x*c22.x*c13y3*c23.x+6*c20.x*c22.x*c13y3*c23.x+6*c10.y*c13x3*c22.y*c23.y+2*c12y3*c13.x*c22.x*c23.x-2*c12x3*c13.y*c22.y*c23.y+6*c10.x*c13.x*c22.x*c13y2*c23.y+6*c10.x*c13.x*c13y2*c22.y*c23.x+6*c10.y*c13.x*c22.x*c13y2*c23.x-3*c11.x*c12.x*c22.x*c13y2*c23.y-3*c11.x*c12.x*c13y2*c22.y*c23.x+2*c11.x*c12.y*c22.x*c13y2*c23.x+4*c11.y*c12.x*c22.x*c13y2*c23.x-6*c10.x*c13x2*c13.y*c22.y*c23.y-6*c10.y*c13x2*c22.x*c13.y*c23.y-6*c10.y*c13x2*c13.y*c22.y*c23.x-4*c11.x*c12.y*c13x2*c22.y*c23.y-6*c20.x*c13.x*c22.x*c13y2*c23.y-6*c20.x*c13.x*c13y2*c22.y*c23.x-2*c11.y*c12.x*c13x2*c22.y*c23.y+3*c11.y*c12.y*c13x2*c22.x*c23.y+3*c11.y*c12.y*c13x2*c22.y*c23.x-2*c12.x*c12y2*c13.x*c22.x*c23.y-2*c12.x*c12y2*c13.x*c22.y*c23.x-2*c12.x*c12y2*c22.x*c13.y*c23.x-6*c20.y*c13.x*c22.x*c13y2*c23.x-6*c21.x*c13.x*c21.y*c13y2*c23.x-6*c21.x*c13.x*c22.x*c13y2*c22.y+6*c20.x*c13x2*c13.y*c22.y*c23.y+2*c12x2*c12.y*c13.x*c22.y*c23.y+2*c12x2*c12.y*c22.x*c13.y*c23.y+2*c12x2*c12.y*c13.y*c22.y*c23.x+3*c21.x*c22x2*c13y3+3*c21x2*c13y3*c23.x-3*c13.x*c21.y*c22x2*c13y2-3*c21x2*c13.x*c13y2*c23.y+c13x2*c22.x*c13.y*(6*c20.y*c23.y+6*c21.y*c22.y)+c13x2*c13.y*c23.x*(6*c20.y*c22.y+3*c21y2)+c21.x*c13x2*c13.y*(6*c21.y*c23.y+3*c22y2)+c13x3*(-2*c20.y*c22.y*c23.y-c23.y*(2*c20.y*c22.y+c21y2)-c21.y*(2*c21.y*c23.y+c22y2)-c22.y*(2*c20.y*c23.y+2*c21.y*c22.y)),c11.x*c21.x*c12.y*c13.x*c13.y*c23.y+c11.x*c12.y*c13.x*c21.y*c13.y*c23.x+c11.x*c12.y*c13.x*c22.x*c13.y*c22.y-c11.y*c12.x*c21.x*c13.x*c13.y*c23.y-c11.y*c12.x*c13.x*c21.y*c13.y*c23.x-c11.y*c12.x*c13.x*c22.x*c13.y*c22.y-6*c11.y*c21.x*c12.y*c13.x*c13.y*c23.x-6*c10.x*c21.x*c13y3*c23.x+6*c20.x*c21.x*c13y3*c23.x+2*c21.x*c12y3*c13.x*c23.x+6*c10.x*c21.x*c13.x*c13y2*c23.y+6*c10.x*c13.x*c21.y*c13y2*c23.x+6*c10.x*c13.x*c22.x*c13y2*c22.y+6*c10.y*c21.x*c13.x*c13y2*c23.x-3*c11.x*c12.x*c21.x*c13y2*c23.y-3*c11.x*c12.x*c21.y*c13y2*c23.x-3*c11.x*c12.x*c22.x*c13y2*c22.y+2*c11.x*c21.x*c12.y*c13y2*c23.x+4*c11.y*c12.x*c21.x*c13y2*c23.x-6*c10.y*c21.x*c13x2*c13.y*c23.y-6*c10.y*c13x2*c21.y*c13.y*c23.x-6*c10.y*c13x2*c22.x*c13.y*c22.y-6*c20.x*c21.x*c13.x*c13y2*c23.y-6*c20.x*c13.x*c21.y*c13y2*c23.x-6*c20.x*c13.x*c22.x*c13y2*c22.y+3*c11.y*c21.x*c12.y*c13x2*c23.y-3*c11.y*c12.y*c13.x*c22x2*c13.y+3*c11.y*c12.y*c13x2*c21.y*c23.x+3*c11.y*c12.y*c13x2*c22.x*c22.y-2*c12.x*c21.x*c12y2*c13.x*c23.y-2*c12.x*c21.x*c12y2*c13.y*c23.x-2*c12.x*c12y2*c13.x*c21.y*c23.x-2*c12.x*c12y2*c13.x*c22.x*c22.y-6*c20.y*c21.x*c13.x*c13y2*c23.x-6*c21.x*c13.x*c21.y*c22.x*c13y2+6*c20.y*c13x2*c21.y*c13.y*c23.x+2*c12x2*c21.x*c12.y*c13.y*c23.y+2*c12x2*c12.y*c21.y*c13.y*c23.x+2*c12x2*c12.y*c22.x*c13.y*c22.y-3*c10.x*c22x2*c13y3+3*c20.x*c22x2*c13y3+3*c21x2*c22.x*c13y3+c12y3*c13.x*c22x2+3*c10.y*c13.x*c22x2*c13y2+c11.x*c12.y*c22x2*c13y2+2*c11.y*c12.x*c22x2*c13y2-c12.x*c12y2*c22x2*c13.y-3*c20.y*c13.x*c22x2*c13y2-3*c21x2*c13.x*c13y2*c22.y+c12x2*c12.y*c13.x*(2*c21.y*c23.y+c22y2)+c11.x*c12.x*c13.x*c13.y*(6*c21.y*c23.y+3*c22y2)+c21.x*c13x2*c13.y*(6*c20.y*c23.y+6*c21.y*c22.y)+c12x3*c13.y*(-2*c21.y*c23.y-c22y2)+c10.y*c13x3*(6*c21.y*c23.y+3*c22y2)+c11.y*c12.x*c13x2*(-2*c21.y*c23.y-c22y2)+c11.x*c12.y*c13x2*(-4*c21.y*c23.y-2*c22y2)+c10.x*c13x2*c13.y*(-6*c21.y*c23.y-3*c22y2)+c13x2*c22.x*c13.y*(6*c20.y*c22.y+3*c21y2)+c20.x*c13x2*c13.y*(6*c21.y*c23.y+3*c22y2)+c13x3*(-2*c20.y*c21.y*c23.y-c22.y*(2*c20.y*c22.y+c21y2)-c20.y*(2*c21.y*c23.y+c22y2)-c21.y*(2*c20.y*c23.y+2*c21.y*c22.y)),-c10.x*c11.x*c12.y*c13.x*c13.y*c23.y+c10.x*c11.y*c12.x*c13.x*c13.y*c23.y+6*c10.x*c11.y*c12.y*c13.x*c13.y*c23.x-6*c10.y*c11.x*c12.x*c13.x*c13.y*c23.y-c10.y*c11.x*c12.y*c13.x*c13.y*c23.x+c10.y*c11.y*c12.x*c13.x*c13.y*c23.x+c11.x*c11.y*c12.x*c12.y*c13.x*c23.y-c11.x*c11.y*c12.x*c12.y*c13.y*c23.x+c11.x*c20.x*c12.y*c13.x*c13.y*c23.y+c11.x*c20.y*c12.y*c13.x*c13.y*c23.x+c11.x*c21.x*c12.y*c13.x*c13.y*c22.y+c11.x*c12.y*c13.x*c21.y*c22.x*c13.y-c20.x*c11.y*c12.x*c13.x*c13.y*c23.y-6*c20.x*c11.y*c12.y*c13.x*c13.y*c23.x-c11.y*c12.x*c20.y*c13.x*c13.y*c23.x-c11.y*c12.x*c21.x*c13.x*c13.y*c22.y-c11.y*c12.x*c13.x*c21.y*c22.x*c13.y-6*c11.y*c21.x*c12.y*c13.x*c22.x*c13.y-6*c10.x*c20.x*c13y3*c23.x-6*c10.x*c21.x*c22.x*c13y3-2*c10.x*c12y3*c13.x*c23.x+6*c20.x*c21.x*c22.x*c13y3+2*c20.x*c12y3*c13.x*c23.x+2*c21.x*c12y3*c13.x*c22.x+2*c10.y*c12x3*c13.y*c23.y-6*c10.x*c10.y*c13.x*c13y2*c23.x+3*c10.x*c11.x*c12.x*c13y2*c23.y-2*c10.x*c11.x*c12.y*c13y2*c23.x-4*c10.x*c11.y*c12.x*c13y2*c23.x+3*c10.y*c11.x*c12.x*c13y2*c23.x+6*c10.x*c10.y*c13x2*c13.y*c23.y+6*c10.x*c20.x*c13.x*c13y2*c23.y-3*c10.x*c11.y*c12.y*c13x2*c23.y+2*c10.x*c12.x*c12y2*c13.x*c23.y+2*c10.x*c12.x*c12y2*c13.y*c23.x+6*c10.x*c20.y*c13.x*c13y2*c23.x+6*c10.x*c21.x*c13.x*c13y2*c22.y+6*c10.x*c13.x*c21.y*c22.x*c13y2+4*c10.y*c11.x*c12.y*c13x2*c23.y+6*c10.y*c20.x*c13.x*c13y2*c23.x+2*c10.y*c11.y*c12.x*c13x2*c23.y-3*c10.y*c11.y*c12.y*c13x2*c23.x+2*c10.y*c12.x*c12y2*c13.x*c23.x+6*c10.y*c21.x*c13.x*c22.x*c13y2-3*c11.x*c20.x*c12.x*c13y2*c23.y+2*c11.x*c20.x*c12.y*c13y2*c23.x+c11.x*c11.y*c12y2*c13.x*c23.x-3*c11.x*c12.x*c20.y*c13y2*c23.x-3*c11.x*c12.x*c21.x*c13y2*c22.y-3*c11.x*c12.x*c21.y*c22.x*c13y2+2*c11.x*c21.x*c12.y*c22.x*c13y2+4*c20.x*c11.y*c12.x*c13y2*c23.x+4*c11.y*c12.x*c21.x*c22.x*c13y2-2*c10.x*c12x2*c12.y*c13.y*c23.y-6*c10.y*c20.x*c13x2*c13.y*c23.y-6*c10.y*c20.y*c13x2*c13.y*c23.x-6*c10.y*c21.x*c13x2*c13.y*c22.y-2*c10.y*c12x2*c12.y*c13.x*c23.y-2*c10.y*c12x2*c12.y*c13.y*c23.x-6*c10.y*c13x2*c21.y*c22.x*c13.y-c11.x*c11.y*c12x2*c13.y*c23.y-2*c11.x*c11y2*c13.x*c13.y*c23.x+3*c20.x*c11.y*c12.y*c13x2*c23.y-2*c20.x*c12.x*c12y2*c13.x*c23.y-2*c20.x*c12.x*c12y2*c13.y*c23.x-6*c20.x*c20.y*c13.x*c13y2*c23.x-6*c20.x*c21.x*c13.x*c13y2*c22.y-6*c20.x*c13.x*c21.y*c22.x*c13y2+3*c11.y*c20.y*c12.y*c13x2*c23.x+3*c11.y*c21.x*c12.y*c13x2*c22.y+3*c11.y*c12.y*c13x2*c21.y*c22.x-2*c12.x*c20.y*c12y2*c13.x*c23.x-2*c12.x*c21.x*c12y2*c13.x*c22.y-2*c12.x*c21.x*c12y2*c22.x*c13.y-2*c12.x*c12y2*c13.x*c21.y*c22.x-6*c20.y*c21.x*c13.x*c22.x*c13y2-c11y2*c12.x*c12.y*c13.x*c23.x+2*c20.x*c12x2*c12.y*c13.y*c23.y+6*c20.y*c13x2*c21.y*c22.x*c13.y+2*c11x2*c11.y*c13.x*c13.y*c23.y+c11x2*c12.x*c12.y*c13.y*c23.y+2*c12x2*c20.y*c12.y*c13.y*c23.x+2*c12x2*c21.x*c12.y*c13.y*c22.y+2*c12x2*c12.y*c21.y*c22.x*c13.y+c21x3*c13y3+3*c10x2*c13y3*c23.x-3*c10y2*c13x3*c23.y+3*c20x2*c13y3*c23.x+c11y3*c13x2*c23.x-c11x3*c13y2*c23.y-c11.x*c11y2*c13x2*c23.y+c11x2*c11.y*c13y2*c23.x-3*c10x2*c13.x*c13y2*c23.y+3*c10y2*c13x2*c13.y*c23.x-c11x2*c12y2*c13.x*c23.y+c11y2*c12x2*c13.y*c23.x-3*c21x2*c13.x*c21.y*c13y2-3*c20x2*c13.x*c13y2*c23.y+3*c20y2*c13x2*c13.y*c23.x+c11.x*c12.x*c13.x*c13.y*(6*c20.y*c23.y+6*c21.y*c22.y)+c12x3*c13.y*(-2*c20.y*c23.y-2*c21.y*c22.y)+c10.y*c13x3*(6*c20.y*c23.y+6*c21.y*c22.y)+c11.y*c12.x*c13x2*(-2*c20.y*c23.y-2*c21.y*c22.y)+c12x2*c12.y*c13.x*(2*c20.y*c23.y+2*c21.y*c22.y)+c11.x*c12.y*c13x2*(-4*c20.y*c23.y-4*c21.y*c22.y)+c10.x*c13x2*c13.y*(-6*c20.y*c23.y-6*c21.y*c22.y)+c20.x*c13x2*c13.y*(6*c20.y*c23.y+6*c21.y*c22.y)+c21.x*c13x2*c13.y*(6*c20.y*c22.y+3*c21y2)+c13x3*(-2*c20.y*c21.y*c22.y-c20y2*c23.y-c21.y*(2*c20.y*c22.y+c21y2)-c20.y*(2*c20.y*c23.y+2*c21.y*c22.y)),-c10.x*c11.x*c12.y*c13.x*c13.y*c22.y+c10.x*c11.y*c12.x*c13.x*c13.y*c22.y+6*c10.x*c11.y*c12.y*c13.x*c22.x*c13.y-6*c10.y*c11.x*c12.x*c13.x*c13.y*c22.y-c10.y*c11.x*c12.y*c13.x*c22.x*c13.y+c10.y*c11.y*c12.x*c13.x*c22.x*c13.y+c11.x*c11.y*c12.x*c12.y*c13.x*c22.y-c11.x*c11.y*c12.x*c12.y*c22.x*c13.y+c11.x*c20.x*c12.y*c13.x*c13.y*c22.y+c11.x*c20.y*c12.y*c13.x*c22.x*c13.y+c11.x*c21.x*c12.y*c13.x*c21.y*c13.y-c20.x*c11.y*c12.x*c13.x*c13.y*c22.y-6*c20.x*c11.y*c12.y*c13.x*c22.x*c13.y-c11.y*c12.x*c20.y*c13.x*c22.x*c13.y-c11.y*c12.x*c21.x*c13.x*c21.y*c13.y-6*c10.x*c20.x*c22.x*c13y3-2*c10.x*c12y3*c13.x*c22.x+2*c20.x*c12y3*c13.x*c22.x+2*c10.y*c12x3*c13.y*c22.y-6*c10.x*c10.y*c13.x*c22.x*c13y2+3*c10.x*c11.x*c12.x*c13y2*c22.y-2*c10.x*c11.x*c12.y*c22.x*c13y2-4*c10.x*c11.y*c12.x*c22.x*c13y2+3*c10.y*c11.x*c12.x*c22.x*c13y2+6*c10.x*c10.y*c13x2*c13.y*c22.y+6*c10.x*c20.x*c13.x*c13y2*c22.y-3*c10.x*c11.y*c12.y*c13x2*c22.y+2*c10.x*c12.x*c12y2*c13.x*c22.y+2*c10.x*c12.x*c12y2*c22.x*c13.y+6*c10.x*c20.y*c13.x*c22.x*c13y2+6*c10.x*c21.x*c13.x*c21.y*c13y2+4*c10.y*c11.x*c12.y*c13x2*c22.y+6*c10.y*c20.x*c13.x*c22.x*c13y2+2*c10.y*c11.y*c12.x*c13x2*c22.y-3*c10.y*c11.y*c12.y*c13x2*c22.x+2*c10.y*c12.x*c12y2*c13.x*c22.x-3*c11.x*c20.x*c12.x*c13y2*c22.y+2*c11.x*c20.x*c12.y*c22.x*c13y2+c11.x*c11.y*c12y2*c13.x*c22.x-3*c11.x*c12.x*c20.y*c22.x*c13y2-3*c11.x*c12.x*c21.x*c21.y*c13y2+4*c20.x*c11.y*c12.x*c22.x*c13y2-2*c10.x*c12x2*c12.y*c13.y*c22.y-6*c10.y*c20.x*c13x2*c13.y*c22.y-6*c10.y*c20.y*c13x2*c22.x*c13.y-6*c10.y*c21.x*c13x2*c21.y*c13.y-2*c10.y*c12x2*c12.y*c13.x*c22.y-2*c10.y*c12x2*c12.y*c22.x*c13.y-c11.x*c11.y*c12x2*c13.y*c22.y-2*c11.x*c11y2*c13.x*c22.x*c13.y+3*c20.x*c11.y*c12.y*c13x2*c22.y-2*c20.x*c12.x*c12y2*c13.x*c22.y-2*c20.x*c12.x*c12y2*c22.x*c13.y-6*c20.x*c20.y*c13.x*c22.x*c13y2-6*c20.x*c21.x*c13.x*c21.y*c13y2+3*c11.y*c20.y*c12.y*c13x2*c22.x+3*c11.y*c21.x*c12.y*c13x2*c21.y-2*c12.x*c20.y*c12y2*c13.x*c22.x-2*c12.x*c21.x*c12y2*c13.x*c21.y-c11y2*c12.x*c12.y*c13.x*c22.x+2*c20.x*c12x2*c12.y*c13.y*c22.y-3*c11.y*c21x2*c12.y*c13.x*c13.y+6*c20.y*c21.x*c13x2*c21.y*c13.y+2*c11x2*c11.y*c13.x*c13.y*c22.y+c11x2*c12.x*c12.y*c13.y*c22.y+2*c12x2*c20.y*c12.y*c22.x*c13.y+2*c12x2*c21.x*c12.y*c21.y*c13.y-3*c10.x*c21x2*c13y3+3*c20.x*c21x2*c13y3+3*c10x2*c22.x*c13y3-3*c10y2*c13x3*c22.y+3*c20x2*c22.x*c13y3+c21x2*c12y3*c13.x+c11y3*c13x2*c22.x-c11x3*c13y2*c22.y+3*c10.y*c21x2*c13.x*c13y2-c11.x*c11y2*c13x2*c22.y+c11.x*c21x2*c12.y*c13y2+2*c11.y*c12.x*c21x2*c13y2+c11x2*c11.y*c22.x*c13y2-c12.x*c21x2*c12y2*c13.y-3*c20.y*c21x2*c13.x*c13y2-3*c10x2*c13.x*c13y2*c22.y+3*c10y2*c13x2*c22.x*c13.y-c11x2*c12y2*c13.x*c22.y+c11y2*c12x2*c22.x*c13.y-3*c20x2*c13.x*c13y2*c22.y+3*c20y2*c13x2*c22.x*c13.y+c12x2*c12.y*c13.x*(2*c20.y*c22.y+c21y2)+c11.x*c12.x*c13.x*c13.y*(6*c20.y*c22.y+3*c21y2)+c12x3*c13.y*(-2*c20.y*c22.y-c21y2)+c10.y*c13x3*(6*c20.y*c22.y+3*c21y2)+c11.y*c12.x*c13x2*(-2*c20.y*c22.y-c21y2)+c11.x*c12.y*c13x2*(-4*c20.y*c22.y-2*c21y2)+c10.x*c13x2*c13.y*(-6*c20.y*c22.y-3*c21y2)+c20.x*c13x2*c13.y*(6*c20.y*c22.y+3*c21y2)+c13x3*(-2*c20.y*c21y2-c20y2*c22.y-c20.y*(2*c20.y*c22.y+c21y2)),-c10.x*c11.x*c12.y*c13.x*c21.y*c13.y+c10.x*c11.y*c12.x*c13.x*c21.y*c13.y+6*c10.x*c11.y*c21.x*c12.y*c13.x*c13.y-6*c10.y*c11.x*c12.x*c13.x*c21.y*c13.y-c10.y*c11.x*c21.x*c12.y*c13.x*c13.y+c10.y*c11.y*c12.x*c21.x*c13.x*c13.y-c11.x*c11.y*c12.x*c21.x*c12.y*c13.y+c11.x*c11.y*c12.x*c12.y*c13.x*c21.y+c11.x*c20.x*c12.y*c13.x*c21.y*c13.y+6*c11.x*c12.x*c20.y*c13.x*c21.y*c13.y+c11.x*c20.y*c21.x*c12.y*c13.x*c13.y-c20.x*c11.y*c12.x*c13.x*c21.y*c13.y-6*c20.x*c11.y*c21.x*c12.y*c13.x*c13.y-c11.y*c12.x*c20.y*c21.x*c13.x*c13.y-6*c10.x*c20.x*c21.x*c13y3-2*c10.x*c21.x*c12y3*c13.x+6*c10.y*c20.y*c13x3*c21.y+2*c20.x*c21.x*c12y3*c13.x+2*c10.y*c12x3*c21.y*c13.y-2*c12x3*c20.y*c21.y*c13.y-6*c10.x*c10.y*c21.x*c13.x*c13y2+3*c10.x*c11.x*c12.x*c21.y*c13y2-2*c10.x*c11.x*c21.x*c12.y*c13y2-4*c10.x*c11.y*c12.x*c21.x*c13y2+3*c10.y*c11.x*c12.x*c21.x*c13y2+6*c10.x*c10.y*c13x2*c21.y*c13.y+6*c10.x*c20.x*c13.x*c21.y*c13y2-3*c10.x*c11.y*c12.y*c13x2*c21.y+2*c10.x*c12.x*c21.x*c12y2*c13.y+2*c10.x*c12.x*c12y2*c13.x*c21.y+6*c10.x*c20.y*c21.x*c13.x*c13y2+4*c10.y*c11.x*c12.y*c13x2*c21.y+6*c10.y*c20.x*c21.x*c13.x*c13y2+2*c10.y*c11.y*c12.x*c13x2*c21.y-3*c10.y*c11.y*c21.x*c12.y*c13x2+2*c10.y*c12.x*c21.x*c12y2*c13.x-3*c11.x*c20.x*c12.x*c21.y*c13y2+2*c11.x*c20.x*c21.x*c12.y*c13y2+c11.x*c11.y*c21.x*c12y2*c13.x-3*c11.x*c12.x*c20.y*c21.x*c13y2+4*c20.x*c11.y*c12.x*c21.x*c13y2-6*c10.x*c20.y*c13x2*c21.y*c13.y-2*c10.x*c12x2*c12.y*c21.y*c13.y-6*c10.y*c20.x*c13x2*c21.y*c13.y-6*c10.y*c20.y*c21.x*c13x2*c13.y-2*c10.y*c12x2*c21.x*c12.y*c13.y-2*c10.y*c12x2*c12.y*c13.x*c21.y-c11.x*c11.y*c12x2*c21.y*c13.y-4*c11.x*c20.y*c12.y*c13x2*c21.y-2*c11.x*c11y2*c21.x*c13.x*c13.y+3*c20.x*c11.y*c12.y*c13x2*c21.y-2*c20.x*c12.x*c21.x*c12y2*c13.y-2*c20.x*c12.x*c12y2*c13.x*c21.y-6*c20.x*c20.y*c21.x*c13.x*c13y2-2*c11.y*c12.x*c20.y*c13x2*c21.y+3*c11.y*c20.y*c21.x*c12.y*c13x2-2*c12.x*c20.y*c21.x*c12y2*c13.x-c11y2*c12.x*c21.x*c12.y*c13.x+6*c20.x*c20.y*c13x2*c21.y*c13.y+2*c20.x*c12x2*c12.y*c21.y*c13.y+2*c11x2*c11.y*c13.x*c21.y*c13.y+c11x2*c12.x*c12.y*c21.y*c13.y+2*c12x2*c20.y*c21.x*c12.y*c13.y+2*c12x2*c20.y*c12.y*c13.x*c21.y+3*c10x2*c21.x*c13y3-3*c10y2*c13x3*c21.y+3*c20x2*c21.x*c13y3+c11y3*c21.x*c13x2-c11x3*c21.y*c13y2-3*c20y2*c13x3*c21.y-c11.x*c11y2*c13x2*c21.y+c11x2*c11.y*c21.x*c13y2-3*c10x2*c13.x*c21.y*c13y2+3*c10y2*c21.x*c13x2*c13.y-c11x2*c12y2*c13.x*c21.y+c11y2*c12x2*c21.x*c13.y-3*c20x2*c13.x*c21.y*c13y2+3*c20y2*c21.x*c13x2*c13.y,c10.x*c10.y*c11.x*c12.y*c13.x*c13.y-c10.x*c10.y*c11.y*c12.x*c13.x*c13.y+c10.x*c11.x*c11.y*c12.x*c12.y*c13.y-c10.y*c11.x*c11.y*c12.x*c12.y*c13.x-c10.x*c11.x*c20.y*c12.y*c13.x*c13.y+6*c10.x*c20.x*c11.y*c12.y*c13.x*c13.y+c10.x*c11.y*c12.x*c20.y*c13.x*c13.y-c10.y*c11.x*c20.x*c12.y*c13.x*c13.y-6*c10.y*c11.x*c12.x*c20.y*c13.x*c13.y+c10.y*c20.x*c11.y*c12.x*c13.x*c13.y-c11.x*c20.x*c11.y*c12.x*c12.y*c13.y+c11.x*c11.y*c12.x*c20.y*c12.y*c13.x+c11.x*c20.x*c20.y*c12.y*c13.x*c13.y-c20.x*c11.y*c12.x*c20.y*c13.x*c13.y-2*c10.x*c20.x*c12y3*c13.x+2*c10.y*c12x3*c20.y*c13.y-3*c10.x*c10.y*c11.x*c12.x*c13y2-6*c10.x*c10.y*c20.x*c13.x*c13y2+3*c10.x*c10.y*c11.y*c12.y*c13x2-2*c10.x*c10.y*c12.x*c12y2*c13.x-2*c10.x*c11.x*c20.x*c12.y*c13y2-c10.x*c11.x*c11.y*c12y2*c13.x+3*c10.x*c11.x*c12.x*c20.y*c13y2-4*c10.x*c20.x*c11.y*c12.x*c13y2+3*c10.y*c11.x*c20.x*c12.x*c13y2+6*c10.x*c10.y*c20.y*c13x2*c13.y+2*c10.x*c10.y*c12x2*c12.y*c13.y+2*c10.x*c11.x*c11y2*c13.x*c13.y+2*c10.x*c20.x*c12.x*c12y2*c13.y+6*c10.x*c20.x*c20.y*c13.x*c13y2-3*c10.x*c11.y*c20.y*c12.y*c13x2+2*c10.x*c12.x*c20.y*c12y2*c13.x+c10.x*c11y2*c12.x*c12.y*c13.x+c10.y*c11.x*c11.y*c12x2*c13.y+4*c10.y*c11.x*c20.y*c12.y*c13x2-3*c10.y*c20.x*c11.y*c12.y*c13x2+2*c10.y*c20.x*c12.x*c12y2*c13.x+2*c10.y*c11.y*c12.x*c20.y*c13x2+c11.x*c20.x*c11.y*c12y2*c13.x-3*c11.x*c20.x*c12.x*c20.y*c13y2-2*c10.x*c12x2*c20.y*c12.y*c13.y-6*c10.y*c20.x*c20.y*c13x2*c13.y-2*c10.y*c20.x*c12x2*c12.y*c13.y-2*c10.y*c11x2*c11.y*c13.x*c13.y-c10.y*c11x2*c12.x*c12.y*c13.y-2*c10.y*c12x2*c20.y*c12.y*c13.x-2*c11.x*c20.x*c11y2*c13.x*c13.y-c11.x*c11.y*c12x2*c20.y*c13.y+3*c20.x*c11.y*c20.y*c12.y*c13x2-2*c20.x*c12.x*c20.y*c12y2*c13.x-c20.x*c11y2*c12.x*c12.y*c13.x+3*c10y2*c11.x*c12.x*c13.x*c13.y+3*c11.x*c12.x*c20y2*c13.x*c13.y+2*c20.x*c12x2*c20.y*c12.y*c13.y-3*c10x2*c11.y*c12.y*c13.x*c13.y+2*c11x2*c11.y*c20.y*c13.x*c13.y+c11x2*c12.x*c20.y*c12.y*c13.y-3*c20x2*c11.y*c12.y*c13.x*c13.y-c10x3*c13y3+c10y3*c13x3+c20x3*c13y3-c20y3*c13x3-3*c10.x*c20x2*c13y3-c10.x*c11y3*c13x2+3*c10x2*c20.x*c13y3+c10.y*c11x3*c13y2+3*c10.y*c20y2*c13x3+c20.x*c11y3*c13x2+c10x2*c12y3*c13.x-3*c10y2*c20.y*c13x3-c10y2*c12x3*c13.y+c20x2*c12y3*c13.x-c11x3*c20.y*c13y2-c12x3*c20y2*c13.y-c10.x*c11x2*c11.y*c13y2+c10.y*c11.x*c11y2*c13x2-3*c10.x*c10y2*c13x2*c13.y-c10.x*c11y2*c12x2*c13.y+c10.y*c11x2*c12y2*c13.x-c11.x*c11y2*c20.y*c13x2+3*c10x2*c10.y*c13.x*c13y2+c10x2*c11.x*c12.y*c13y2+2*c10x2*c11.y*c12.x*c13y2-2*c10y2*c11.x*c12.y*c13x2-c10y2*c11.y*c12.x*c13x2+c11x2*c20.x*c11.y*c13y2-3*c10.x*c20y2*c13x2*c13.y+3*c10.y*c20x2*c13.x*c13y2+c11.x*c20x2*c12.y*c13y2-2*c11.x*c20y2*c12.y*c13x2+c20.x*c11y2*c12x2*c13.y-c11.y*c12.x*c20y2*c13x2-c10x2*c12.x*c12y2*c13.y-3*c10x2*c20.y*c13.x*c13y2+3*c10y2*c20.x*c13x2*c13.y+c10y2*c12x2*c12.y*c13.x-c11x2*c20.y*c12y2*c13.x+2*c20x2*c11.y*c12.x*c13y2+3*c20.x*c20y2*c13x2*c13.y-c20x2*c12.x*c12y2*c13.y-3*c20x2*c20.y*c13.x*c13y2+c12x2*c20y2*c12.y*c13.x);var roots=poly.getRootsInInterval(0,1);for(var i=0;i<roots.length;i++){var s=roots;var xRoots=new Polynomial(c13.x,c12.x,c11.x,c10.x-c20.x-s*c21.x-s*s*c22.x-s*s*s*c23.x).getRoots();var yRoots=new Polynomial(c13.y,c12.y,c11.y,c10.y-c20.y-s*c21.y-s*s*c22.y-s*s*s*c23.y).getRoots();if(xRoots.length>0&&yRoots.length>0){var TOLERANCE=1e-3;checkRoots:for(var j=0;j<xRoots.length;j++){var xRoot=xRoots;if(0<=xRoot&&xRoot<=1){for(var k=0;k<yRoots.length;k++){if(Math.abs(xRoot-yRoots)<TOLERANCE){result.points.push(c23.multiply(s*s*s).add(c22.multiply(s*s).add(c21.multiply(s).add(c20))));break checkRoots;}}}}}}if(result.points.length>0)result.status="Intersection";return result;};
//--(bez, line) erwartet trotzdem segment
Intersection.intersectBezier3Line=function(seg1,seg2){var a,b,c,d;var c3,c2,c1,c0;var cl;var n;var min=seg2.A.min(seg2.D);var max=seg2.A.max(seg2.D);var result=new Intersection("No Intersection");a=seg1.A.multiply(-1);b=seg1.B.multiply(3);c=seg1.C.multiply(-3);d=a.add(b.add(c.add(seg1.D)));c3=new Vector2D(d.x,d.y);a=seg1.A.multiply(3);b=seg1.B.multiply(-6);c=seg1.C.multiply(3);d=a.add(b.add(c));c2=new Vector2D(d.x,d.y);a=seg1.A.multiply(-3);b=seg1.B.multiply(3);c=a.add(b);c1=new Vector2D(c.x,c.y);c0=new Vector2D(seg1.A.x,seg1.A.y);n=new Vector2D(seg2.A.y-seg2.D.y,seg2.D.x-seg2.A.x);cl=seg2.A.x*seg2.D.y-seg2.D.x*seg2.A.y;roots=new Polynomial(n.dot(c3),n.dot(c2),n.dot(c1),n.dot(c0)+cl).getRoots();for(var i=0;i<roots.length;i++){var t=roots;if(0<=t&&t<=1){var p5=seg1.A.lerp(seg1.B,t);var p6=seg1.B.lerp(seg1.C,t);var p7=seg1.C.lerp(seg1.D,t);var p8=p5.lerp(p6,t);var p9=p6.lerp(p7,t);var pt10=p8.lerp(p9,t);if(seg2.A.x==seg2.D.x){if(min.y<=pt10.y&&pt10.y<=max.y){result.status="Intersection";result.appendPoint(pt10);}}else if(seg2.A.y==seg2.D.y){if(min.x<=pt10.x&&pt10.x<=max.x){result.status="Intersection";result.appendPoint(pt10);}}else if(pt10.gte(min)&&pt10.lte(max)){result.status="Intersection";result.appendPoint(pt10);}}}return result;};
//--(line, line) erwartet trotzdem segment
Intersection.intersectLineLine=function (seg1,seg2){var result;var ua_t=(seg2.D.x-seg2.A.x)*(seg1.A.y-seg2.A.y)-(seg2.D.y-seg2.A.y)*(seg1.A.x-seg2.A.x);var ub_t=(seg1.D.x-seg1.A.x)*(seg1.A.y-seg2.A.y)-(seg1.D.y-seg1.A.y)*(seg1.A.x-seg2.A.x);var u_b=(seg2.D.y-seg2.A.y)*(seg1.D.x-seg1.A.x)-(seg2.D.x-seg2.A.x)*(seg1.D.y-seg1.A.y);if(u_b!=0){var ua=ua_t/u_b;var ub=ub_t/u_b;if(0<=ua&&ua<=1&&0<=ub&&ub<=1){result=new Intersection("Intersection");result.points.push(new Point(seg1.A.x+ua*(seg1.D.x-seg1.A.x),seg1.A.y+ua*(seg1.D.y-seg1.A.y)));}else{result=new Intersection("No Intersection");}}else{if(ua_t==0||ub_t==0){result=new Intersection("Coincident");}else{result=new Intersection("Parallel");}}return result;};
//------------------------
Intersection.intersectBezier3Circle=function(p1,p2,p3,p4,c,r){return Intersection.intersectBezier3Ellipse(p1,p2,p3,p4,c,r,r);};
Intersection.intersectBezier3Ellipse=function(p1,p2,p3,p4,ec,rx,ry){var a,b,c,d;var c3,c2,c1,c0;var result=new Intersection("No Intersection");a=p1.multiply(-1);b=p2.multiply(3);c=p3.multiply(-3);d=a.add(b.add(c.add(p4)));c3=new Vector2D(d.x,d.y);a=p1.multiply(3);b=p2.multiply(-6);c=p3.multiply(3);d=a.add(b.add(c));c2=new Vector2D(d.x,d.y);a=p1.multiply(-3);b=p2.multiply(3);c=a.add(b);c1=new Vector2D(c.x,c.y);c0=new Vector2D(p1.x,p1.y);var rxrx=rx*rx;var ryry=ry*ry;var poly=new Polynomial(c3.x*c3.x*ryry+c3.y*c3.y*rxrx,2*(c3.x*c2.x*ryry+c3.y*c2.y*rxrx),2*(c3.x*c1.x*ryry+c3.y*c1.y*rxrx)+c2.x*c2.x*ryry+c2.y*c2.y*rxrx,2*c3.x*ryry*(c0.x-ec.x)+2*c3.y*rxrx*(c0.y-ec.y)+2*(c2.x*c1.x*ryry+c2.y*c1.y*rxrx),2*c2.x*ryry*(c0.x-ec.x)+2*c2.y*rxrx*(c0.y-ec.y)+c1.x*c1.x*ryry+c1.y*c1.y*rxrx,2*c1.x*ryry*(c0.x-ec.x)+2*c1.y*rxrx*(c0.y-ec.y),c0.x*c0.x*ryry-2*c0.y*ec.y*rxrx-2*c0.x*ec.x*ryry+c0.y*c0.y*rxrx+ec.x*ec.x*ryry+ec.y*ec.y*rxrx-rxrx*ryry);
var roots1=poly.getRootsInInterval(0,1);for(var i=0;i<roots1.length;i++){var t=roots1;result.points.push(c3.multiply(t*t*t).add(c2.multiply(t*t).add(c1.multiply(t).add(c0))));}if(result.points.length>0)result.status="Intersection";return result;};
Intersection.intersectLinePolygon=function(a1,a2,points){var result=new Intersection("No Intersection");var length=points.length;for(var i=0;i<length;i++){var b1=points;var b2=points[(i+1)%length];var inter=Intersection.intersectLineLine(a1,a2,b1,b2);result.appendPoints(inter.points);}if(result.points.length>0)result.status="Intersection";return result;};
Intersection.intersectPolygonPolygon=function(points1,points2){var result=new Intersection("No Intersection");var length=points1.length;for(var i=0;i<length;i++){var a1=points1;var a2=points1[(i+1)%length];var inter=Intersection.intersectLinePolygon(a1,a2,points2);result.appendPoints(inter.points);}if(result.points.length>0)result.status="Intersection";return result;};

//--------------by Andreas Weber-----------------------
function getTOfPointOnCubicCurve(p0, seg){return getTOfPoint.apply(this, arguments);}
function getTOfPoint(p0,seg){var p1=seg.A,p2=seg.B,p3=seg.C,p4=seg.D;var ax,bx,cx,dx,ay,by,cy,dy,xl,yl,i,j,k,len1,len2,len3,min,r,round,v;var p0x=p0.x,p0y=p0.y,p1x=p1.x,p1y=p1.y,p2x=p2.x,p2y=p2.y,p3x=p3.x,p3y=p3.y;round=10000;var p4x=p4.x,p4y=p4.y;ax=p4x-3*p3x+3*p2x-p1x;bx=3*p3x-6*p2x+3*p1x;cx=3*p2x-3*p1x;dx=p1x-p0x;ay=p4y-3*p3y+3*p2y-p1y;by=3*p3y-6*p2y+3*p1y;cy=3*p2y-3*p1y;dy=p1y-p0y;min=1/round;if(ax<min&&ax>0-min){ax=0} if(bx<min&&bx>0-min){bx=0} if(cx<min&&cx>0-min){cx=0} if(dx<min&&dx>0-min){dx=0} if(ay<min&&ay>0-min){ay=0} if(by<min&&by>0-min){by=0} if(cy<min&&cy>0-min){cy=0} if(dy<min&&dy>0-min){dy=0} xl=solveCubicPolynomial(ax,bx,cx,dx);yl=solveCubicPolynomial(ay,by,cy,dy);for(i=0,len1=xl.length;i<len1;i++){v=xl;if(v!='NAN'){xl=Math.round(v*round)/round;}v=xl;if(v<0||v>1){xl.splice(i,1);len1--;i--;}}for(i=0,len1=yl.length;i<len1;i++){v=yl;if(v!='NAN'){yl=Math.round(v*round)/round;}v=yl;if(v<0||v>1){yl.splice(i,1);len1--;i--;}}if(xl[0]=='NAN'){return yl;}else if(yl[0]=='NAN'){return xl;}else{r=new Array();len1=xl.length;len2=yl.length;for(i=0;i<len1;i++){for(j=0;j<len2;j++){if(xl==yl){for(k=0,len3;k<r.length;k++){if(r==xl){break;}}r.push(xl);yl.splice(j,1);len2--;}}}if(r.length>0){return r;} return[-1];}}

/*by Aless Lasaruk, adapted by Andreas Weber*/
function solveCubicPolynomial(a, b, c, d) { var p, q, di, pi; if(a==0){ if(b==0){ if(c==0 && d==0){ return ['NAN']; }else if(c != 0){ return [-d/c]; } }else{ di = c*c-4*b*d; if (di < 0){ return []; }else if(di==0) { return [-c/(2*b)]; }else{ return [(-c + Math.sqrt(di))/(2*b), (-c - Math.sqrt(di))/(2*b)]; } } } p = (3*a*c - b*b)/(3*a*a); q = (2*b*b*b-9*a*b*c+27*a*a*d)/(27*a*a*a); di = q*q/4+p*p*p/27; if(di > 0){ return [crt(-q/2+Math.sqrt(di))+crt(-q/2-Math.sqrt(di))-b/(3*a)]; }else if(di==0) { return [crt(q/2)-b/(3*a), -crt(4*q)-b/(3*a)]; }else{ pi = Math.PI; return [2*Math.sqrt(-p/3)*Math.cos(1/3*Math.acos(-q/2*Math.sqrt(-27/(p*p*p))))- b/(3*a), -2*Math.sqrt(-p/3)*Math.cos(1/3*Math.acos(-q/2*Math.sqrt(-27/(p*p*p)))+ pi/3) - b/(3*a), -2*Math.sqrt(-p/3)*Math.cos(1/3*Math.acos(-q/2*Math.sqrt(-27/(p*p*p)))- pi/3) - b/(3*a) ]; } }
function crt(x){return x<0 ? -Math.pow(-x,1/3) : Math.pow(x,1/3);}
//-----------------------------
function getTOfPointOnLine(pt, seg){return seg.A.distanceFrom(pt)/seg.A.distanceFrom(seg.D);}

////----------end of intersection

// POINT OBJ
// point und line: basiert auf code: written by Kevin Lindsey
// (kevin@kevlindev.com)
function Point(x, y) {
     this.name = "_point";
     if (arguments.length == 1) {
          this.x = x[0];
          this.y = x[1]
     }
     if (arguments.length == 2) {
          this.x = x;
          this.y = y
     }
     this.arr = [ this.x, this.y ];
}
Point.prototype.lerp = function(that, t) {
     return new Point(this.x + (that.x - this.x) * t, this.y + (that.y - this.y)
               * t);
};
Point.prototype.distanceFrom = function(that) {
     var dx = this.x - that.x;
     var dy = this.y - that.y;
     return Math.sqrt(dx * dx + dy * dy);
};
Point.prototype.angle = function(p2) {
     var w = Math.atan2(p2.y - this.y, p2.x - this.x) * 180 / Math.PI;
     if (w < 0) {
          w = w + 360
     }
     return w;
};
Point.prototype.plumb = function(lp1, lp2) {
     var x = this.x, y = this.y, x0 = lp1.x, y0 = lp1.y, x1 = lp2.x, y1 = lp2.y;
     if (!(x1 - x0))
          return new Point(x0, y);
     else if (!(y1 - y0))
          return new Point(x, y0);
     var left, tg = -1 / ((y1 - y0) / (x1 - x0));
     var o = {
          x : left = (x1 * (x * tg - y + y0) + x0 * (x * -tg + y - y1))
                    / (tg * (x1 - x0) + y0 - y1),
          y : tg * left - tg * x + y
     };
     return new Point(o.x, o.y);
};
Point.prototype.isInHull = function(hull) {// hull? handlungsbedarf
     // wenn hull=bezier
     if (hull.A) {
          hull.pPoints.push(hull.A);
          hull.pPoints.push(hull.B);
          hull.pPoints.push(hull.C);
          hull.pPoints.push(hull.D);
     }
     var w = new Array();
     for ( var i1 = 0; i1 < hull.pPoints.length; i1++) {
          w[i1] = this.angle(hull.pPoints[i1])
     }
     w.sort(NumSort);
     for ( var i = 0; i < w.length; i++) {
          if (i == 0) {
               if (w[0] + 360 - w[w.length - 1] > 180) {
                    return false
               }
          } else {
               if (w - w[i - 1] > 180) {
                    return false
               }
          }
     }
     return true
};
Point.prototype.Dot = function(d) {
     var ell = app.activeDocument.pathItems.ellipse(this.y + d / 2, this.x - d
               / 2, d, d);
     ell.selected = false;
     return ell
};
Point.prototype.Line = function(pt) {
     var list = [ [ this.x, this.y ], [ pt.x, pt.y ] ], line = app.activeDocument.pathItems
               .add();
     line.setEntirePath(list);
     return line
};
Point.prototype.add = function(that) {
     return new Point(this.x + that.x, this.y + that.y);
};
Point.prototype.addEquals = function(that) {
     this.x += that.x;
     this.y += that.y;
     return this;
};
Point.prototype.scalarAdd = function(scalar) {
     return new Point(this.x + scalar, this.y + scalar);
};
Point.prototype.scalarAddEquals = function(scalar) {
     this.x += scalar;
     this.y += scalar;
     return this;
};
Point.prototype.subtract = function(that) {
     return new Point(this.x - that.x, this.y - that.y);
};
Point.prototype.subtractEquals = function(that) {
     this.x -= that.x;
     this.y -= that.y;
     return this;
};
Point.prototype.scalarSubtract = function(scalar) {
     return new Point(this.x - scalar, this.y - scalar);
};
Point.prototype.scalarSubtractEquals = function(scalar) {
     this.x -= scalar;
     this.y -= scalar;
     return this;
};
Point.prototype.multiply = function(scalar) {
     return new Point(this.x * scalar, this.y * scalar);
};
Point.prototype.multiplyEquals = function(scalar) {
     this.x *= scalar;
     this.y *= scalar;
     return this;
};
Point.prototype.divide = function(scalar) {
     return new Point(this.x / scalar, this.y / scalar);
};
Point.prototype.divideEquals = function(scalar) {
     this.x /= scalar;
     this.y /= scalar;
     return this;
};
Point.prototype.eq = function(that) {
     return (this.x == that.x && this.y == that.y);
};
Point.prototype.lt = function(that) {
     return (this.x < that.x && this.y < that.y);
};
Point.prototype.lte = function(that) {
     return (this.x <= that.x && this.y <= that.y);
};
Point.prototype.gt = function(that) {
     return (this.x > that.x && this.y > that.y);
};
Point.prototype.gte = function(that) {
     return (this.x >= that.x && this.y >= that.y);
};
Point.prototype.min = function(that) {
     return new Point(Math.min(this.x, that.x), Math.min(this.y, that.y));
};
Point.prototype.max = function(that) {
     return new Point(Math.max(this.x, that.x), Math.max(this.y, that.y));
};
Point.prototype.toString = function() {
     return this.x + "," + this.y;
};
Point.prototype.setXY = function(x, y) {
     this.x = x;
     this.y = y;
};
Point.prototype.setFromPoint = function(that) {
     this.x = that.x;
     this.y = that.y;
};
Point.prototype.swap = function(that) {
     var x = this.x;
     var y = this.y;
     this.x = that.x;
     this.y = that.y;
     that.x = x;
     that.y = y;
};
// LINE OBJ
function Line(p1, p2) {
     this.p1 = p1;
     this.p2 = p2;
     this.type = this.type()
}
Line.prototype.type = function() {
     if (this.p1.x == this.p2.x) {
          return "vert"
     }
     if (this.p1.y == this.p2.y) {
          return "hori"
     }
     return "diag"
};
// Steigung
Line.prototype.slope = function() {
     var p = this.p2.subtract(this.p1);
     return p.y / p.x
};
Line.prototype.YatX0 = function() {
     return this.p1.y - this.slope() * this.p1.x
};
Line.prototype.isParallel = function(that) {
     if (this.type == "diag" && that.type == "diag") {
          if (this.slope() == that.slope()) {
               return true
          }
          return false
     }
     if (this.type == that.type)
          return true;
     return false
};
Line.prototype.intersect = function(that) {
     var a = this.type, b = that.type, x, y;
     if (this.isParallel(that) == false) {
          if (a == "hori") {
               y = this.p1.y;
               if (b == "vert")
                    return new Point(that.p1.x, y);
               if (b == "diag")
                    return new Point(equate(that.YatX0(), y)
                              / equate(this.slope(), that.slope()), y)
          }
          if (a == "vert") {
               x = this.p1.x;
               if (b == "hori")
                    return new Point(x, that.p1.y);
               if (b == "diag")
                    return new Point(x, that.slope() * x + that.YatX0())
          }
          if (a == "diag") {
               if (b == "hori") {
                    y = that.p1.y;
                    x = equate(y, this.YatX0())
                              / equate(this.slope(), that.slope());
                    return new Point(x, y)
               }
               if (b == "vert") {
                    x = that.p1.x;
                    y = this.slope() * x + this.YatX0();
                    return new Point(x, y)
               }
               if (b == "diag") {
                    x = equate(that.YatX0(), this.YatX0())
                              / equate(this.slope(), that.slope());
                    y = this.slope() * x + this.YatX0();
                    return new Point(x, y)
               }
          }
     }
     return "parallel"
};
Line.prototype.plumb = function(pt) { // lotrecht
     var x = pt.x, y = pt.y, x0 = this.p1.x, y0 = this.p1.y, x1 = this.p2.x, y1 = this.p2.y;
     if (!(x1 - x0))
          return new Point(x0, y);
     else if (!(y1 - y0))
          return new Point(x, y0);
     var left, tg = -1 / ((y1 - y0) / (x1 - x0));
     var o = {
          x : left = (x1 * (x * tg - y + y0) + x0 * (x * -tg + y - y1))
                    / (tg * (x1 - x0) + y0 - y1),
          y : tg * left - tg * x + y
     };
     return new Point(o.x, o.y);
};
Line.prototype.getT = function(pt) {
     return this.p1.distanceFrom(pt) / this.p1.distanceFrom(this.p2);
};
Line.prototype.hasPoint = function(pt) {
     var t = this.getT(pt);
     if (t < 0 || t > 1)
          return t;
     return t
};
// BEZIER OBJ
function Bezier(p1, p2) {
     this.name = "_bezier";
     this.A = p1.an;
     this.B = p1.rDir;
     this.C = p2.lDir;
     this.D = p2.an;
     this.type = this.isLine()
}
Bezier.prototype.isLine = function() {
     var self = this;
     if (self.A.x == self.B.x && self.A.y == self.B.y && self.D.x == self.C.x
               && self.D.y == self.C.y) {
          return "line"
     }
     return "bez"
};
Bezier.prototype.PointsForT = function(ti) {
     if (this.type == "bez") {
          this.BT = this.A.lerp(this.B, ti); // new B
          this.tt = this.B.lerp(this.C, ti); // ???
          this.CT = this.C.lerp(this.D, ti); // new C
          this.T1 = this.BT.lerp(this.tt, ti);// new point lDir
          this.T2 = this.tt.lerp(this.CT, ti);// new point rDir
          this.PP = this.T1.lerp(this.T2, ti);// new point an
          this.t = ti;
          this.normale = function() {
               var n = this.PP.subtract(this.T1), n2 = new Point(-n.y, n.x);
               return n2.add(this.PP);
          }
          // tangent is T1 or T2
          if (ti <= 0.001) {
               this.tang = this.T2.angle(this.PP)
          }
          if (ti >= 0.999) {
               this.tang = this.PP.angle(this.T1)
          }
          if (ti > 0.001 && ti < 0.999) {
               this.tang = this.T2.angle(this.T1)
          }
     }
     if (this.type == "line") {
          this.PP = this.A.lerp(this.D, ti);
          // return this
     }
     return this
};
Bezier.prototype.BezLength = function(tolerance) {
     var seelf = this, len1 = this.A.distanceFrom(this.D), len2 = 0, result = new Array(
               [ this.A, 0 ]);
     result.push( [ this.D, 1 ]);
     var ri = 1, s = 2, z = 0;
     romberg();
     function romberg() {
          z += 1;
          for (ri; ri < s; ri += 2) {
               var temp = seelf.PointsForT(ri / s);
               result = result.insert( [ temp.PP, temp.t ], ri);//
          }
          s = s * 2;
          ri = 1;
          for ( var j = 0; j < result.length; j++) {
               result[0][2] = len2;
               if (result[0][1] < 1) {
                    len2 += result[0][0].distanceFrom(result[1][0]);
               }
               result.turn1();
          }
     }
     while (len2 - len1 > tolerance || z < 5) { //
          len1 = len2;
          len2 = 0;
          romberg();
     }
     return {
          bezLength : len2,
          list : result
     };
     // return len2;
}
Bezier.prototype.getTonLength = function(le, tolerance) {
     try {
          var dat = this.BezLength(tolerance)
     } catch (e) {
          return "getLengthFail"
     }
     var lDiff; // var t;
     if (dat.bezLength < le) {
          le -= 0.0001
     }
     if (dat.bezLength < le) {
          alert("getTonLength_toShort \n  " + le + " " + dat.bezLength);
          return "toShort"
     }
     if (dat.bezLength == le)
          return 1;
     if (le == 0)
          return 0
          // if(dat.bezLength>le){alert("getTonLength_toLong \n "+le+"
          // "+dat.bezLength);return "toLong"}

          // if(dat.bezLength==le){le=le-0.1}
     for ( var i = 0; i < dat.list.length; i++) {
          if (dat.list[2] > le) {
               lDiff = (dat.list[2] - dat.list[i - 1][2])
                         / (le - dat.list[i - 1][2]);
               // alert();
               return dat.list[i - 1][1] + dat.list[1][1] / lDiff;
          }
     }
}
// EXTENDED PATHPOINT OBJ
function XpPoint(ld, an, rd) {
     if (arguments.length < 1)
          return null;
     this.name = "_pPoint";
     if (ld.anchor) { // illustrator pathPoint
          this.lDir = new Point(ld.leftDirection);
          this.an = new Point(ld.anchor);
          this.rDir = new Point(ld.rightDirection);
          this.type = ld.pointType;
     } else if (ld.an) { // pPoint
          this.lDir = ld.lDir;
          this.an = ld.an;
          this.rDir = ld.rDir;
          this.type = ld.type;
     } else if (ld.x) { // point('s)
          if (an)
               this.an = an
          else
               this.an = ld;
          this.lDir = ld;
          if (rd)
               this.rDir = rd
          else
               this.rDir = ld;
          // this.ai.type=
     }
}
// only useful for pathPoints on Beziers, not on rect or line or ....
XpPoint.prototype.isCurvePoint = function() {
     if ((Math.round((this.rDir.y - this.an.y) / (this.rDir.x - this.an.x)
               * 1000) == Math.round((this.lDir.y - this.an.y)
               / (this.lDir.x - this.an.x) * 1000))
               || (this.rDir.y == this.an.y && this.lDir.y == this.an.y)
               || (this.rDir.x == this.an.x && this.lDir.x == this.an.x)) {
          return true
     }
     return false
};

// EXTENDED PATH OBJ
Xpath.prototype = new Xitem();
Xpath.prototype.constructor = Xpath ;
function Xpath(pfad) {
     Xitem.call(this, pfad);

     this.name = "_Xpath";
     this.ai = pfad;
     if (pfad.pathPoints) {
          this.pPoints = new Array();
          this.pPoints.name = "_pPoints";
          for ( var i = 0; i < pfad.pathPoints.length; i++) {
               this.pPoints.push(new XpPoint(pfad.pathPoints))
          }
     }
     if (this.pPoints) {
          this.beziers = new Array();
          this.beziers.name = "_beziers";
          var i73 = 0, pts = this.pPoints;
          if (pfad.closed == false)
               i73++;
          for (i73; i73 < pts.length; i73++) {
               this.beziers.push(new Bezier(pts[0], pts[1]));
               pts.turn1()
          }
          pts.turn1()
     }
}

Xpath.prototype.SetPath = function() {
     var ancor = new Array(), p = this.pPoints;
     for ( var i1 = 0; i1 < p.length; i1++) {
          ancor.push( [ p[i1].an.x, p[i1].an.y ]);
     }
     var P;
     if (this.ai.pathPoints) {
          P = this.ai.pathPoints.parent
     } else {
          P = app.activeDocument.pathItems.add()
     }
     P.setEntirePath(ancor);
     for ( var i = 0; i < p.length; i++) {
          P.pathPoints.rightDirection = [ p.rDir.x, p.rDir.y ];
          P.pathPoints.leftDirection = [ p.lDir.x, p.lDir.y ];
          if (p.type) {
               P.pathPoints.pointType = p.type
          }
     }
};

// EXTENDED ITEM OBJ
function Xitem(obj) {
     if (obj) {
          this.name = "_Xitem";
          this.ai = obj;
          Xitem.prototype.center = new Point(this.ai.position[0] + this.ai.width
                    / 2, this.ai.position[1] - this.ai.height / 2);

          Xitem.prototype.bottomLeft = new Point(this.ai.position[0],
                    this.ai.position[1] - this.ai.height);
          
          Xitem.prototype.topRight = new Point(this.ai.position[0]
                    + this.ai.width, this.ai.position[1]);

     }
}



Xitem.prototype.SetToCenter = function(point) {
     this.ai.position = [ point.x - this.ai.width / 2,
               point.y + this.ai.height / 2 ]
};
Xitem.prototype.SetToBottom = function(point) {
     this.ai.position = [ point.x - this.ai.width / 2, point.y + this.ai.height ]
};
Xitem.prototype.SetToTop = function(point) {
     this.ai.position = [ point.x - this.ai.width / 2, point.y ]
};
Xitem.prototype.inside = function(pt) {
     if (pt.x < this.topRight.x && pt.y < this.topRight.y) {
          if (pt.x > this.bottomLeft.x && pt.y > this.bottomLeft.y) {
               return true
          }
     }
     return false
};
// Xitem.prototype.duplicate=function (){return new Xitem(this.ai.duplicate())};
// -------------------------------------------------------------------
// ----------END OF
// XTENDAIJS----------------------------------------------------------

function Demo(h) {
     alert("we will take its first 4 pathpoints as points for a beziersegment");
     var pfad = new Xpath(h);
     sel[0].remove();
     var a = pfad.pPoints[1].an;
     var b = pfad.pPoints[2].an;
     var c = pfad.pPoints[3].an;
     var d = pfad.pPoints[0].an;
     var bez = new Bezier( {
          an : a,
          rDir : b
     }, {
          lDir : c,
          an : d
     }) // ------ (pPoint1 , pPoint2)
     // ------{A,B,C,D} are Points ( with properties x,y)
     // ----------------------------------------------------------------------------------------------------------------
     var p1 = bez.A.Dot(15), p2 = bez.D.Dot(15);
     redraw()
     alert("These are the anchors");
     // ----------------------------------------------------------------------------------------------------------------
     // ---------Bezier.Point.function(size)
     var p3 = bez.B.Dot(10), p4 = bez.C.Dot(10);
     // ---------Bezier.Point.function(Point)
     var l1 = bez.A.Line(bez.B), l2 = bez.C.Line(bez.D);
     redraw()
     alert("These are the handles");
     // ----------------------------------------------------------------------------------------------------------------
     var t03 = bez.PointsForT(0.3);
     t03.PP.Dot(10);
     redraw()
     alert("This is the Point on the Path at T=0.3...");
     // ---------------------------------------------------------------------------------------------------------------
     bez.B.Line(bez.C);
     t03.BT.Line(t03.tt);
     t03.CT.Line(t03.tt);
     t03.T1.Line(t03.T2);
     redraw()
     alert("... and this is how it was calculated");
     // ---------------------------------------------------------------------------------------------------------------
     bez.PointsForT(0.1).PP.Dot(10);
     bez.PointsForT(0.2).PP.Dot(10);
     bez.PointsForT(0.5).PP.Dot(10);
     bez.PointsForT(0.4).PP.Dot(10);
     bez.PointsForT(0.6).PP.Dot(10);
     bez.PointsForT(0.7).PP.Dot(10);
     bez.PointsForT(0.8).PP.Dot(10);
     bez.PointsForT(0.9).PP.Dot(10);
     redraw()
     alert("Points from T=0.1 to 0.9");
     // --------------------------------------------------------------------------------------------------------------
     var pa1 = new Xpath(pa.add()); //-------- normally created from existing PathItem...
     // -------...then this step is  not necessary:
     pa1.pPoints = [ new XpPoint(a, a, b), new XpPoint(c, d, d) ];
     pa1.SetPath();
     redraw()
     alert("This is the resulting Path \n try to set a point manually at pos t 0.3\n and observe how the handles change");
}

function Demo3(PagEitem) {
     var p = new Xpath(PagEitem);
     var pZero = new Point(0, 0);
     alert(p.center);
     p.SetToCenter(pZero);
     redraw();
     alert(p.name);
     alert(p.ai.typename);
     p.SetToCenter( {
          x : 20,
          y : 20
     });
}

function Demo2() {
     var pa1 = new Xpath(sel[0]), pa2 = new Xpath(sel[1]);
     for ( var i_1 = 0; i_1 < pa1.beziers.length; i_1++) {
          for ( var i_2 = 0; i_2 < pa2.beziers.length; i_2++) {
               var inters = new Intersection().IfInterSect(pa1.beziers[i_1],
                         pa2.beziers[i_2]);
               if (inters.status == "Intersection") {
                    for ( var i_3 = 0; i_3 < inters.points.length; i_3++) {
                         // if you want to know the point...
                         inters.points[i_3].Dot(7);
                         // ...to manipulate path 1...
                         pa1.beziers[i_1].PointsForT(inters.points[i_3].t1).PP
                                   .Dot(15);
                         // ...path 2
                         pa2.beziers[i_2].PointsForT(inters.points[i_3].t2).PP
                                   .Dot(20);
                    }
               }
          }
     }
}

function polyline(){
     
     for(var i =0;i<pa.length;i++){
     
          var polypoints=[];
          
          var pfad= new Xpath(pa);
          
          for(var j =0;j<pfad.beziers.length;j++){
          
               var bez = pfad.beziers;
               
               for(var k=0; k<=1; k+=0.1){
               
                    var point = bez.PointsForT(k).PP;
                    
                    polypoints.push([point.x,point.y]);
               }
          }
          
          pa.setEntirePath(polypoints);
     }

}

//-----Begin Script--------
var ad = app.activeDocument, pa = ad.pathItems;
var sel = GetSelPaths();
//demo1
// if (sel) {
     // //sel.selected=false; redraw();
     // Demo3(sel[0])
// } else {
     // alert("please draw a path with at least 4 ancors, select it and run again");
// }

//demo2   select 2 (overlapping) PathItems and run
// Demo2()

polyline();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines