This is the standard formula for up=z:
Vector3D Vector3D::GetSphericalCoordinate() {
double xOutput = sqrt(x*x + y*y + z*z);
double yOutput = acos(z/xOutput);
yOutput = yOutput * 180.0 / 3.14159265;
double zOutput = atan2(y, x);
zOutput = zOutput * 180.0 / 3.14159265;
return Vector3D(xOutput, yOutput, zOutput);
}
Since the y and z value is rotated, here is the formula for up=y:
Vector3D Vector3D::GetSphericalCoordinate() {
double xOutput = sqrt(x*x + y*y + z*z);
double yOutput = acos(y/xOutput);
yOutput = yOutput * 180.0 / 3.14159265;
double zOutput = atan2(z, x);
zOutput = zOutput * 180.0 / 3.14159265;
return Vector3D(xOutput, yOutput, zOutput);
}
double xOutput = sqrt(x*x + y*y + z*z);
double yOutput = acos(y/xOutput);
yOutput = yOutput * 180.0 / 3.14159265;
double zOutput = atan2(z, x);
zOutput = zOutput * 180.0 / 3.14159265;
return Vector3D(xOutput, yOutput, zOutput);
}
I use this second code for my program. We also have to do the same modification for spherical to cartesian coordinate. Instead of using this for up=z:
double xOutput = x * getSinValue(y) * getCosValue(z);
double yOutput = x * getSinValue(y) * getSinValue(z);
double zOutput = x * getCosValue(y);
double zOutput = x * getCosValue(y);
I did this for up=y:
double xOutput = x * getSinValue(y) * getCosValue(z);
double zOutput = x * getSinValue(y) * getSinValue(z);
double zOutput = x * getSinValue(y) * getSinValue(z);
double yOutput = x * getCosValue(y);
Notice that my phi and theta is y and z respectively. So I represent my spherical coordinate as a 3D Vector (radius, phi, theta). Phi is identical to elevation, and theta is the azimuth.
No comments:
Post a Comment