记录一下。
描述:有一张全景图,和一个模型,需要求模型中每个点映射到全景图中所对应的坐标。
本来想用PPT画图,嫌太麻烦了,就手画传图了。
void calcSphereUV(const Vec3f& V)
{
//BasePoint为球心坐标
float x = V[0] - BasePoint[0];
float y = V[1] - BasePoint[1];
float z = V[2] - BasePoint[2];
float R = sqrt(x * x + y * y + z * z);
float theta = asin(z / R);//-90~90
float phi = atan(y / x);
if (x >= 0)
{
phi = phi + (3.0 / 2.0 * PI);
}
else if (x < 0)
{
phi = PI / 2.0 + phi;
}
theta = PI / 2.0 - theta;
//cout << "theta=" << theta / PI * 180.0 << endl;
//cout << "phi=" << phi / PI * 180.0 << endl;
Vec2f tmp;
tmp[0] = phi / PI / 2.0;
tmp[1] = theta / PI;
//cout << "U = " << tmp[0] << endl;
//cout << "V = " << tmp[1] << endl << endl;
}