title: How to convert spherical to cartesian coordinates in postgresql
body: <p>I tried to convert spherical to cartesian coordinates in postgresql.</p>
  
  <p>Illustrations:</p>
  
  <ul>
  <li>Input: elevation, azimuth</li>
  <li>Output: x, y, z</li>
  </ul>
  
  <p>Sample data</p>
  
  <pre><code>hour    Elevation   Azimuth x   y   z
  06:29:00    -0.833  67.72   0.379094033 0.9252439455    -0.0145380682
  07:00:00    6.28    68.75   0.3602640625    0.9264147202    0.1093872546
  08:00:00    20.15   69.78   0.3244723425    0.880938168 0.3444787991
  09:00:00    34.06   69.39   0.2916199874    0.7754290366    0.5600603468
  </code></pre>
  
  <p>Any queries or functions are there to convert?</p>
  
  <p>I tried to create a function</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION ST_spr2cart(point_a geometry, point_b geometry)
    RETURNS geometry AS
  $BODY$SELECT ST_SetSRID(ST_MakePoint(
    Cos(a1) * Cos(b1),
    Cos (a1) * sin (b1),
    sin(a1)), ST_SRID($1))
  FROM (SELECT
    ST_m($1) AS a1, 
    ST_m($2) AS b1
  ) AS f$BODY$
  LANGUAGE sql IMMUTABLE;
  </code></pre>
  
  <p>Function created but when I execute it, there is an error.</p>