查找网格中单击的点

发布于 2024-12-04 21:28:35 字数 251 浏览 6 评论 0原文

给定这个网格( https://i.sstatic.net/Nz39I.jpg 是一个梯形/梯形,不是正方形),如何找到用户点击的点?即当用户单击网格中的某个点时,它应该返回 A1 或 D5 等坐标。

我正在尝试为此编写伪代码,但我被困住了。谁能帮助我吗?谢谢!

编辑:我仍然卡住了......有谁知道有什么方法可以找到网格的高度吗?

Given this grid ( https://i.sstatic.net/Nz39I.jpg is a trapezium/trapezoid, not a square), how do you find the point clicked by the user? I.e. When the user clicks a point in the grid, it should return the coordinates like A1 or D5.

I am trying to write pseudo code for this and I am stuck. Can anyone help me? Thanks!

EDIT: I am still stuck... Does anyone know of any way to find the height of the grid?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绮烟 2024-12-11 21:28:35

如果它是真正的透视投影,您可以通过逆投影运行单击点以找到它在 3D 世界中的 X、Z 坐标。该网格具有规则的间距,您可以使用简单的数学来获得 A1、D5 等。

如果它只是您绘制的内容,那么您必须将 Y 坐标与水平线的位置进行比较才能找出哪一行。然后,您需要检查其相对于成角度的线的位置(左/右)以获得列 - 为此,您需要端点的坐标或线的方程。

另一种选择是存储相同的图像,其中每个“方块”都充满不同的颜色。然后,您检查用户在该备用图像中单击的像素的颜色。此方法假设它是固定图像,并且灵活性最差。

If it is a true perspective projection, you can run the click-point through the inverse projection to find it's X,Z coordinates in the 3D world. That grid has regular spacing and you can use simple math to get the A1,D5,etc.

If it's just something you drew, then you'll have to compare the Y coordinates to the positions of the horizontal lines to figure out which row. Then you'll need to check its position (left/right) relative to the angled lines to get the column - for that, you'll need either coordinates of the end-points, or equations for the lines.

Yet another option is to store an identical image where each "square" is flood-filled with a different color. You then check the color of the pixel where the user clicked but in this alternate image. This method assumes that it's a fixed image and is the least flexible.

-黛色若梦 2024-12-11 21:28:35

如果您有网格线端点的坐标,那么

尝试对每条网格线使用内-外测试并找到位置

If you have the coordinates of end points of the grid lines then

Try using the inside-outside test for each grid line and find the position

潦草背影 2024-12-11 21:28:35

由于该网格只是 2D 网格平面的 3D 视图,因此存在投影变换,将网格上的坐标变换为 2D 平面上的坐标。要找到此变换,只需在平面上标记 4 个不同的点(例如边缘),为它们分配 2D 平面上的坐标并求解所得线性方程组即可。

Since this grid is just a 3D view of a 2D grid plane, there is a projective transform that transforms the coordinates on the grid into coordinates on the 2D plane. To find this transform, it is sufficient to mark 4 different points on the plane (say, the edges), assign them coordinates on the 2D plane and solve the resulting linear equation system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文