Rotating Magnetic field matrixs: Can you tell me if imrotate & headtranslation.m are same or not?

1 vue (au cours des 30 derniers jours)
I used imrotate command to do the rotation for magnetic field? but i have another function called heatranslation.m to rotate....i am not sure if it is same as imrotate or different????
function headTranslation(fileIn,fileOut,Angle)
%function headTranslation(fileIn,fileOut,Angle)
%
% fileIn =Input model file name
% fileOut =File name for output moel
% Angle =Angle to rotate model
%
% This function rotates a head model around its midline axis (rotates each
% transverse plane)
%
% NOTE: Requires "savedata.m" function found in the creategeometry
% directory
% Author: D. Stough
% Date: 6.25.2010
% History
% 6.1.2011 D. Stough Modified to function call
% headTranslation('TestHead_1p5875.dat','TestHead_45deg.dat',-pi/4);
% clear all
% close all
% clc
%Set Default Angle
if nargin < 3
Angle=-pi/4; %CHANGE ANGLE
end
%Load Model
head_model=load(fileIn); %CHANGE MODEL
xMax=max(head_model(:,1));xMin=max(head_model(:,1));
yMax=max(head_model(:,2));yMin=max(head_model(:,2));
xCenter=(xMax-yMax)/2+xMin;
yCenter=(yMax-yMax)/2+yMin;
%Initialize New Model Array
newHeadModel=[];
%Rotate each XY plane
for i = min(head_model(:,3)):max(head_model(:,3))
%Display Progress for User
disp(['z= ' num2str(i) '/ ' num2str(max(head_model(:,3)))])
%Find Head-Points for ith XY plane
[RowX ColX]=find(head_model(:,3)==i);
%Define Array of Head Point Locations
xData=head_model(RowX,1);
yData=head_model(RowX,2);
epsilon=head_model(RowX,4);
sigma=head_model(RowX,5);
% % [X,Y]=meshgrid(1:2*xCenter,1:2*yCenter);
% %
% % fill=zeros(4*xCenter*yCenter,4);
% %
% % fill(:,1)=reshape(X,[],1);
% % fill(:,2)=reshape(Y,[],1);
% %
% % for j=1:length(RowX)
% % fill((xData(j)-1)*2*xCenter+yData(j),3)=epsilon(j);
% % fill((xData(j)-1)*2*xCenter+yData(j),4)=sigma(j);
% % end
%Recombine Into New Array for the XY plane
fill=[xData yData epsilon sigma];
%Add Corner Points for Frame of reference for each level
fill=[fill; 1 1 1.0 0.0; 1 2*yCenter 1.0 0.0; 2*xCenter 1 1.0 0.0; 2*xCenter 2*yCenter 1.0 0.0]; %#ok<AGROW>
X=fill(:,1)';
Y=fill(:,2)';
shiftObj=[X;Y];
%Enter Shift Around Z Axis in Radians
zAngleTransformation=[...
cos(Angle) -sin(Angle); ...
sin(Angle) cos(Angle) ];
%Perform Rotation
xyTransform=zAngleTransformation*shiftObj;
%Recenter the Head in the 1st Quadrant
xShift=floor(min(xyTransform(1,:)));
yShift=floor(min(xyTransform(2,:)));
if xShift<1
xyTransform(1,:)=xyTransform(1,:)+abs(xShift)+1;
end
if yShift<1
xyTransform(2,:)=xyTransform(2,:)+abs(yShift)+1;
end
xyTransform=xyTransform';
[X,Y]=meshgrid(1:ceil(max(xyTransform(:,1))),1:ceil(max(xyTransform(:,2))));
integerFill=zeros(ceil(max(xyTransform(:,1)))*ceil(max(xyTransform(:,2))),5);
integerFill(:,1)=reshape(X,[],1);
integerFill(:,2)=reshape(Y,[],1);
integerFill(:,3)=ones(length(integerFill),1).*i;
%Search for the nearest point
for k=1:length(integerFill)
% % % if mod(k,100)==0
% % % tic
% % % end
%Test For Close Point
xLoc=find(xyTransform(:,1)<integerFill(k,1)+1.0 & xyTransform(:,1)>integerFill(k,1)-1.0); %1.2 is arbitrary
searchXY=find(xyTransform(xLoc,2)<integerFill(k,2)+1.0 & xyTransform(xLoc,2)>integerFill(k,2)-1.0); %this search result could be piped into the distance calc with some manipulation, the index is for the subset of the array
%Find Distance for Close Point
if size(searchXY,1)~=0
distance = ((xyTransform(xLoc,1)-integerFill(k,1)).^2+(xyTransform(xLoc,2)-integerFill(k,2)).^2).^(1/2);
[C I]=min(distance);
integerFill(k,4)=fill(xLoc(I),3);
integerFill(k,5)=fill(xLoc(I),4);
end
% % % if mod(k,100)==0
% % % elapsedTime=toc
% % % end
end
newHeadModel=[newHeadModel; integerFill(find(integerFill(:,5)~=0.0),:)]; %#ok<AGROW>
end
savedata(newHeadModel,fileOut);
disp('Model Rotation Complete')

Réponses (0)

Catégories

En savoir plus sur Computational Geometry dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by