我想获得某点(非顶点)到mesh面上的最短距离,根据以往的帖子我看到是利用DrapeLineString去获取CurveVector,但是我出现了以下的问题:
不知道是我的坐标传错了还是方向不对。
MeshHeaderElement meshElem = element as MeshHeaderElement; //direction 到Mesh的垂直方向 DVector3d direction = new DVector3d(0,0,1); //point DPoint3d dp_1 = new DPoint3d(403791699190, 36344091290); DPoint3d dp_3 = new DPoint3d(403791755410, 36344058670); dpList.Add(dp_1); dpList.Add(dp_3); //gain PolyfaceHeader PolyfaceHeader pfh = meshElem.GetMeshData(); //cv is null CurveVector cv = pfh.DrapeLinestring(dpList, direction);
以下是获取的PolyfaceHeader:
1. 您的direction是DVector3d(0,0,1),表示沿z轴向上,这要求您的dpList的点要在Mesh的下方。
2. 查看返回结果不是应该看返回值cv中的点吗?看您原始的phf有什么作用?
MeshHeaderElement meshElem = element as MeshHeaderElement; DVector3d direction = new DVector3d(0,0,1); DPoint3d dp_1 = new DPoint3d(403791699190, 36344091290); DPoint3d dp_3 = new DPoint3d(403791755410, 36344058670);
PolyfaceHeader pfh = meshElem.GetMeshData(); dpList.Add(dp_1); dpList.Add(dp_3); //cv is null CurveVector cv = pfh.DrapeLinestring(dpList, direction);
if (cv == null) { direction = new DVector3d(0, 0, -1); CurveVector cv_1 = pfh.DrapeLinestring(dpList, direction); for (int i = 0; i < cv_1.Count; i++) { CurvePrimitive cp = cv.GetPrimitive(i); cp.TryGetLineString(dpLS);
} } else { for (int i = 0; i < cv.Count; i++) { CurvePrimitive cp = cv.GetPrimitive(i); cp.TryGetLineString(dpLS);
} } for (int i = 0; i < dpLS.Count; i++) { DPoint3d dd = dpLS[i]; }
符老师,我重新改了代码,但cv_1还是空的。
链接:pan.baidu.com/.../1TgiZJ0TBT-vC6NKtGeJb4g 提取码:loko
这是测试文件
两个投影的点压根就投不到Mesh上,返回的结果当然是空的了。
正如郭工所述,我们编程前可以先手工去验证一下我们的数据。看是否能工作,而后再用代码去实现它们。我用你的模型和你代码中两个点画了一个线,如下图所示。这条线和您现有的Mesh都距离很远,无法通过(0,0,1)这个方向投影上去。