|
 |
"Maetes" <nomail@nomail> wrote:
> Tanks, but unfortunately it crashes in the first line. After I fixed it, the
> result wasnt as expected. I tried more than an hour, without success.
> I will give it somewhen later anoter try.
Nein.
Try this alternate version:
returns a vector <RA, Declination, Radius> with angles in degrees and RA
normalized to [0,360).
#declare MA_Deg2Vector_RA_Offset = 0;
// Forward: (RA, Dec, Radius) -> <x, y, z>
#macro MA_Deg2Vector(S_RA, S_Dec, S_Radius)
#local S_Rect = radians(S_RA + MA_Deg2Vector_RA_Offset);
#local S_DecRad = radians(S_Dec);
#local S_X = S_Radius * sin(S_DecRad) * cos(S_Rect);
#local S_Y = S_Radius * cos(S_DecRad);
#local S_Z = S_Radius * sin(S_DecRad) * sin(S_Rect);
#local V_Out = <S_X, -S_Y, S_Z>;
V_Out
#end
// Inverse: <x, y, z> -> <RA, Dec, Radius>
#macro MA_Vector2Deg(V_In)
// Undo the original Y inversion
#local S_X = V_In.x;
#local S_Y = -V_In.y;
#local S_Z = V_In.z;
#local S_Radius = sqrt(S_XS_X + S_YS_Y + S_Z*S_Z);
// Handle the degenerate zero-length vector
#if (S_Radius < 1e-12)
<0, 0, 0>
#else
// θ (the "rectangular" angle used in the forward mapping) from x,z
// NOTE: atan2(y, x) in POV-Ray; we want θ = atan2(z, x).
#local S_Theta = atan2(S_Z, S_X); // radians
// Recover sin(Dec) with its sign using both x & z and the θ we just found:
// x = r*sin(Dec)*cosθ, z = r*sin(Dec)*sinθ
// => x*cosθ + z*sinθ = r*sin(Dec)
#local S_SinDec = (S_X * cos(S_Theta) + S_Z * sin(S_Theta)) / S_Radius;
// Clamp for numeric safety
#if (S_SinDec > 1) #local S_SinDec = 1; #end
#if (S_SinDec < -1) #local S_SinDec = -1; #end
#local S_Dec = degrees(asin(S_SinDec));
#local S_RA = degrees(S_Theta) - MA_Deg2Vector_RA_Offset;
// Normalize RA into [0, 360)
#while (S_RA < 0)
#local S_RA = S_RA + 360;
#end
#while (S_RA >= 360)
#local S_RA = S_RA - 360;
#end
<S_RA, S_Dec, S_Radius>
#end
#end
// Example round-trip test
//#declare V1 = MA_Deg2Vector(35, -20, 10);
//#declare P1 = MA_Vector2Deg(V1); // P1 = <RA, Dec, R>
//#debug concat("RA=",str(P1.x,0,3),", Dec=",str(P1.y,0,3),",
R=",str(P1.z,0,3),"\n")
// end of code
Post a reply to this message
|
 |