我有一个以正交投影为中心绘制的单位球体(半径为 1)。
球体可以自由旋转。
如何确定用户单击球体上的点?
Given:
- 显示器的高度和宽度
- 投影圆的半径,以像素为单位
- 用户点击点的坐标
假设左上角为 (0,0),则 x 值随着向右移动而增加,y 值随着向下移动而增加。
将用户的点击点转换到地球的坐标空间中。
userPoint.x -= monitor.width/2
userPoint.y -= monitor.height/2
userPoint.x /= circleRadius
userPoint.y /= circleRadius
找到交点的 z 坐标。
//solve for z
//x^2 + y^2 + z^2 = 1
//we know x and y, from userPoint
//z^2 = 1 - x^2 - y^2
x = userPoint.x
y = userPoint.y
if (x^2 + y^2 > 1){
//user clicked outside of sphere. flip out
return -1;
}
//The negative sqrt is closer to the screen than the positive one, so we prefer that.
z = -sqrt(1 - x^2 - y^2);
现在您知道了 (x,y,z) 交点,您可以找到纬度和经度。
假设用户面对的地球中心是0E 0N,
longitude = 90 + toDegrees(atan2(z, x));
lattitude = toDegrees(atan2(y, sqrt(x^2 + z^2)))
如果旋转球体使得 0E 子午线不直接面向观察者,则从经度中减去旋转角度。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)