Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %cylyndric: (rho, alpha, z)
- % rho - the distance from Z axis
- % alpha - angle around the Z axis
- % z - the distance above the XY plane
- %spheric: (r, alpha, epsilon)
- % r - the diameter of the sphere
- % alpha - angle around the Z axis
- % epsilon - angle from the XY plane
- function [r, alpha, epsilon] = mycyl2sph(varargin)
- switch nargin
- %One parameter - matrix full of points
- case 1
- Xi = varargin{1};
- [h, w] = size(Xi);
- r = zeros(h, w);
- for i = 1:w
- point = Xi(:,i);
- [point(1), point(2), point(3)] = mycyl2sph(point(1), point(2),point(3));
- r(:,i) = point;
- end
- case 3
- rho = varargin{1};
- %Alpha will be unchanged
- alpha = varargin{2};
- z = varargin{3};
- r = sqrt(rho^2 + z^2);
- %Special cases where rho is 0 - in that case we can't divide
- %with it
- if(rho==0)
- %If z is non-zero epsilon will point straight up or down
- if(z>0)
- epsilon=pi/2;
- elseif(z<0)
- epsilon=-pi/2;
- %If z is zero, everything is zero...
- else
- epsilon=0;
- end
- %Normal calculation using tangents
- else
- epsilon = atan(z/rho);
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment