1

Following is the conversion for spherical to cartesian coordinate

X = r cosθ sinΦ 
Y = r sinθ sinΦ 
Z = rcosΦ

we are using the reverse computation to compute spherical coordinate from cartesian coordinate which is defined as

r = √(x^2+y^2+z^2 ) 
θ = atan⁡(Y./X) 
Φ = atan⁡(√(X^2+Y^2 )./Z)

The problem arises when Y and X are zero so θ can take any arbitrary value so during Matlab computations this results in NAN(not a number ) which makes θ discontinuous. Is there any interpolation technique to remove this discontinuity and how to interpret θ in this case.

θ is a matrix at various point and it gives following result it has jumps and black patched that represent discontinuity whereas I need to generate the following image with smooth variation. Please see the obtained theta and correct theta variation by clicking on the link and suggest some changes. Discontinuous_Theta_variation Correct Theta variation

Nikita Chopra
  • 440
  • 9
  • 22

1 Answers1

1

While doing conversion from Cartesian to Spherical coordinate system, however the formulas which are written here are correct but you first need to understand their physical significance.

'r' is the distance of the point from origin. θ is the angle from the positive x axis to the line which is made by projecting the given point to XY plane. And Φ being the angle from positive z-axis to the line which joins origin and given point. http://www.learningaboutelectronics.com/Articles/Cartesian-rectangular-to-spherical-coordinate-converter-calculator.php#answer

So say, for a point which has X and Y coordinates as 0, that means it lies on z axis and hence, its projection on XY plane lies on the origin. So we cannot exactly determine the angle of origin from X axis. But please note that, since the point lies on Z axis, so Φ=0 or pi (depending whether Z is positive or negative).

So while coding this problem, you may adapt this approach that you first check for Φ, if it is 0 or pi then theta = 0 (by default). I hope this serves the purpose.

  • NAN( Not a number ) in Matlab by default visualized as zero and as you can see in the Image 1 it results in discontinuity . Theta can have any value between o to 2*pi but after checking matlab function cart2sph it shows that matlab's implementation considers default value as pi/2 . So are there any spatial interpolation techniques that can resolve this problem. – Nikita Chopra Jan 26 '16 at 04:22