Klaim
Reputation
1,669
Top tag
Next privilege 2,000 Rep.
 Aug 30 awarded Notable Question Jul 20 awarded Yearling Apr 10 awarded Popular Question Feb 4 awarded Notable Question Dec 13 awarded Popular Question Jul 31 awarded Notable Question Jul 20 awarded Yearling Jul 2 awarded Curious May 31 comment What are the pros and cons of HLSL vs GLSL vs cg? @NicolBolas That part was added but I'm not the author. I couldn't find any link at the time but there is apparently an effective lack of update of CG so I guess it was true. Also it looks like APIs will change again soon, so... Feb 11 awarded Nice Question Feb 7 awarded Popular Question Jan 26 comment Spherical coordinate from cartesian coordinate Thanks. I'll not to never again try to do maths at 2am in the morning... Jan 26 comment Spherical coordinate from cartesian coordinate After having use this code, I found that there is an issue: when I ask for `from_cartesian( UNIT_X )` I get a phi which is negative (-90degree) while I should have a positive value (270degree). This I believe makes my unit tests get very wrong. I have no idea how to fix this. Dec 12 accepted Spherical coordinate from cartesian coordinate Dec 6 comment Spherical coordinate from cartesian coordinate It my mistake again, I did atan2( y, hypot(x,z)) instead of atan2( hypot(x,z), y). Now it seems to work almost perfectly. The problem I see is positions around negative Z being avoided (I'm using a moving cursor using the spherical coordinates to check visually). I think the issue might be related to a chain of transformations I'm doing, I'm checking that right now. Dec 6 comment Spherical coordinate from cartesian coordinate Howver, my problem don't seem to be really fixed yet. Dec 6 comment Spherical coordinate from cartesian coordinate It don't seem to work either. I'm not sure where is the problem. Dec 6 comment Spherical coordinate from cartesian coordinate My mistake, I assumed that radius was already the value of hypot(x,z). I'll try that right now. Dec 6 comment Spherical coordinate from cartesian coordinate It helps understanding the issue, but not fully, because it was not clear to me how to work around the sign and pi thing. I learnt about atan2 which apparently does the work efficiently. Dec 6 comment Spherical coordinate from cartesian coordinate Ok now I think I get it. I try the following code: SphereVector result = SphereVector::ZERO; result.radius = cartesian.length(); if( result.radius == 0 ) return result; result.phi = Math::ATan2( cartesian.z, cartesian.x ); result.theta = Math::ACos( cartesian.y / result.radius ); return result; It seems to be working except for positions close to negative Z which seems to be buggy, but it might be something else in my code that's wrong.