MATLAB: How do I get 3D coordinates from a user-click?

僤鯓⒐⒋嵵緔 提交于 2019-12-24 13:32:55

问题


I'm using Matlab to create a small chess game for one of my courses this semester. The thing I'm having trouble with is having the user be able to select one of the chess pieces.

To simplify things, I'm making it so that the user selects a piece by clicking on the square that the chess piece resides on rather than clicking the piece itself (which I assume would be much more difficult). I know how to get the x and y coordinates of the view-port, but how do I transform these coordinates into 3-space coordinates?

I know that there are multiple x,y,z coordinates associated with each view-port coordinate, but I'm only interested in the x,y,z coordinate where z = 0 (since the board itself is in the x,y plane that intersects the z axis where z = 0).


回答1:


You may want to have a look at select3d from the file exchange. It allows you to select patch objects in 3D (which is probably how you want to create your board, anyway).




回答2:


Not MATLAB-specific, but this may help: Given the camera parameters and the click location, you could project a ray into the scene and test for intersections, but it would probably be a whole lot easier to just consider the inverse problem: Map your chess-grid squares onto screen coordinates, and then just compare in 2D against the click location. Note that this is already being done in rendering the scene.



来源:https://stackoverflow.com/questions/2784155/matlab-how-do-i-get-3d-coordinates-from-a-user-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!