正剧开始:
星历2016年03月11日 14:42:08, 银河系厄尔斯星球中华帝国江南行省。
[工程师阿伟]正在和[机器小伟]一起研究[轴对称]。
<span style="font-size:18px;">//题6 function myDraw(xGlobal, yGlobal) { var config = new PlotConfiguration(); config.init(); config.setPreference(); var r = 20; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r); config.axis2D(0, 0,180); var a = [[3,0], [0, 3], [1, 4], [4,1]]; //对称轴 var sym = [4, 0]; var len = a.length; for (var i = 0; i < len; i++) { a.push([2*sym[0]-a[i][0], a[i][1]]); } var b = shape.angularSort(a); var tmp = [].concat(b); plot.translate(-sym[0]*2*r, 0); shape.angleDraw(tmp, 'blue', 2*r); plot.fillText('E->D->C->G->A->B->E', -100, 100, 200); }</span>
小球的运动轨迹并不是图中蓝色的线,这只是小伟做的一个研究而已。
这个关于x轴或y轴轴对称的倒好办,但关于任意直线轴对称的点的关系是什么呢?
各种资料找了又找,终于让阿伟找到了一组方程,于是阿伟用它来画了一下关于[过坐标原点直线]的对称的图:
<span style="font-size:18px;">function myDraw(xGlobal, yGlobal) { var config = new PlotConfiguration(); config.init(); config.setPreference(); var r = 20; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r); config.axis2D(0, 0,180); var a = [[3,0], [0, 3], [1, 4]]; var k = Math.tan(-Math.PI/6); var len = a.length; var b = []; var x, y; for (var i = 0; i < len; i++) { //x1=(m-2kb+2kn-mk^2)/(1+k^2) //y1=(-n+2b+2km+nk^2)/(1+k^2) if (k != NaN) { var m = a[i][0], n = a[i][1]; x = (m-2*k+2*k*n-m*k*k)/(1+k*k); y = (-n+2*k*m+n*k*k)/(1+k*k); b.push([x,y]); } } shape.strokeDraw(a, 'red', r); shape.strokeDraw(b, 'blue', r); } </span>
<span style="font-size:18px;"> var a = [[3,0], [0, 3], [1, 4], [7, 2], [-7, 2]]; var k = Math.tan(-Math.PI/5);</span>
<span style="font-size:18px;">function myDraw(xGlobal, yGlobal) { var config = new PlotConfiguration(); config.init(); config.setPreference(); var r = 20; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r); config.axis2D(0, 0,180); var a = [[3,0], [0, 3], [1, 4], [7, 2], [-7, 2]]; var k = Math.tan(-Math.PI/5); var len = a.length; var b = []; var x, y; for (var i = 0; i < len; i++) { b.push([a[i][0], a[i][1]]); } for (var i = 0; i < len; i++) { //x1=(m-2kb+2kn-mk^2)/(1+k^2) //y1=(-n+2b+2km+nk^2)/(1+k^2) if (k != NaN) { var m = a[i][0], n = a[i][1]; x = (m-2*k+2*k*n-m*k*k)/(1+k*k); y = (-n+2*k*m+n*k*k)/(1+k*k); b.push([x,y]); } } var c = shape.angularSort(b); //shape.strokeDraw(a1, 'red', r); shape.strokeDraw(c, 'blue', r); } </span>
关于这些手拉手的猴子,小伟尽管做了多次尝试,现在还是没法成功完成。
现在只能做到这个程度:
<span style="font-size:18px;">function myDraw(xGlobal, yGlobal) { var config = new PlotConfiguration(); config.init(); config.setPreference(); var r = 15; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r); config.axis2D(0, 0,180); var a = [[10, -20]]; var r0 = 2, r1= 2*r0, r2=2*r1; //圆弧角度的起始 var beg, end; var central = shape.nEdge(0, 0, 10*r, 8); var len = central.length; var pangle = Math.PI*24/len; for (var i = 0; i < len; i++) { plot.save(); plot.translate(central[i][0], central[i][1]); plot.rotate(pangle*i); a = [[20, -30]]; // shape.strokeCircle(a[0][0], a[0][1], r0); shape.strokeCircle(a[0][0], a[0][1], r1); beg = -Math.PI/2-Math.PI/6, end = Math.PI/2; plot.beginPath() .arc(a[0][0], a[0][1], Math.abs(a[0][1]), beg, end, 0) .moveTo(a[0][0], a[0][1]-Math.abs(a[0][1])) .closePath() .stroke(); beg = -Math.PI/2; end = Math.PI/2-Math.PI/6; plot.beginPath() .arc(a[0][0], -a[0][1], Math.abs(a[0][1]), beg, end, 1) .moveTo(a[0][0], a[0][1]+Math.abs(a[0][1])) .closePath() .stroke(); plot.beginPath() .moveTo(a[0][0]-r2/2, -a[0][1]+r2/2) .lineTo(a[0][0]+r2/2, -a[0][1]-r2/2) .closePath() .stroke(); //对称 a[0][0] = -a[0][0]; // shape.strokeCircle(a[0][0], a[0][1], r0); shape.strokeCircle(a[0][0], a[0][1], r1); beg = Math.PI/2, end = -Math.PI/2+Math.PI/6; plot.beginPath() .arc(a[0][0], a[0][1], Math.abs(a[0][1]), beg, end, 0) .moveTo(a[0][0], a[0][1]-Math.abs(a[0][1])) .closePath() .stroke(); beg = Math.PI/2+Math.PI/6; end = -Math.PI/2; plot.beginPath() .arc(a[0][0], -a[0][1], Math.abs(a[0][1]), beg, end, 1) .moveTo(a[0][0], a[0][1]+Math.abs(a[0][1])) .closePath() .stroke(); plot.beginPath() .moveTo(a[0][0]-r2/2, -a[0][1]-r2/2) .lineTo(a[0][0]+r2/2, -a[0][1]+r2/2) .closePath() .stroke(); plot.translate(-central[i][0], -central[i][1]); plot.restore(); } }</span>
而不是用API来一点点的画。白白浪费感情了。
<span style="font-size:18px;">//题3 function myDraw(xGlobal, yGlobal) { var config = new PlotConfiguration(); config.init(); config.setPreference(); var r = 20; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r); config.axis2D(0, 0,180); var a = shape.nStar(0, 0, 8*r, 5, -Math.PI/2); var len = a.length; var tmp = []; tmp = [].concat(a); shape.angleDraw(tmp, 'red'); }</span>
<span style="font-size:18px;">function myDraw(xGlobal, yGlobal) { var config = new PlotConfiguration(); config.init(); config.setPreference(); var r = 15; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r); config.axis2D(0, 0,180); var triangle = new Triangle(); var a = triangle.know2angles([84-42, 42], 2*15); var tmp = [].concat(a); shape.angleDraw(tmp, 'red', 4); var s = triangle.info(); plot.fillText(s, -250, 150, 500); }</span>
本节到此结束,欲知后事如何,请看下回分解。