计算光球内部元素的位置 [英] Calculate the position of an element inside a photosphere

查看:86
本文介绍了计算光球内部元素的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 a-sky 元素进行显示

我的问题是我必须在光球体内放置一些必须像标记一样工作的元素;但我不明白如何计算这些元素的 x-y-z 头寸。

My problem is that I have to place inside the photosphere some elements that must act like 'markers'; but I do not understand how to calculate the x-y-z position of those elements.

例如,假设我有一幅尺寸为4096x2048的图片,我想在169,1349处放置一个简单的盒子。

For example, lets say that I have a picture with size 4096x2048 and I want to place a simple box at 169,1349.

我知道球体的半径(5000),我知道盒子的大小(我可以选择一个合适的大小),我只知道如何获取像素位置的位置(169,

I know the radius of the sphere (5000), i know the size of the box (I can choose a convenient size), I only know how to retrieve the position of that "pixel position" (169,1349) inside the sphere.

有提示吗?

推荐答案

对不起回答我自己的问题,但这一次真的很容易:

Sorry for answering my own question but this time was really easy:

function sphericalCoordsToVector3(distance, latitude, longitude){
  return new THREE.Vector3(
    distance * -Math.cos(latitude) * Math.cos(longitude),
    distance * Math.sin(latitude),
    distance * -Math.cos(latitude) * Math.sin(longitude)
  );
}

距离

就记录而言,相反的函数是:

Just for the records, the opposite function is:

function vector3ToSphericalCoords(vector) {
  var phi = Math.acos(vector.y / Math.sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z));
  var theta = Math.atan2(vector.x, vector.z);
  return {
    longitude: theta < 0 ? -theta : (Math.PI * 2.0) - theta,
    latitude: (Math.PI / 2.0) - phi
  };
};

原始功能可以在这里找到: mistic100 / Photo-Sphere-Viewer (还有一些不错的功能可以获取位置屏幕中元素的位置)

The original functions can be found here: mistic100/Photo-Sphere-Viewer (there are also nice functions to get the position of the element inside the screen)

这篇关于计算光球内部元素的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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