VDF常见问题整理(四十三):如何从点中获取折线段?

VectorDraw Developer Framework试用版下载


问:

    单击折线的某处时如何获取折线的线段/p>

答:

    在版本7012.0.7中,已导出新方法vdgeo.GetPlineSegmentIndexFromPoint(对象点,对象[]顶点,bool isClosed,对象trusionVector)。

  • 点:世界坐标中的通过点。

  • 顶点:通常从pline.VertexList.Items获取的折线顶点数组。

  • isClosed:如果关闭则为True,打开则为False,不通过为False。

  • trusionVector:[X,Y,Z]的数组,它是一个垂直于折线平面的向量。通常我们从折线中获取它。如果不通过,它将获得[0,0,1]值。

    下面是一个示例,其中当我们单击折线附近的某个位置时,我们可以在鼠标按下事件中找到带有折线的起点和终点的线段,它更接近我们单击的点。

   function _vdmousedown(e) {            if (e.target.ActiveAction().IsStarted()) return; //no user waiting action is active            var entity = e.target.GetEntityFromPoint(e.xPix, e.yPix); //scan for an entity under the pick point            if (!entity || entity._t !== vdConst.vdPolyline_code) return; //check if entity exist and is a polyline type            var index = vdgeo.GetPlineSegmentIndexFromPoint([e.x, e.y, e.z], entity.VertexList.Items, entity.Flag == 1, entity.ExtrusionVector); //get the picked index near the pick point            if (index == -1) return;             //an index was found.Print the result            var sp, ep;             sp = entity.VertexList.Items[index];             if (index == entity.VertexList.Items.length - 1) ep = entity.VertexList.Items[0];//in case passed polyline is closed            else ep = entity.VertexList.Items[index + 1];            alert("Segment " + index + "nbetween first point X=" + sp[0].toFixed(3).toString() + "   Y=" + sp[1].toFixed(3).toString() + "   Z=" + sp[2].toFixed(3).toString() + "   Bulge=" + sp[3].toFixed(3).toString()            + "nand second point X=" + ep[0].toFixed(3).toString() + "   Y=" + ep[1].toFixed(3).toString() + "   Z=" + ep[2].toFixed(3).toString() + "   Bulge=" + ep[3].toFixed(3).toString());       }

    对于以上问答,如果您有任何的疑惑都可以在评论区留言,我们会及时回复。此系列的问答教程我们会持续更新,如果您感兴趣,可以多多关注本教程。

热门文章推荐:

  • 如何排除GroundSurface对象的三角形区域/strong>

  • 复杂自定义对象的入门指南


    如果您对想要购买正版授权VectorDraw Developer Framework(VDF),可以联系在线客服>>咨询相关问题。

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年11月3日
下一篇 2019年11月3日

相关推荐

发表回复

登录后才能评论