Commit 848c7178 authored by Marco Berzborn's avatar Marco Berzborn

added translation, rotation and scaling to itaCoordinates

parent 004eb62c
...@@ -66,7 +66,7 @@ classdef itaCoordinates ...@@ -66,7 +66,7 @@ classdef itaCoordinates
elseif isstruct(varargin{1}) elseif isstruct(varargin{1})
%% struct input/convert %% struct input/convert
fieldName = fieldnames(varargin{1}); fieldName = fieldnames(varargin{1});
for ind = 1:numel(fieldName); for ind = 1:numel(fieldName)
try try
this.(fieldName{ind}) = varargin{1}.(fieldName{ind}); this.(fieldName{ind}) = varargin{1}.(fieldName{ind});
catch errmsg catch errmsg
...@@ -294,29 +294,29 @@ classdef itaCoordinates ...@@ -294,29 +294,29 @@ classdef itaCoordinates
% do nothing % do nothing
case 'sph' case 'sph'
% sph2cart % sph2cart
r = this.mCoord(:,1); r = this.mCoord(:,1); %#ok<PROP>
theta = this.mCoord(:,2); theta = this.mCoord(:,2); %#ok<PROP>
phi = this.mCoord(:,3); phi = this.mCoord(:,3); %#ok<PROP>
% apply builtin transformation % apply builtin transformation
[x,y,z] = sph2cart(phi, pi/2 - theta, r); [x,y,z] = sph2cart(phi, pi/2 - theta, r); %#ok<PROP>
this.mCoord = [x y z]; this.mCoord = [x y z]; %#ok<PROP>
this.mCoordSystem = 'cart'; this.mCoordSystem = 'cart';
case 'cyl' case 'cyl'
% cyl2cart % cyl2cart
rho = this.mCoord(:,1); rho = this.mCoord(:,1); %#ok<PROP>
phi = this.mCoord(:,2); phi = this.mCoord(:,2); %#ok<PROP>
[x,y] = pol2cart(phi,rho); [x,y] = pol2cart(phi,rho); %#ok<PROP>
this.mCoord(:,[1 2]) = [x y]; this.mCoord(:,[1 2]) = [x y]; %#ok<PROP>
this.mCoordSystem = 'cart'; this.mCoordSystem = 'cart';
case 'pol' case 'pol'
r = this.mCoord(:,1); r = this.mCoord(:,1); %#ok<PROP>
alpha = this.mCoord(:,2); alpha = this.mCoord(:,2); %#ok<PROP>
beta = this.mCoord(:,3); beta = this.mCoord(:,3); %#ok<PROP>
z = r.*sin(alpha).*sin(beta); z = r.*sin(alpha).*sin(beta); %#ok<PROP>
rcoselev = r .* cos(beta); rcoselev = r .* cos(beta); %#ok<PROP>
x = rcoselev .* sin(alpha); x = rcoselev .* sin(alpha); %#ok<PROP>
y = r.*cos(alpha); y = r.*cos(alpha); %#ok<PROP>
this.mCoord = [x y z]; this.mCoord = [x y z]; %#ok<PROP>
this.mCoordSystem = 'cart'; this.mCoordSystem = 'cart';
otherwise otherwise
...@@ -327,16 +327,16 @@ classdef itaCoordinates ...@@ -327,16 +327,16 @@ classdef itaCoordinates
switch this.mCoordSystem switch this.mCoordSystem
case 'cart' case 'cart'
% cart2sph % cart2sph
x = this.mCoord(:,1); x = this.mCoord(:,1); %#ok<PROP>
y = this.mCoord(:,2); y = this.mCoord(:,2); %#ok<PROP>
z = this.mCoord(:,3); z = this.mCoord(:,3); %#ok<PROP>
% apply builtin transformation % apply builtin transformation
[phiMod, thetaMod, r] = cart2sph(x,y,z); [phiMod, thetaMod, r] = cart2sph(x,y,z); %#ok<PROP>
% phi = 0..2*pi % phi = 0..2*pi
% theta = 0..pi % theta = 0..pi
phi = mod(phiMod, 2*pi); phi = mod(phiMod, 2*pi); %#ok<PROP>
theta = pi/2 - thetaMod; theta = pi/2 - thetaMod; %#ok<PROP>
this.mCoord = [r theta phi]; this.mCoord = [r theta phi]; %#ok<PROP>
this.mCoordSystem = 'sph'; this.mCoordSystem = 'sph';
case 'sph' case 'sph'
% do nothing % do nothing
...@@ -356,16 +356,16 @@ classdef itaCoordinates ...@@ -356,16 +356,16 @@ classdef itaCoordinates
switch this.mCoordSystem switch this.mCoordSystem
case 'cart' case 'cart'
% cart2cyl % cart2cyl
x = this.mCoord(:,1); x = this.mCoord(:,1); %#ok<PROP>
y = this.mCoord(:,2); y = this.mCoord(:,2); %#ok<PROP>
z = this.mCoord(:,3); z = this.mCoord(:,3); %#ok<PROP>
% apply builtin transformation % apply builtin transformation
[phiMod, rho] = cart2pol(x,y); [phiMod, rho] = cart2pol(x,y); %#ok<PROP>
% phi = 0..2*pi % phi = 0..2*pi
phi = mod(phiMod, 2*pi); phi = mod(phiMod, 2*pi); %#ok<PROP>
this.mCoord = [rho phi z]; this.mCoord = [rho phi z]; %#ok<PROP>
this.mCoordSystem = 'cyl'; this.mCoordSystem = 'cyl';
case 'sph' case 'sph'
% sph2cyl % sph2cyl
...@@ -409,20 +409,20 @@ classdef itaCoordinates ...@@ -409,20 +409,20 @@ classdef itaCoordinates
switch this.mCoordSystem switch this.mCoordSystem
case 'cart' case 'cart'
% cart2pol % cart2pol
x = this.mCoord(:,1); x = this.mCoord(:,1); %#ok<PROP>
y = this.mCoord(:,2); y = this.mCoord(:,2); %#ok<PROP>
z = this.mCoord(:,3); z = this.mCoord(:,3); %#ok<PROP>
% apply builtin transformation % apply builtin transformation
hypotxy = hypot(x,y); hypotxy = hypot(x,y); %#ok<PROP>
r = hypot(hypotxy,z); r = hypot(hypotxy,z); %#ok<PROP>
thetaMod = acos(y./r); thetaMod = acos(y./r); %#ok<PROP>
phiMod = atan2(z,x); phiMod = atan2(z,x); %#ok<PROP>
% phi = 0..2*pi % phi = 0..2*pi
% theta = 0..pi % theta = 0..pi
beta = mod(phiMod, 2*pi); beta = mod(phiMod, 2*pi); %#ok<PROP>
alpha = thetaMod; alpha = thetaMod; %#ok<PROP>
this.mCoord = [r alpha beta]; this.mCoord = [r alpha beta]; %#ok<PROP>
this.mCoordSystem = 'pol'; this.mCoordSystem = 'pol';
case 'sph' case 'sph'
% sph2pol % sph2pol
...@@ -458,6 +458,42 @@ classdef itaCoordinates ...@@ -458,6 +458,42 @@ classdef itaCoordinates
end end
end end
% Translation in x,y,z
% Syntax is itaCoord = itaCoord.translate([x,y,z]) as this is not a handle class
function this = translate(this, txyz)
if strcmp(this.mCoordSystem, 'cart')
transCoords = (makehgtform('translate',txyz) * [this.mCoord, ones(this.nPoints,1)].').';
this.mCoord = transCoords(:,1:3);
else
this = makeCart(this);
this = translate(this, txyz);
end
end
% Rotation around x,y,z-axis as defined by the Cartesian coordinate system in Matlab
% Syntax is itaCoord = itaCoord.rotate([x,y,z]) as this is not a handle class
function this = rotate(this, angles)
if strcmp(this.mCoordSystem, 'cart')
rotCoords = (makehgtform('xrotate',angles(1),'yrotate',angles(2),'zrotate',angles(3)) * [this.mCoord, ones(this.nPoints,1)].').';
this.mCoord = rotCoords(:,1:3);
else
this = makeCart(this);
this = rotate(this, angles);
end
end
% Scaling in x,y,z
% Syntax is itaCoord = itaCoord.scale([x,y,z]) as this is not a handle class
function this = scale(this, sxyz)
if strcmp(this.mCoordSystem, 'cart')
scaleCoords = (makehgtform('scale',sxyz) * [this.mCoord, ones(this.nPoints,1)].').';
this.mCoord = scaleCoords(:,1:3);
else
this = makeCart(this);
this = scale(this, sxyz);
end
end
function this = resize(this,n) function this = resize(this,n)
if n > size(this.mCoord,1) if n > size(this.mCoord,1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment