var my={};function crossprodMain(typ){my.version='0.77';my.typ=typeof typ!=='undefined'?typ:'triangle';w=240;h=240;var s="";s+='
';s+='';s+='
';s+=getPlayHTML(40);s+='
';s+='
© 2018 MathsIsFun.com v'+my.version+'
';s+='
';document.write(s);el=document.getElementById('canvasId');ratio=2;el.width=w*ratio;el.height=h*ratio;el.style.width=w+"px";el.style.height=h+"px";g=el.getContext("2d");g.setTransform(ratio,0,0,ratio,0,0);my.frame=0;my.skip=0 my.midPt=new Pt(w/2,h/2);my.wd=100 my.rotPts=getArcPts(0,0,1,1,0,Math.PI*2);my.ellPts=[] for(var i=0;imy.rotPts.length if(aboveQ)drawCrossProd() g.strokeStyle='hsla(50,50%,70%,1)' g.fillStyle='hsla(50,50%,90%,0.7)' g.beginPath();drawPts(g,my.ellPts,true) g.stroke() g.fill() g.strokeStyle='black' g.lineJoin='round';g.lineWidth=2;g.beginPath();var pt0=trans(my.pts[0],my.rotZeroPt) g.moveTo(pt0.x,pt0.y) var pt1=trans(my.pts[1],my.rotZeroPt) g.lineTo(pt1.x,pt1.y) g.stroke();doArrow(pt0,pt1,true) g.font='bold 18px arial' g.fillText('a',(pt0.x+pt1.x)/2,(pt0.y+pt1.y)/2) g.strokeStyle='black' g.beginPath();var pt0=trans(my.pts[0],rotPt) g.moveTo(pt0.x,pt0.y) var pt1=trans(my.pts[1],rotPt) g.lineTo(pt1.x,pt1.y) g.stroke();doArrow(pt0,pt1,true) g.fillText('b',(pt0.x+pt1.x)/2,(pt0.y+pt1.y)/2) if(!aboveQ)drawCrossProd() if(playQ)requestAnimationFrame(animate);} function drawCrossProd(){var rot=my.frame/my.rotPts.length;var rot1=Math.sin(rot*2*Math.PI) var topPt={x:my.midPt.x,y:my.midPt.y-100*rot1} g.strokeStyle='blue';g.lineWidth=3;g.beginPath();g.moveTo(my.midPt.x,my.midPt.y);g.lineTo(topPt.x,topPt.y);g.stroke();doArrow(my.midPt,topPt,false)} function doArrow(frPt,toPt,flatQ){var len=Math.sqrt(Math.pow(toPt.x-frPt.x,2)+Math.pow(toPt.y-frPt.y,2)) if(len>1){var headLen=20 var shaftHt=15 if(flatQ){headLen=20*len/100 shaftHt=headLen*0.75}else{if(len<10){}} g.beginPath() var ang=Math.atan2(toPt.y-frPt.y,toPt.x-frPt.x) g.drawArrow(toPt.x,toPt.y,shaftHt,2,headLen,10,-ang) g.stroke() g.fillStyle=g.strokeStyle g.fill()}} function trans(pt,rotPt){var x=my.midPt.x+(pt.x-my.midPt.x)*rotPt.x var y=(my.midPt.y-20)*rotPt.y var dx=pt.x-my.midPt.x;x=pt.x+dx*(rotPt.x-1) y=pt.y+dx*rotPt.y return{x:x,y:y}} function getArcPts(midX,midY,radiusX,radiusY,fromAngle,toAngle){var points=[];if(isNear(fromAngle,toAngle,0.0001)){return points;} if(radiusX!=radiusY){fromAngle=Math.atan2(Math.sin(fromAngle)*radiusX/radiusY,Math.cos(fromAngle));toAngle=Math.atan2(Math.sin(toAngle)*radiusX/radiusY,Math.cos(toAngle));} if(fromAngle>toAngle){while(fromAngle>toAngle){fromAngle-=2*Math.PI;}} var steps=Math.max(1,parseInt((toAngle-fromAngle)*28));for(var i=0;i<=steps;i++){var radians=fromAngle+(toAngle-fromAngle)*(i/steps);var thisX=midX+(Math.cos(radians)*radiusX);var thisY=midY-(Math.sin(radians)*radiusY);points.push(new Pt(thisX,thisY));} return points;} function rotatePts(pts,midX,midY,rot){var newPts=[];for(var i=0;icentralVal+limitVal) return false;return true;} function Pt(ix,iy){this.x=ix;this.y=iy;this.name="?";this.rad=12;angleIn=0;angleOut=0;} Pt.prototype.add=function(dx,dy){return new Pt(this.x+dx,this.y+dy);};Pt.prototype.rotate=function(angle){var cosa=Math.cos(angle);var sina=Math.sin(angle);var xPos=this.x*cosa+this.y*sina;var yPos=-this.x*sina+this.y*cosa;return new Pt(xPos,yPos);} CanvasRenderingContext2D.prototype.drawArrow=function(x0,y0,totLen,shaftHt,headLen,headHt,angle,sweep,invertQ){var g=this;var pts=[[0,0],[-headLen,-headHt/2],[-headLen+sweep,-shaftHt/2],[-totLen,-shaftHt/2],[-totLen,shaftHt/2],[-headLen+sweep,shaftHt/2],[-headLen,headHt/2],[0,0]];if(invertQ){pts.push([0,-headHt/2],[-totLen,-headHt/2],[-totLen,headHt/2],[0,headHt/2]);} for(var i=0;i