正剧开始:
星历2016年03月19日 10:03:20, 银河系厄尔斯星球中华帝国江南行省。
[工程师阿伟]正在和[机器小伟]一起研究[勾股定理]。
<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 triangle = new Triangle(); var array = triangle.know3edges([3, 4, 5]); var tmp = []; plot.translate(r, -r) .save(); for (var i = 0; i < 4; i++) { tmp = [].concat(array); shape.angleDraw(tmp, 'red', 2*r, 'ABC'); plot.rotate(Math.PI/2); plot.translate(2*r, 0); } plot.restore(); }</span>
<span style="font-size:18px;">function Triangle() { this.edges = []; this.angles = []; //已知三条边 this.know3edges = function(edges) { this.edges = []; this.angles = []; this.edges = edges; //角度为弧度单位 //a边对应角 this.angles.push(Math.acos((edges[1]*edges[1] + edges[2]*edges[2]-edges[0]*edges[0])/(2*edges[1]*edges[2]))); //b边对应角 this.angles.push(Math.acos((edges[0]*edges[0] + edges[2]*edges[2]-edges[1]*edges[1])/(2*edges[0]*edges[2]))); //c边对应角 this.angles.push(Math.acos((edges[0]*edges[0] + edges[1]*edges[1]-edges[2]*edges[2])/(2*edges[0]*edges[1]))); var x0 = 0, y0 = 0; var x1 = x0 + this.edges[0], y1 = y0; var x2 = x0 + this.edges[1] * Math.cos(-this.angles[2]), y2 = y0 + this.edges[1] * Math.sin(-this.angles[2]); var retArray = new Array(); retArray.push([x0, y0]); retArray.push([x1, y1]); retArray.push([x2, y2]); return retArray; } //已知两个角 this.know2angles = function(angles, r) { this.edges = []; this.angles = []; this.angles = [angles[0]/180*Math.PI, angles[1]/180*Math.PI, (180-(angles[0]+angles[1]))/180*Math.PI]; //设其中一边长度为10 r = r > 0 ? r : 10; //A边 this.edges.push(r); var angleA = this.angles[0]; angleB = this.angles[1]; angleC = this.angles[2]; //B边 this.edges.push(Math.sin(angleB)/Math.sin(angleA)*r); //C边 this.edges.push(Math.sin(angleC)/Math.sin(angleA)*r); var x0 = 0, y0 = 0; var x1 = x0 + this.edges[0], y1 = y0; var x2 = x0 + this.edges[1] * Math.cos(-this.angles[2]), y2 = y0 + this.edges[1] * Math.sin(-this.angles[2]); var retArray = new Array(); retArray.push([x0, y0]); retArray.push([x1, y1]); retArray.push([x2, y2]); return retArray; } //已知2条边 this.know2edges = function(edges, angle) { this.edges = []; this.angles = []; //如果没有指定两边的夹角,默认为90度 angle = angle ? angle/180*Math.PI : Math.PI/2; var edgeC = Math.sqrt(edges[0]*edges[0]+edges[1]*edges[1]-2*edges[0]*edges[1]*Math.cos(angle)); this.edges = [edges[0], edges[1], edgeC]; var edgeA = this.edges[0], edgeB = this.edges[1]; //角度为弧度单位 //a边对应角 this.angles.push(Math.acos((edgeB*edgeB + edgeC*edgeC-edgeA*edgeA)/(2*edgeB*edgeC))); //b边对应角 this.angles.push(Math.acos((edgeA*edgeA + edgeC*edgeC-edgeB*edgeB)/(2*edgeA*edgeC))); //c边对应角 this.angles.push(angle); var x0 = 0, y0 = 0; var x1 = x0 + this.edges[0], y1 = y0; var x2 = x0 + this.edges[1] * Math.cos(-this.angles[2]), y2 = y0 + this.edges[1] * Math.sin(-this.angles[2]); var retArray = new Array(); retArray.push([x0, y0]); retArray.push([x1, y1]); retArray.push([x2, y2]); return retArray; } //返回角度和边信息的字符串 this.info = function() { var angleLabel = ['C', 'A', 'B']; var edgeLabel = ['ab', 'bc', 'ac']; var s = ''; for (var i = 0; i < 3; i++) { s += edgeLabel[i]+' : '; s += this.edges[i].toFixed(2)+' ; '; } for (var i = 0; i < 3; i++) { s += angleLabel[i]+' : '; s += (this.angles[i]*180/Math.PI).toFixed(2) + ' ; '; } return s; } }</span>
还有:
<span style="font-size:18px;">this.angleDraw = function(array, style, scale, vertexLabel) { //vertexLabel是顶点编号顺序字符串 ABC,... style = style ? style : 'black'; //array是一个存放二维坐标点序列的数组 var a0 = new Array(); a0 = [].concat(array); scale = scale ? scale : 1; var len = a0.length; if (scale != 1 && scale > 0) { for (var i = 0; i < len; i++) { for (var j = 0; j < 2; j++) { a0[i][j]*=scale; } } } //进行环状排序,这样传入的array就可以任意顺序放置坐标点。 var a = this.angularSort(a0); //分两次绘点和连线 var tmp = [].concat(a); this.pointDraw(tmp, style); tmp = [].concat(a); this.strokeDraw(tmp, style); var d1, d2, d3, angle; var x1,y1, x2, y2, x3, y3; var s; //坐标点编号 var s0 = vertexLabel ? vertexLabel : 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; //标记边的长度 var edgeLong = 0; var measure = 0; //为每个点利用余弦定理求角 for (var i = 0; i < len; i++) { if (i == 0) { x1 = a[len-1][0]; y1 = a[len-1][1]; x3 = a[i+1][0]; y3 = a[i+1][1]; } else if (i == len-1) { x1 = a[i-1][0]; y1 = a[i-1][1]; x3 = a[0][0]; y3 = a[0][1]; } else { x1 = a[i-1][0]; y1 = a[i-1][1]; x3 = a[i+1][0]; y3 = a[i+1][1]; } x2 = a[i][0]; y2 = a[i][1]; d1 = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); d2 = (x2-x3)*(x2-x3)+(y2-y3)*(y2-y3); d3 = (x1-x3)*(x1-x3)+(y1-y3)*(y1-y3); angle = Math.acos((d1+d2-d3)/(2*Math.sqrt(d1*d2)))/Math.PI*180; s = angle.toFixed(2)+'°'; //document.write(s+'<p>'); //标注角度和顶点编号 plot.setFillStyle('purple'); plot.fillText(s, x2, -y2-5, 100); plot.setFillStyle(style); plot.fillText(s0[i], x2, -y2+20, 20); edgeLong = (Math.sqrt(d1)/scale).toFixed(2); measure = plot.measureText(edgeLong); plot.setFillStyle('blue'); plot.fillText(edgeLong, (x1+x2-measure)/2, -(y1+y2)/2+20, measure); } //由于处理会改变原矩阵,看以下操作能否恢复原矩阵 if (scale != 1 && scale > 0) { for (var i = 0; i < len; i++) { for (var j = 0; j < 2; j++) { a0[i][j]/=scale; } } } }</span>
看到这个题,阿伟就想笑,这个对角线就比木板多了4个毫米,如果这块板太薄,过门时很容易折坏,
如果稍微厚那么一点,就等着撞门框吧,这理论的数据可当不的真的哦。
<span style="font-size:18px;">function myDraw(xGlobal, yGlobal) { var config = new PlotConfiguration(); config.init(); config.setPreference(); var r = 80; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r/4); config.axis2D(0, 0,180); var triangle = new Triangle(); var array = triangle.know2edges([Math.sqrt(2.6*2.6-2.4*2.4), 2.4]); var tmp = []; config.setSector(1,3,1,1); tmp = [].concat(array); shape.angleDraw(tmp, 'red', r); array = triangle.know2edges([Math.sqrt(2.6*2.6-1.9*1.9), 1.9]); config.setSector(1,3,1,2); tmp = [].concat(array); shape.angleDraw(tmp, 'green', r); }</span>
<span style="font-size:18px;">function myDraw(xGlobal, yGlobal) { var config = new PlotConfiguration(); config.init(); config.setPreference(); var r = 25; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r); config.axis2D(0, 0,180); /* var triangle = new Triangle(); var array = triangle.know2edges([Math.sqrt(2.6*2.6-2.4*2.4), 2.4]); var tmp = []; config.setSector(2,3,1,1); tmp = [].concat(array); shape.angleDraw(tmp, 'red', r); array = triangle.know2edges([Math.sqrt(2.6*2.6-1.9*1.9), 1.9]); config.setSector(2,3,1,2); tmp = [].concat(array); shape.angleDraw(tmp, 'green', r); */ var array = []; var thita = 0; var rho = 0; var x, y; for (var i = 0; i < 36; i++) { rho = Math.sqrt(i); x = rho*Math.cos(thita); y = rho*Math.sin(thita); array.push([x, -y]); thita += Math.PI/12; } var tmp = []; tmp = [].concat(array); shape.pointDraw(tmp, 'red', r); tmp = [].concat(array); shape.multiLineDraw(tmp, 'pink', r); }</span>
<span style="font-size:18px;">function myDraw(xGlobal, yGlobal) { var config = new PlotConfiguration(); config.init(); config.setPreference(); var r = 50; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r/2); config.axis2D(0, 0,180); var triangle = new Triangle(); var array = triangle.know2edges([3, 4]); var tmp = []; config.setSector(2,3,1,1); tmp = [].concat(array); shape.angleDraw(tmp, 'red', r); array = triangle.know2edges([2.4, 0.7]); config.setSector(2,3,1,2); tmp = [].concat(array); shape.angleDraw(tmp, 'red', 2*r, 'AOB'); }</span>
<span style="font-size:18px;">function myDraw(xGlobal, yGlobal) { var config = new PlotConfiguration(); config.init(); config.setPreference(); var r = 50; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r/2); config.axis2D(0, 0,180); var triangle = new Triangle(); var array = triangle.know2edges([19, 39]); var tmp = []; config.setSector(2,3,1,1); tmp = [].concat(array); shape.angleDraw(tmp, 'red', 6); array = triangle.know2edges([Math.sqrt(7*7-5*5), 5]); config.setSector(2,3,1,2); tmp = [].concat(array); shape.angleDraw(tmp, 'red', 20); }</span>
<span style="font-size:18px;">function myDraw(xGlobal, yGlobal) { var config = new PlotConfiguration(); config.init(); config.setPreference(); var r = 50; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r/2); config.axis2D(0, 0,180); var triangle = new Triangle(); var array = triangle.know2edges([Math.sqrt(88*88-32*32), 32]); var tmp = []; config.setSector(2,3,1,1); tmp = [].concat(array); shape.angleDraw(tmp, 'red', 2); array = triangle.know2edges([5, 12]); config.setSector(2,3,1,2); tmp = [].concat(array); shape.angleDraw(tmp, 'green', 50); }</span>
<span style="font-size:18px;"> var mathText = new MathText(); var s = [ 'AE = DB', 'AD^[2]+DB^[2] = AB^[2]', 'AB^[2] = AC^[2]+BC^[2] = 2*AC^[2]' ]; var x =40, y=40; var r1 = 40; var len = s.length; for (var i = 0; i < len; i++) { if (s[i] == '') { if (x < 100) { x += 300; y-=r1*3; } else { x = 20; y += r1; } } else { mathText.print(s[i], x, y); y+=r1; } } </span>
<span style="font-size:18px;"> var triangle = new Triangle(); var array = []; var tmp = []; array = triangle.know3edges([15, 8, 17]); config.setSector(2,3,1,1); tmp = [].concat(array); shape.angleDraw(tmp, 'red', 10); array = triangle.know3edges([13, 14, 15]); config.setSector(2,3,1,2); tmp = [].concat(array); shape.angleDraw(tmp, 'green', 10); </span>
<span style="font-size:18px;"> var triangle = new Triangle(); var array = []; var tmp = []; array = triangle.know3edges([18, 24, 30]); config.setSector(2,3,1,1); tmp = [].concat(array); shape.angleDraw(tmp, 'red', 10); </span>
本节到此结束,欲知后事如何,请看下回分解。