JSFiddle - React, Tailwind, and code Playground
by Cibeles Garcia
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<canvas height="240" id="cinciMainCanvas" style="width: 100%;" width="320"></canvas>
JavaScript
function BizierLineCollide(x,y,m,A,B,C,D){
var Ax=A[0], Ay=A[1], At, Bx=B[0], By=B[1], Bt, Cx=C[0], Cy=C[1], Ct, Dx=D[0], Dy=D[1], Dt, result=[];
if(Math.abs(m)<=1){
At=(Ay-3*By+3*Cy-Dy)-m*(Ax-3*Bx+3*Cx-Dx);
Bt=3*(By-2*Cy+Dy)-m*3*(Bx-2*Cx+Dx);
Ct=3*(Cy-Dy)-m*3*(Cx-Dx)
Dt=Dy-y+m*(x-Dx);
result= eqCubic(At,Bt,Ct,Dt);
}else{
var w=1/m;
At=(Ax-3*Bx+3*Cx-Dx)-w*(Ay-3*By+3*Cy-Dy);
Bt=3*(Bx-2*Cx+Dx)-w*3*(By-2*Cy+Dy);
Ct=3*(Cx-Dx)-w*3*(Cy-Dy);
Dt=Dx-x+w*(y-Dy);
result= eqCubic(At,Bt,Ct,Dt);
}
var fnB=fnBizier(A,B,C,D), _return=[];
result.forEach(function(v,k){
if(!isNaN(v)){
v=Math.round(v*10000)/10000;
if(v>=0 && v<1){
_return.push(fnB(v));
}
}
});
return _return;
}
function eqCubic(a,b,c,d){ //http://www.gyplan.com/es/eqcubic_es.html
var x1=x2=x3=0, f,g,h,m,k,m2,n,n2,r,rc,theta;
if(a=="" && b==""&& c=="" && d=="") return 'es vacia';
if(a=="" && b==""&& c=="" ) return d;
if(a=="" && b=="" ){
a=c; b=d;
return -b/a;
}
if(a==0 | a=="") {
a=b; b=c; c=d;
var b24ac2a=Math.sqrt(b*b-4*a*c);
return isNaN(b24ac2a)?[]:[(-b+b24ac2a)/(2*a),(-b-b24ac2a)/(2*a)];
};
f = (((3*c)/a) - (((b*b)/(a*a))))/3
g = ((2*((Math.pow(b,3))/(Math.pow(a,3)))-(9*b*c/(a*a)) + ((27*(d/a)))))/27 // Math.pow(b,3)
h = (((g*g)/4) + ((f*f*f)/27))
var dis = h;
if (h > 0){
m = (-(g/2)+ (Math.sqrt(h)))
k=1
if (m < 0) k=-1; else k=1
m2 = (Math.pow((m*k),(1/3)))
m2 = m2*k
k=1
n = -(g/2)- (Math.sqrt(h))
if (n < 0) k=-1; else k=1
n2 = (Math.pow((n*k),(1/3)))
n2 = n2*k
k=1
x1= (m2 + n2) - b/(3*a);
x2= ((-1*(m2 + n2)/2 - b/(3*a)) + " + i * " + (m2 - n2)*Math.pow(3,.5)/2 );
x3= ((-1*(m2 + n2)/2 - b/(3*a)) + " - i * " + (m2...