0% found this document useful (0 votes)
13 views3 pages

Fractal Generation in MATLAB

Uploaded by

Ashish Jakhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Fractal Generation in MATLAB

Uploaded by

Ashish Jakhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

% Set the number of iterations

num_iterations = 8;

% Call the main function to generate and plot the deterministic fractal

deterministic_fractal(num_iterations);

% Function to generate and plot the deterministic fractal

function deterministic_fractal(num_iterations)

% Initial figure: a closed equilateral triangle

S = [0, 0; 2, 0; 1, sqrt(3); 0, 0]; % Triangle with vertices (0,0), (2,0), (1,height) and closing the loop

% Define the transformation matrices and translation vectors

A1 = [0.5 0.5; -0.5 0.5]; t1 = [0.5; 0];

A2 = [0.3 -0.6; 0.6 0.3]; t2 = [-0.5; 0.5];

A3 = [-0.5 0.5; 0.5 0.5]; t3 = [0; -0.5];

A4 = [0.6 0; 0 0.2]; t4 = [0.1; 0.7];

% Initialize the figure

figure;

axis equal;

hold on;

axis off;

% Iterate to generate the fractal

for i = 1:num_iterations
% Apply transformations deterministically

S = apply_transformations(S, A1, t1, A2, t2, A3, t3, A4, t4);

end

% Plot the final iteration with a custom color

plot(S(:,1), S(:,2), 'o-', 'MarkerSize', 2, 'Color', [0.2, 0.7, 0.9]); % Light blue color

hold off;

end

% Function to apply transformations deterministically

function new_S = apply_transformations(S, A1, t1, A2, t2, A3, t3, A4, t4)

% Initialize new set

new_S = zeros(size(S, 1) * 4, 2); % Four times the number of original points

% Apply each transformation to the entire figure

new_S(1:size(S, 1), :) = (A1 * S')' + repmat(t1', size(S, 1), 1);

new_S(size(S, 1)+1:2*size(S, 1), :) = (A2 * S')' + repmat(t2', size(S, 1), 1);

new_S(2*size(S, 1)+1:3*size(S, 1), :) = (A3 * S')' + repmat(t3', size(S, 1), 1);

new_S(3*size(S, 1)+1:end, :) = (A4 * S')' + repmat(t4', size(S, 1), 1);

end

OUTPUT starting with triangle:

You might also like