Advertisement
Darker666

Spheric to cylindric conversion matlab

Feb 28th, 2015
224
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %cylyndric: (radius ρ, azimuth φ,     elevation z)  (rho, alpha, z)       (r,   theta, z)
  2. %spheric:   (radius r, azimuth φ,  inclination θ,)  (r,   alpha, epsilon) (rho, theta, phi)
  3.  
  4. function [rho, alpha, z] = mysph2cyl(varargin)
  5.     switch nargin
  6.         case 1
  7.             Xi = varargin{1};
  8.             [w,h] = size(Xi);
  9.             rho = zeros(w, h);
  10.             for i = 1:Xi
  11.                 point = Xi(:,i);
  12.                 [point(1), point(2), point(3)] =mysph2cyl(point(1), point(2),point(3));
  13.                 rho(:,i) = point;
  14.             end
  15.         case 3
  16.             r = varargin{1};
  17.             alpha = varargin{2};
  18.             epsilon = varargin{3};
  19.             %The other two are simple:
  20.             rho = r*sin(epsilon);
  21.             z = r*cos(epsilon);
  22.     end
  23. end
Advertisement
RAW Paste Data Copied
Advertisement