从 X,Y 坐标计算球体上的纬度/经度?

发布于 2024-11-07 11:00:53 字数 982 浏览 3 评论 0原文

我想获取 3D 球体上的纬度和经度,具体取决于鼠标 X、Y。 我明白我必须使用三角学。问题是球体被放入透视图中,至少我猜问题是因为我的计算:

radius *= (width / 2.0f);
    float y = (mouseY - (height / 2.0f)) / radius;
    latitude = (float) -Math.toDegrees(Math.asin(y));

和经度:

    float x = (float) ((mouseX - (width / 2.0f)) / (radius));
    longitude = (float) (90 - Math.toDegrees(Math.acos(x)));

为了简单起见,半径= 1 在开始(从屏幕的中心到边缘)。我们也忽略任何旋转。

问题:
我的问题是我没有得到正确的价值观。我离中心越远;误差越大。
正如所提到的,我想这与我使用透视图(视锥体)有关。但我不知道如何解决它,以及真正导致这个问题的原因是什么。

如果有帮助的话,我的视角设置为 45 度,宽度/高度比为 0.6。因此,使用以下公式: tan(2*atan(1,x)/0.6) = x,我将球体 x (~-4.17) 平移到屏幕(在 z 上)。

我的预测:

        gl.glViewport(0, 0, width, height); 
    gl.glMatrixMode(GL10.GL_PROJECTION); 
    gl.glLoadIdentity();

   GLU.gluPerspective(gl, 45f, (float) width / (float) height, 0.1f,
            100.0f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);

    gl.glLoadIdentity();

I want to get the latitude and longitude on a 3D sphere, depending on Mouse X,Y.
Iv'e understood that i have to use trigonometry. The problem is that the sphere is put into a perspective, at least that's what i guess the problem is because with my calculations:

radius *= (width / 2.0f);
    float y = (mouseY - (height / 2.0f)) / radius;
    latitude = (float) -Math.toDegrees(Math.asin(y));

and longitude:

    float x = (float) ((mouseX - (width / 2.0f)) / (radius));
    longitude = (float) (90 - Math.toDegrees(Math.acos(x)));

For simplicity, radius = 1 at the beginning (from center to edge of the screen). Also we ignore any rotation.

Problem:
My problem is that i don't get the right values. The further i move away from center; the bigger the error becomes.
As is mentioned, i guess this has to do with the fact that i'm using a perspective (frustum). But i can't figure out how to solve it, and what's really causing this problem.

If it's to any help, my perspective is set up to 45 degrees, and my width / height ration is 0.6. Therefor with this fromula: tan(2*atan(1,x)/0.6) = x, I translate the sphere x (~-4.17) into the screen (on z).

My projection:

        gl.glViewport(0, 0, width, height); 
    gl.glMatrixMode(GL10.GL_PROJECTION); 
    gl.glLoadIdentity();

   GLU.gluPerspective(gl, 45f, (float) width / (float) height, 0.1f,
            100.0f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);

    gl.glLoadIdentity();

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

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

发布评论

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

评论(1

孤蝉 2024-11-14 11:00:53

您需要做的是找到从相机原点开始并穿过鼠标光标位置处的眼平面的光线。这可以通过将透视投影变换的逆变换应用于鼠标光标的视口坐标来获得表示鼠标位置的世界空间点来完成。

该射线与球体的交点(如果存在)将是一个表面点,您可以使用简单的三角学来计算纬度和经度值。

What you need to do is find the ray which starts at the camera's origin and goes through the eye plane at the mouse cursor's position. This can be done by applying the inverse of your perspective projection transform to the mouse cursor's viewport coordinates to get a world-space point that represents the mouse's position.

The intersection of this ray with your sphere, if one exists, will be a surface point that you can use to compute latitude and longitude values, using simple trigonometry.

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