You are on page 1of 5

Additive Manufacturing

# Take input from user to get 4 by 4 matrix which is to be rotated by 45


degrees about y axis and then followed by 45 degrees about x axis , determine
the resultant matrix using matlab.

CODE:
% Define the input matrix
input_matrix = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12; 13, 14, 15, 16];

% Rotation matrix for 45 degrees about y-axis


rot_y = [cos(pi/4), 0, sin(pi/4), 0; 0, 1, 0, 0; -sin(pi/4), 0, cos(pi/4), 0; 0, 0, 0, 1];

% Rotation matrix for 45 degrees about x-axis


rot_x = [1, 0, 0, 0; 0, cos(pi/4), -sin(pi/4), 0; 0, sin(pi/4), cos(pi/4), 0; 0, 0, 0, 1];

transformation_x_y = rot_x.*rot_y

% Apply the rotations to the input matrix


result_matrix = input_matrix.* transformation_x_y
% Display the result
disp('Resultant matrix:');
disp(result_matrix);

transformation_x_y =

0.7071 0 0 0
0 0.7071 0 0
0 0 0.5000 0
0 0 0 1.0000

result_matrix =

0.7071 0 0 0
0 4.2426 0 0
0 0 5.5000 0
0 0 0 16.0000

Resultant matrix:
0.7071 0 0 0
0 4.2426 0 0
0 0 5.5000 0
0 0 0 16.0000

# How to enter 4 by 4 matrix in matlab :

CODE:
matrix = input('Enter a 4x4 matrix: ');
matrix = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12; 13, 14, 15, 16];

# There is difference between matrix multiplication and dot product for


transformation , .* is used instead of * in case of tranformation matrix

#Rotation of a triangle about a point apart from origin Matlab Code


% Original coordinates of the triangle
A = [0; 0];
B = [2; 2];
C = [4; 2];

% Rotation angle and center point


theta = 45 * pi/180; % angle in radians
center = [-2; -2];

% Translation to center
A = A - center;
B = B - center;
C = C - center;

% Rotation
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
A = R * A;
B = R * B;
C = R * C;

% Translation back to original position


A = A + center;
B = B + center;
C = C + center;

% Display new coordinates


disp('New coordinates of the triangle:');
disp(['A: (' num2str(A(1)) ', ' num2str(A(2)) ')']);
disp(['B: (' num2str(B(1)) ', ' num2str(B(2)) ')']);
disp(['C: (' num2str(C(1)) ', ' num2str(C(2)) ')']);
New coordinates of the triangle:
A: (-2, 0.82843)
B: (-2, 3.6569)
C: (-0.58579, 5.0711)

# Hermite Curves
Here are some potential problems related to Hermite curves that could be
implemented using MATLAB:
. Given two endpoints and their associated tangent vectors, create a
cubic Hermite curve and plot it using MATLAB's "plot" function.
. Create a series of Hermite curves that connect a set of control points,
each with their own associated tangent vectors, and plot the resulting
curve using MATLAB.
. Use MATLAB's "fmincon" function to find the optimal set of tangent
vectors for a given set of control points that minimizes the curvature
of the resulting Hermite curve.
. Implement a Hermite interpolation function in MATLAB that takes a set
of data points and their associated tangent vectors, and returns a
smooth, continuous curve that passes through all of the data points.
. Create a GUI in MATLAB that allows the user to interactively adjust the
positions and tangent vectors of a set of control points, and see the
resulting Hermite curve in real time.
. Use MATLAB's "ode45" function to simulate the motion of a particle
following a Hermite curve in 2D or 3D space, given its initial position
and velocity.
. Implement a spline interpolation function in MATLAB that uses Hermite
curves to interpolate a set of data points with smoothly varying
tangent vectors.
. Given a set of control points and tangent vectors, use MATLAB's
"convhull" function to create a convex hull of the resulting Hermite
curve, and plot it using MATLAB's "patch" function.
. Implement a function in MATLAB that takes a Hermite curve and
computes its curvature and torsion as a function of the curve
parameter t.
. Use MATLAB's "fminsearch" function to find the optimal set of control
points and tangent vectors for a Hermite curve that minimizes its
distance from a given set of data points.
# Polygon Composite Transformation

. Given a polygon, apply a scaling transformation followed by a


.
translation transformation.
. Given a polygon, apply a rotation transformation followed by a
translation transformation.
. Given two polygons, apply a scaling transformation to one polygon
followed by a translation transformation and then apply a rotation
transformation to the other polygon.
. Given a polygon, apply a shearing transformation followed by a scaling
transformation.
. Given a polygon, apply a reflection transformation followed by a
translation transformation.

Given a triangle with A (2,0) B (3,2), C (4,0) , apply a scaling


transformation followed by a translation transformation. Find the new
coordinates A',B',C' using Matlab
% Define the original triangle vertices
A = [2, 0];
B = [3, 2];
C = [4, 0];

% Apply scaling transformation


S = [2 0; 0 2]; % Scaling matrix
A = A*S;
B = B*S;
C = C*S;

% Apply translation transformation


T = [3 1]; % Translation vector
A = A + T;
B = B + T;
C = C + T;

% Display the new vertices


fprintf('A'' = (%f, %f)\n', A(1), A(2));
fprintf('B'' = (%f, %f)\n', B(1), B(2));
fprintf('C'' = (%f, %f)\n', C(1), C(2));

Given two endpoints and their associated tangent vectors, create a cubic
Hermite curve and plot it using MATLAB's "plot" function.
In notes

Create a series of Hermite curves that connect a set of control points,


each with their own associated tangent vectors, and plot the resulting
curve using MATLAB.
% Define control points
P = [0 0; 2 4; 4 4; 6 0];

% Define tangent vectors at each control point


T = [1 2; 1 -2; 1 2; 1 -2];

% Generate Hermite curve using spline function


t = linspace(0,1,100);
X = spline([0 0 0 0.5 1 1 1],[P(1,1) P(2,1) P(3,1) P(4,1) P(4,1) P(3,1)
P(2,1)],...
[0 T(1,1) T(2,1) 0 0 T(3,1) T(4,1)]);
Y = spline([0 0 0 0.5 1 1 1],[P(1,2) P(2,2) P(3,2) P(4,2) P(4,2) P(3,2)
P(2,2)],...
[0 T(1,2) T(2,2) 0 0 T(3,2) T(4,2)]);

% Plot Hermite curve


figure
plot(P(:,1), P(:,2), 'o', X, Y)
legend('Control points', 'Hermite curve')

You might also like