Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions matlab/@surfer/scale.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
%
% Snew = scale(S,sf) creates a new surfer object sf times bigger than S
% (all geometry is similarly scaled). If sf is a 3-vector, the scale
% factors apply in x,y,z axes respectively.
% factors apply in x,y,z axes respectively. If sf is a scalar, then all
% axes are scaled by sf.

nsf = numel(sf);
if numel(sf) == 1
sf = sf*ones(3,1);
end
if (length(sf) ~=3)
if nsf == 2 || nsf > 3
fprintf('incompatible sizes');
objout = surfer.empty;
return
elseif nsf == 1
sf = sf*ones(3,1);
end

objout = affine_transf(obj,diag(sf),[0;0;0]);
Expand Down
36 changes: 36 additions & 0 deletions matlab/test/test_scale.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
% Tester for surfer scaling
run ../startup.m

% Unit sphere in origin
R = 1;
S = geometries.sphere(R, 6, [0;0;0]);

% Error in surface area before scaling
aerr_sphere = abs(4*pi*R^2-area(S));
fprintf('Error in area before scaling=%d\n',aerr_sphere);

% Scale to prolate spheroid using vector [a,b,c]
a = 2.1; b = 2.1; c = 3.4;
S_spheroid = S.scale([a,b,c]);

% Validate spheroidal surface area
ecc = sqrt(1-a^2/c^2);
aref = 2*pi*a^2*(1+c/a/ecc*asin(ecc));
aerr_spheroid = abs(aref-area(S_spheroid));
fprintf('Error in area after vector scaling=%d\n',aerr_spheroid);

% Scale to ellipsoid using vector [a,b,c]
a = 0.1; b = 2.1; c = 3.4;
S_ellipsoid = S.scale([a,b,c]);

% Validate scaling factors of coordinates in each direction
assert(max(S_ellipsoid.r(1,:))/max(S.r(1,:))==a);
assert(max(S_ellipsoid.r(2,:))/max(S.r(2,:))==b);
assert(max(S_ellipsoid.r(3,:))/max(S.r(3,:))==c);

% Scalar scaling of sphere using scalar a
a = 1.37;
S_scalar_scaled = S.scale(a);
aerr_sphere_scaled = abs(4*pi*(R*a)^2-area(S_scalar_scaled));
fprintf('Error in area after scalar scaling=%d\n',aerr_sphere_scaled);