File: xyz2spherical.c

package info (click to toggle)
openmx 3.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 325,856 kB
  • ctags: 3,575
  • sloc: ansic: 152,655; f90: 2,080; python: 876; makefile: 675; sh: 25; perl: 18
file content (75 lines) | stat: -rw-r--r-- 1,339 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**********************************************************************
  xyz2spherical.c:

     xyz2spherical.c is a subrutine to transform xyz coordinates to
     sherical coordinates

  Log of xyz2spherical.c:

     22/Nov/2001  Released by T.Ozaki

***********************************************************************/

#include <stdio.h>
#include <math.h>
#include "openmx_common.h"

void xyz2spherical(double x, double y, double z,
                   double xo, double yo, double zo,
                   double S_coordinate[3])
{
  double dx,dy,dz,r,r1,theta,phi,dum,dum1,Min_r;

  Min_r = 10e-15;

  dx = x - xo;
  dy = y - yo;
  dz = z - zo;

  dum = dx*dx + dy*dy; 
  r = sqrt(dum + dz*dz);
  r1 = sqrt(dum);

  if (Min_r<=r){

    if (r<fabs(dz))
      dum1 = sgn(dz)*1.0;
    else
      dum1 = dz/r;

    theta = acos(dum1);

    if (Min_r<=r1){
      if (0.0<=dx){

        if (r1<fabs(dy))
          dum1 = sgn(dy)*1.0;
        else
          dum1 = dy/r1;        
  
        phi = asin(dum1);
      }
      else{

        if (r1<fabs(dy))
          dum1 = sgn(dy)*1.0;
        else
          dum1 = dy/r1;        

        phi = PI - asin(dum1);
      }
    }
    else{
      phi = 0.0;
    }
  }
  else{
    theta = 0.5*PI;
    phi = 0.0;
  }

  S_coordinate[0] = r;
  S_coordinate[1] = theta;
  S_coordinate[2] = phi;
}