tremble 6 gadi atpakaļ
vecāks
revīzija
547717ab52
2 mainītis faili ar 49 papildinājumiem un 11 dzēšanām
  1. 4 4
      js/drawGeometry.js
  2. 45 7
      js/util.js

+ 4 - 4
js/drawGeometry.js

@@ -121,10 +121,10 @@ function drawGeometry(n_panorama_line_3d) {
 
 }
 
-// /**
-//  * 
-//  * @param {*} point 
-//  */
+/**
+ * 
+ * @param {*} point 
+ */
 // function findverticalLine(point) {
 //     let lineAry = [];
 //     for (let i = 0; i < panorama_line_3d.length; i++) {

+ 45 - 7
js/util.js

@@ -700,12 +700,18 @@ function selectWhichFace(lineArr, faceArr, current, _3dLine, scaleTime, scaleTim
 }
 
 /**
-* 
-* @param {*} point 
+* 求与该平面相交的线段的相关信息
+* @param {array} faceLine 面的索引数组
+* @return {object} verticalLineData
 */
 function findverticalLine(faceLine,n_panorama_line_3d) {
 
     let lineAry = [];
+    let verticalLineData = {
+        lineAry: [],
+        vecAry: [],
+        verticalVec: []
+    }
     for (let k = 0; k < faceLine.length; k++) {
         n_panorama_line_3d.find(item => {
             if (item['3d_id'] === faceLine[k]) {
@@ -713,22 +719,54 @@ function findverticalLine(faceLine,n_panorama_line_3d) {
                     let sta_point = item[geoKeys[l]];
                     for (let i = 0; i < n_panorama_line_3d.length; i++) {
                         for (let j = 0; j < geoKeys.length; j++) {
-                            let curpoint = n_panorama_line_3d[i][geoKeys[j]];
+                            let line = n_panorama_line_3d[i];
+                            let curpoint = line[geoKeys[j]];
                             let id = n_panorama_line_3d[i]['3d_id'];
-                            if (arrayEquals(sta_point, curpoint) && faceLine.indexOf(id) < 0 && lineAry.indexOf(id) < 0) {
-                                lineAry.push(id);
+                            // 如果相交线段在当前面中, 则求它对应的向量
+                            if (arrayEquals(sta_point, curpoint) && faceLine.indexOf(id) >= 0 && verticalLineData.vecAry.length < 2) {
+                                let croodData = getThreeDVec(line['3d_point1'], line['3d_point2']);
+                                let vec3 = new THREE.Vector3(croodData[0], croodData[1], croodData[2])
+                                verticalLineData.vecAry.push(vec3);
+                            }
+                            if (arrayEquals(sta_point, curpoint) && faceLine.indexOf(id) < 0 && verticalLineData.lineAry.indexOf(id) < 0) {
+                                verticalLineData.lineAry.push(id);
                             }
                         }
                     }
                 }
             }
         })
-
     }
-    console.log(lineAry);
+    let crossVec = new THREE.Vector3();
+    crossVec.crossVectors(verticalLineData.vecAry[0], verticalLineData.vecAry[1]);
+    verticalLineData.verticalVec.push(crossVec.x, crossVec.y, crossVec.z)
+    // console.log(tmp);
+    // console.log(lineAry);
     return lineAry;
 }
 
+/**
+ * 计算三维空间中的向量
+ * @param {array} point1 
+ * @param {array} point2 
+ */
+function getThreeDVec(point1, point2) {
+    if (!point1 || !point2 || (point1.length !== point2.length)) {
+        console.log('点数据有误, 请检查');
+        return;
+    }
+    let vec = [];
+    for (let i = 0; i < point1.length; i++) {
+        let val = point1[i] - point2[i];
+        vec.push(val);
+    }
+    if (vec.length < 3) {
+        console.log('所求三维向量有误, 请检查');
+        return;
+    }
+    return vec;
+}
+
 
 /**
  * 根据sta查找点