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

FernwithRiAlgorithm

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)
5 views3 pages

FernwithRiAlgorithm

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
You are on page 1/ 3

% Initialize parameters

num_iterations = 100;

num_points = 100000; % Number of points in the initial set

% Define the initial set as a small vertical strip

S = [zeros(num_points, 1), rand(num_points, 1) * 0.1]; % Small vertical strip

% Define the transformation matrices and translation vectors for Barnsley Fern

A1 = [0 0; 0 0.16]; t1 = [0; 0];

A2 = [0.85 0.04; -0.04 0.85]; t2 = [0; 1.6];

A3 = [0.2 -0.26; 0.23 0.22]; t3 = [0; 1.6];

A4 = [-0.15 0.28; 0.26 0.24]; t4 = [0; 0.44];

% Probability weights for each transformation (Barnsley Fern)

p1 = 0.02;

p2 = 0.85;

p3 = 0.07;

p4 = 0.07;

% Iterative process

for i = 1:num_iterations

% Generate random values for selecting the transformation

rand_vals = rand(num_points, 1);

% Initialize new set


new_S = zeros(num_points, 2);

% Apply each transformation based on the random values

new_S(rand_vals < p1, :) = (A1 * S(rand_vals < p1, :)')' + repmat(t1', sum(rand_vals < p1), 1);

new_S(rand_vals >= p1 & rand_vals < p1 + p2, :) = (A2 * S(rand_vals >= p1 & rand_vals < p1 + p2, :)')' +
repmat(t2', sum(rand_vals >= p1 & rand_vals < p1 + p2), 1);

new_S(rand_vals >= p1 + p2 & rand_vals < p1 + p2 + p3, :) = (A3 * S(rand_vals >= p1 + p2 & rand_vals <
p1 + p2 + p3, :)')' + repmat(t3', sum(rand_vals >= p1 + p2 & rand_vals < p1 + p2 + p3), 1);

new_S(rand_vals >= p1 + p2 + p3, :) = (A4 * S(rand_vals >= p1 + p2 + p3, :)')' + repmat(t4',


sum(rand_vals >= p1 + p2 + p3), 1);

% Update the set

S = new_S;

end

% Create a figure for visualization

figure;

hold on;

axis equal;

% Plot the final iteration

plot(S(:,1), S(:,2), '.', 'MarkerSize', 1,'Color', 'b');

hold off;

OUTPUT with initial as vertical strip of points

You might also like