-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart2PolN.m
More file actions
50 lines (46 loc) · 1.64 KB
/
cart2PolN.m
File metadata and controls
50 lines (46 loc) · 1.64 KB
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
%% Function Cart2PolN
%
%% Introduction:
% Function to convert an n-dimensional cartesian coordinate system into
% n-dimentional spherical polar coordinate system.
%% Function Definition:
% Function takes in the values of the n-dimensional cartesian system
% coordinates of a single point in space in the form of an 1-dimensional
% array in the parameter list and return as output the spherical polar
% version of the same coordinates of the same point as another 1-d array
%% Operation Procedure:
% syntax: polar_coordinates=cart2PolN(cartesian_coordinates)
% NB.: both cartesian_coordinates and polar_coordinates are in the form of
% 1-d arrays or row vectors
%% Variable List:
% List of variables in order of declaration and usage
% polars: spherical polar coordinate values of a point that is returned as
% the result. (vector)
% cartesn: cartesian coordinate values of a point that is taken in as input
% parameters to the function.(vector)
% dim: dimensions of cartesn and polar
% sumD2: sum of the squares of dimensions.
% sumD1: reverse sum of the squares of dimensions.
% i: loop variable
%% Function Code
function polars=cart2PolN(cartesn)
dim=size(cartesn);
polars=zeros(dim);
sumD2=0;
for i=1:dim(2)
sumD2= sumD2 + power(cartesn(i),2);
end
polars(1)=sqrt(sumD2);
sumD1=0;
for i=2:dim(2)
sumD1=sumD1+power(cartesn(i-1),2);
if(i==dim(2))
polars(i)=2*acot((cartesn(i-1)+sqrt(power(cartesn(i),2)+power(cartesn(i-1),2)))/cartesn(i));
else
polars(i)=acot(cartesn(i-1)/sqrt(sumD2-sumD1));
end
end
end
%% Copyrights
% (c) Programmed by Bishal Biswas
% email: b.biswas_94587@ieee.org