It looks like you're using an Ad Blocker.
Please white-list or disable AboveTopSecret.com in your ad-blocking tool.
Thank you.
Some features of ATS will be disabled while you continue to use an ad-blocker.
originally posted by: Stevenmonet
a reply to: TycoonBarnaby
The numbers are not straight forward because we are trying to describe a perfectly ballanced system in a continual state of flux held together by the imaginary number zero that can never be atained but must exist in order for any information/universe to exist/be observed.
%% Inputs parsing
assert(nargin < 6,'Too many input arguments.');
if ~nargin
nb_it = 3;
option_display = true;
M1 = [0.5*sqrt(3) 0 0];
M2 = [0 1 0];
M3 = [-0.5*sqrt(3) 0 0];
elseif nargin > 0
assert(isnumeric(nb_it) && nb_it == floor(nb_it) && nb_it >= 0,'nb_it parameter value must be numeric positive or null integer.');
if nargin > 1
if nargin < 4
error('The three input arguments M1, M2 and M3 must defined together.');
else % check M1, M2, M3 same size, dim
assert(isequal(size(M1),size(M2),size(M3)), 'All inputs points must have the same size.');
assert(isequal(numel(M1),numel(M2),numel(M3)), 'All inputs points must have the same number of elements (2 or 3).');
assert(isequal(ndims(M1),ndims(M2),ndims(M3),2),'All inputs points must have the same number of dimensions (2).');
assert(isreal(M1) && isreal(M2) && isreal(M3), 'All inputs points must contain real numbers only.');
if nargin > 4
assert(islogical(option_display) || isnumeric(option_display),'option_display parameter type must be either logical or numeric.');
else
option_display = true;
end
end
else
M1 = [0.5*sqrt(3) 0 0];
M2 = [0 1 0];
M3 = [-0.5*sqrt(3) 0 0];
option_display = true;
end
end
warning('on');
if option_display && nb_it > 7
warning('%s triangles to display ! Make sure your graphic card has enough memory.',num2str(3^(nb_it+1)))
end
warning('off');
%% Body
nb_max_it = 9;
sample_step = 2^(nb_max_it-nb_it);
% Create a meshed triangle
[V1,T_array_1] = sample_triangle(M1',M2',M3',sample_step);
% Middle edge vertices
edg_idx1 = 1 + sample_step/2;
edg_idx3_vect = cumsum(edg_idx1:1+sample_step);
edg_idx3 = edg_idx3_vect(end);
edg_idx2 = edg_idx3 - sample_step/2;
V_array_1 = V1;
% Iterate over nb_it
p = 0;
while p ~= nb_it
new_V_array_1 = repmat(V_array_1,[1 1 3]);
for j = 1:size(V_array_1,3) % loop on current nb Sierpinski triangles
new_V_array_1(:,:,3*(j-1)+1) = sample_triangle(V_array_1(1,:,j)',V_array_1(edg_idx1,:,j)',V_array_1(edg_idx2,:,j)',sample_step);
new_V_array_1(:,:,3*(j-1)+2) = sample_triangle(V_array_1(1 + sample_step,:,j)',V_array_1(edg_idx3,:,j)',V_array_1(edg_idx1,:,j)',sample_step);
new_V_array_1(:,:,3*(j-1)+3) = sample_triangle(V_array_1(end,:,j)',V_array_1(edg_idx2,:,j)',V_array_1(edg_idx3,:,j)',sample_step);
end
V_array_1 = new_V_array_1;
p = p+1;
end
V = V_array_1(:,:,1);
T = T_array_1(:,:,1);
for k = 1:size(V_array_1,3)
T = cat(1,T,T_array_1(:,:,1)+size(V,1));
V = cat(1,V,V_array_1(:,:,k));
end
%% Display
if option_display
figure;
set(gcf,'Color',[0 0 0]);
t = trisurf(T,V(:,1),V(:,2),V(:,3)); shading interp, hold on;
t.EdgeColor = 'g';
set(gca,'Color',[0 0 0],'XColor',[1 1 1],'YColor',[1 1 1],'ZColor',[1 1 1]);
colormap([0 1 0]);
axis equal, axis tight;
camlight right;
end
end % Sierpinski_triangle
%% sample_triangle subfunction
function [V, T] = sample_triangle(V1, V2, V3, nbstep)
% Create sampling grid
global Ndim;
Ndim = size(V1,1);
% (V1V2, V1V3) base
u = (V2 - V1);
v = (V3 - V1);
V = zeros(sum(1:nbstep+1),Ndim);
nu = u / norm(u);
nv = v / norm(v);
stepu = norm(u) / nbstep;
stepv = norm(v) / nbstep;
k = 1;
% Sampling & vertices generation
for m = 0:nbstep
for n = 0:nbstep
if m+n