标签:
剧情提要:正剧开始:
星历2016年04月10日 13:48:09, 银河系厄尔斯星球中华帝国江南行省。
[工程师阿伟]正在和[机器小伟]一起研究[点、直线、平面之间的位置关系]。
来画个平面玩玩吧。
<span style="font-size:18px;">//平面 if (1) { var r = 20; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r); config.axis3D(0, 0, 0, 180); var transform = new Transform(); var a = 4*r, b = 3*r, h = 2*r; var edges = 4; var array = shape.rect(a, b); var size = array.length; var topFace = [], bottomFace = []; for (var i = 0; i < size; i++) { topFace.push(shape.point3D(array[i][0], 0, array[i][1])); } topFace = transform.flipY(topFace); shape.strokeDraw([].concat(topFace), 'pink',5); shape.pointDraw([].concat(topFace), 'red',5, 1); }</span>
再来画两个平面相交:
<span style="font-size:18px;"> if (1) { var r = 20; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r); config.axis3D(0, 0, 0, 180); var transform = new Transform(); var a = 4*r, b = 3*r, h = 2*r; var edges = 4; var array = shape.rect(a, b); var size = array.length; var topFace = [], bottomFace = []; var thita = 2*Math.PI/3; var x = y = 0; for (var i = 0; i < size; i++) { x = -array[i][0]*Math.cos(thita)*0.6; y = array[i][0]*Math.sin(thita)*0.6; topFace.push(shape.point3D(array[i][0], 0, array[i][1])); bottomFace.push(shape.point3D(x, y, array[i][1])); } topFace = transform.flipY(topFace); bottomFace = transform.flipY(bottomFace); shape.strokeDraw([].concat(topFace), 'pink',5); shape.pointDraw([].concat(topFace), 'red',5, 1); shape.strokeDraw([].concat(bottomFace), 'orange',5); shape.pointDraw([].concat(bottomFace), 'orange',5, 1, ['A\'', 'B\'', 'C\'', 'D\'']); } </span>
由于这些公理都是在一定的假设前提下证明的,所以小伟没办法多加深入,
但小伟想知道的是:一个投影点的坐标,它可能是哪些空间点产生的,
比如在斜二测画法的情况下?
于是做了一个研究:
<span style="font-size:18px;">def point3D(x, y, z): z = z/2; x = -(x-z*0.707); y = y+z*0.707; return [x, y]; def tmp(): x0 = y0 = z0 = 5; b = point3D(x0, y0, z0); epsilon = 0.01; rMin = 0; rMax = 10; delta = 0.1; x = y = z = 0; while x < rMax: x += delta; y = rMin; while y < rMax: y += delta; z = rMin; while z < rMax: z += delta; a = point3D(x, y, z); if abs(a[0] - b[0])< epsilon and abs(a[1] - b[1])<epsilon: print('PROJ[{0:.2f}, {1:.2f}, {2:.2f}] = PROJ[{3}, {4}, {5}] = {6:.2f}, {7:.2f}' .format(x, y, z, x0, y0, z0, a[0], a[1]));</span>
这是结果:
<span style="font-size:18px;">>>> PROJ[3.30, 6.70, 0.20] = PROJ[5, 5, 5] = -3.23, 6.77 PROJ[3.40, 6.60, 0.50] = PROJ[5, 5, 5] = -3.22, 6.78 PROJ[3.70, 6.30, 1.30] = PROJ[5, 5, 5] = -3.24, 6.76 PROJ[3.80, 6.20, 1.60] = PROJ[5, 5, 5] = -3.23, 6.77 PROJ[3.90, 6.10, 1.90] = PROJ[5, 5, 5] = -3.23, 6.77 PROJ[4.30, 5.70, 3.00] = PROJ[5, 5, 5] = -3.24, 6.76 PROJ[4.40, 5.60, 3.30] = PROJ[5, 5, 5] = -3.23, 6.77 PROJ[4.50, 5.50, 3.60] = PROJ[5, 5, 5] = -3.23, 6.77 PROJ[4.90, 5.10, 4.70] = PROJ[5, 5, 5] = -3.24, 6.76 PROJ[5.00, 5.00, 5.00] = PROJ[5, 5, 5] = -3.23, 6.77 PROJ[5.10, 4.90, 5.30] = PROJ[5, 5, 5] = -3.23, 6.77 PROJ[5.50, 4.50, 6.40] = PROJ[5, 5, 5] = -3.24, 6.76 PROJ[5.60, 4.40, 6.70] = PROJ[5, 5, 5] = -3.23, 6.77 PROJ[5.70, 4.30, 7.00] = PROJ[5, 5, 5] = -3.23, 6.77 PROJ[6.10, 3.90, 8.10] = PROJ[5, 5, 5] = -3.24, 6.76 PROJ[6.20, 3.80, 8.40] = PROJ[5, 5, 5] = -3.23, 6.77 PROJ[6.30, 3.70, 8.70] = PROJ[5, 5, 5] = -3.22, 6.78 PROJ[6.60, 3.40, 9.50] = PROJ[5, 5, 5] = -3.24, 6.76 PROJ[6.70, 3.30, 9.80] = PROJ[5, 5, 5] = -3.24, 6.76 PROJ[6.80, 3.20, 10.10] = PROJ[5, 5, 5] = -3.23, 6.77</span>
都可能会有很多点被投影到同一个图像位置。
其实这次小伟想来算一下点阵围成图形的面积。
<span style="font-size:18px;"> if (1) { var r = 20; config.setSector(1,1,1,1); config.graphPaper2D(0, 0, r); config.axis2D(0, 0, 180); var transform = new Transform(); var a = 4, b = 3, h = 2; var edges = 4; var array = shape.trapezoid(0, 0, 0, a, b, Math.PI/3); var size = array.length; //document.write(areaCalc(array)); //由阵列分割出的三角形 var tri = []; var xCenter = yCenter = 0; var S = 0; var scale = 2*r; var measure = 0; for (var i = 1; i < size-1; i++) { tri = []; tri.push(array[0]); tri.push(array[i]); tri.push(array[i+1]); xCenter = (tri[0][0]+tri[1][0]+tri[2][0])/3*scale; yCenter = -(tri[0][1]+tri[1][1]+tri[2][1])/3*scale; S = areaCalc(tri); if (S > 0) { shape.strokeDraw(tri, 'red', scale); var text = 'S='+S.toFixed(2); measure = plot.measureText(text); plot.fillText(text, xCenter-measure/2, yCenter, measure); } } shape.angleDraw(array, 'blue', scale); } } function areaCalc(array) { //array中包含组成三角形的三个点的坐标 array = shape.angularSort(array); var S = 0; if (array.length >=3) { var x1 = array[0][0], y1 = array[0][1], x2 = array[1][0], y2 = array[1][1], x3 = array[2][0], y3 = array[2][1]; S = 0.5*(x1*y2+x2*y3+x3*y1-x1*y3-x2*y1-x3*y2); } return S; }</span>
有了这个工具,以后应该会省不少事的。
本节到此结束,欲知后事如何,请看下回分解。
标签:
原文地址:http://blog.csdn.net/mwsister/article/details/51112569