如何从ILNumerics曲面图上的鼠标单击位置中找到曲面的3D坐标? [英] How to find the 3D coordinates of a surface from the click location of the mouse on the ILNumerics surface plots?

查看:116
本文介绍了如何从ILNumerics曲面图上的鼠标单击位置中找到曲面的3D坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我们的系统使用带有ILNumerics曲面组件的ILNumerics 3D绘图立方体类来显示3D网格化表面.我们系统的目标是能够通过在图上单击鼠标来查询表面上的各个点.我们在绘图上设置了MouseClick事件,问题是我不确定如何获取已单击的表面上特定点的值,有人可以帮助解决此问题吗?

Currently our system uses the ILNumerics 3D plot cube class with an ILNumerics surface component to display a 3D meshed surface. An aim for our system is to be able to interrogate individual points on the surface from a mouse click on the plot. We have the MouseClick event set up on our plot the problem is I am unsure on how to get the values for the particular point on the surface that has been clicked, could anyone help with this issue?

推荐答案

可以从2D鼠标坐标转换为3D模型"坐标-在某些限制下:

The conversion from 2D mouse coordinates to 3D 'model' coordinates is possible - under some limitations:

  1. 转换不是明确的.鼠标事件仅提供2个维度:X和Y屏幕坐标.在3D模型中,此2D屏幕点后面"可能不止一个点.因此,最好的方法是以3D计算一条线,从相机开始到无限深为止.

  1. The conversion is not unambiguous. The mouse event only provides 2 dimensions: X and Y screen coordinates. In the 3D model there might be more than one point 'behind' this 2D screen point. Therefore, the best you can get is to compute a line in 3D, starting at the camera and ending in infinite depth.

虽然理论上至少可以尝试找到与3D对象的线相交,但ILNumerics当前没有.即使在简单的表面情况下,也很容易构造一个3D模型,该模型在一条以上的点上与线相交.

While in theory it would be possible at least to try to find the crossing of the line with the 3D objects, ILNumerics currently does not. Even in the simple case of a surface it is easy to construct a 3D model which crosses the line at more than one point.

对于简化情况,存在一种解决方案:如果3D中的Z坐标无关紧要,则可以使用通用矩阵转换来获取3D中的X和Y坐标,并且仅使用它们.假设您的图是2D线图或表面图-但只能从 ``上方''(即未旋转的X-Y平面).单击的点的Z坐标可能没有意义.让我们进一步假设,您已经使用ILPanel在常见的Windows应用程序中设置了一个ILScene场景:

For a simplified situation a solution exists: If the Z coordinate in 3D does not matter, one can use common matrix conversions in order to acquire the X and Y coordinates in 3D and use these only. Let's say, your plot is a 2D line plot or a surface plot - but only watched from 'above' (i.e. The unrotated X-Y plane). The Z coordinate of the point clicked may not be of interest. Let's further assume, you have setup an ILScene scene in a common windows application with ILPanel:

private void ilPanel1_Load(对象发送者,EventArgs e){

private void ilPanel1_Load(object sender, EventArgs e) {

var scene  = new ILScene() {
    new ILPlotCube(twoDMode: true) {
        new ILSurface(ILSpecialData.sincf(20,30)) 
    }
}; 
scene.First<ILSurface>().MouseClick += (s,arg) => {
    // we start at the mouse event target -> this will be the 
    // surface group node (the parent of "Fill" and "Wireframe")
    var group = arg.Target.Parent;
    if (group != null) {
        // walk up to the next camera node 
        Matrix4 trans = group.Transform; 
        while (!(group is ILCamera) && group != null) {
            group = group.Parent;
            // collect all nodes on the path up
            trans = group.Transform * trans; 
        }
        if (group != null && (group is ILCamera)) {
            // convert args.LocationF to world coords
            // The Z coord is not provided by the mouse! -> choose arbitrary value
            var pos = new Vector3(arg.LocationF.X * 2 - 1, arg.LocationF.Y * -2 + 1, 0); 
            // invert the matrix.
            trans = Matrix4.Invert(trans); 
            // trans now converts from the world coord system (at the camera) to 
            // the local coord system in the 'target' group node (surface). 
            // In order to transform the mouse (viewport) position, we 
            // left multiply the transformation matrix.
            pos = trans * pos; 
            // view result in the window title
            Text = "Model Position: " + pos.ToString(); 
        }
    }
};
ilPanel1.Scene = scene; 

}

它的作用:在表面组节点上注册一个MouseClick事件处理程序.在处理程序中,它在从单击的目标(表面组节点)到该表面是其子级的下一个摄像头节点的路径上累积转换矩阵.在渲染时,顶点的(模型)坐标由位于每个组节点中的局部坐标转换矩阵进行转换.所有的变换都是累积的,因此顶点坐标最终会在每个摄像机都建立的世界坐标"系统中.因此,渲染从3D模型顶点位置中找到2D屏幕位置.

What it does: it registers a MouseClick event handler on the surface group node. In the handler it accumulates the transformation matrices on the path from the clicked target (the surface group node) up to the next camera node the surface is a child of. While rendering, the (model) coordinates of the vertices are transformed by the local coordinate transformation matrix, hosted in every group node. All transformations are accumulated and so the vertex coordinates end up in the 'world coordinate' system, established by every camera. So rendering finds the 2D screen position from the 3D model vertex positions.

为了从2D屏幕坐标中找到3D位置-一个人必须走另一条路.在该示例中,我们获取每个组节点的变换矩阵,将它们全部相乘,然后反转.这是必需的,因为这样的转换自然会描述从子节点到父节点的转换.在这里,我们需要另一种方法-因此,反转是必要的.

In order to find the 3D position from the 2D screen coordinates - one must go the other way around. In the example, we acquire the transformation matrices for every group node, multiply them all up and invert the resulting transformation matrix. This is needed, because such transforms naturally describe the conversion from the child node to the parent. Here, we need the other way around - hence the inversion is necessary.

此方法可在鼠标位置提供正确的3D坐标.但是,请记住限制!在此,我们不考虑绘图多维数据集的任何旋转(必须不旋转绘图多维数据集),也没有考虑任何投影变换(默认情况下,绘图多维数据集确实使用正交变换,这基本上是一个noop).为了也识别这些变量,您可以相应地扩展示例.

This method gives the correct 3D coordinates at the mouse position. However, keep the limitations in mind! Here, we do not take into account any rotation of the plot cube (the plot cube must be left unrotated) and no projection transforms (plot cubes do use orthographic transform by default, which basically is a noop). In order to recognize those variables as well, you may extend the example accordingly.

这篇关于如何从ILNumerics曲面图上的鼠标单击位置中找到曲面的3D坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆