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

Fractal Generation with Transformation Matrices

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

Fractal Generation with Transformation Matrices

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

% Define x and y coordinates of the points

x = [0, 1, 2]; % Replace with your x-coordinates

y = [0, 1, 4]; % Replace with your y-coordinates

% Define vertical scaling factors (d1 and d2)

d = [0.25, 0.25]; % Scaling factors for w1 and w2

% Ensure consistency

if length(x) ~= 3 || length(y) ~= 3 || length(d) ~= 2

error('x and y must have 3 points, and d must have 2 elements.');

end

% Compute coefficients for w1

a1 = (x(2) - x(1)) / (x(3) - x(1));

c1 = ((y(2) - y(1)) - (d(1) * (y(3) - y(1)))) / (x(3) - x(1));

e1 = (x(3)*x(1)- (x(1)*x(2)))/ (x(3) - x(1));

f1 = ((x(3)*y(1)) - (x(1)*y(2)) - d(1)*(x(3)*y(1)-x(1)*y(3))) / (x(3) - x(1));

% Transformation matrix and translation vector for w1

A1 = [a1, 0; c1, d(1)];

B1 = [e1; f1];

% Compute coefficients for w2

a2 = (x(3) - x(2)) / (x(3) - x(1));

c2 = ((y(3) - y(2)) - (d(2) * (y(3) - y(1)))) / (x(3) - x(1));


e2 = (x(3)*x(2)- (x(1)*x(3)))/ (x(3) - x(1));

f2 = ((x(3)*y(2)) - (x(1)*y(3)) - d(2)*(x(3)*y(1)-x(1)*y(3))) / (x(3) - x(1));

% Transformation matrix and translation vector for w2

A2 = [a2, 0; c2, d(2)];

B2 = [e2; f2];

% Display transformation matrices and vectors

disp('Transformation w1:');

disp('A1 = '); disp(A1);

disp('B1 = '); disp(B1);

disp('Transformation w2:');

disp('A2 = '); disp(A2);

disp('B2 = '); disp(B2);

% Generate fractal points

n_points = 1000; % Number of points to generate

X = [0; 0]; % Initial point

fractal_points = zeros(2, n_points);

for i = 1:n_points

% Randomly select transformation w1 or w2

k = randi([1, 2]);

if k == 1
X = A1 * X + B1;

else

X = A2 * X + B2;

end

fractal_points(:, i) = X;

end

% Plot the fractal

figure;

plot(fractal_points(1, :), fractal_points(2, :), '.');

title('Generated Fractal using w1 and w2');

xlabel('x');

ylabel('y');

axis equal;

grid on;

You might also like