Commit 8c3ba8c5 authored by Laurent Belcour's avatar Laurent Belcour

Adding stereographic un-projection to cartesian coordinates

parent cf752110
......@@ -114,6 +114,27 @@ void params::to_cartesian(const double* invec, params::input intype,
outvec[5] = cos(invec[2]);
break;
case params::STEREOGRAPHIC:
{
// Project the 2D direction on the surface invec[0,1] to the View
// vector outvec[0,1,2]
const double normL = invec[0]*invec[0] + invec[1]*invec[1];
const double alphL = (1.0 - normL) / (1.0 + normL);
outvec[0] = invec[0] + alphL;
outvec[1] = invec[1] + alphL;
outvec[2] = alphL;
// Project the 2D direction on the surface invec[2,3] to the Light
// vector outvec[3,4,5]
const double normV = invec[2]*invec[2] + invec[3]*invec[3];
const double alphV = (1.0 - normV) / (1.0 + normV);
outvec[3] = invec[2] + alphV;
outvec[4] = invec[3] + alphV;
outvec[5] = alphV;
break;
}
// 6D Parametrization
case params::CARTESIAN:
memcpy(outvec, invec, 6*sizeof(double));
......
......@@ -15,35 +15,6 @@
#include <cstdlib>
#include <cmath>
#define EPSILON 1.0E-5
vec coord(vec V, vec L, vec X, vec Y, vec N)
{
vec pV = V-dot(V,N)*N;
vec vCoord(2);
vCoord[0] = dot(pV,X);
vCoord[1] = dot(pV,Y);
vCoord /= (1.0+dot(V,N));
vec pL = L-dot(L,N)*N;
vec lCoord(2);
lCoord[0] = dot(pL,X);
lCoord[1] = dot(pL,Y);
lCoord /= (1.0+dot(L,N));
if (norm(lCoord)>EPSILON)
{
vec lDir = normalize(lCoord);
vec temp(2);
temp[0] = lDir[0]*vCoord[0] + lDir[1]*vCoord[1];
temp[1] = lDir[0]*vCoord[1] - lDir[1]*vCoord[0];
vCoord = temp;
}
return vCoord;
}
int main(int argc, char** argv)
{
QApplication app(argc, argv, false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment