Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Write a Matlab program that takes in as an input up to 4 polygon vertices in

ID: 2085860 • Letter: 1

Question

1) Write a Matlab program that takes in as an input up to 4 polygon vertices in Cartesian coordinates (x,y). It should also take as an input a matrix that can describe any of the following 2D transformations in homogeneous coordinates: translation, Euclidian, similarity, affine or projective. Note that all the transformations must be performed in homogeneous coordinates.

a. Input Cartesian coordinates for an equilateral triangle

b. Select appropriate matrices for each type of 2D transformation. Perform all the abovementioned transformations on the triangle. Plot the original triangle and transformed triangles for each transformation.

c. Input Cartesian coordinates for a square

d. Perform the same transformations on the square using the same matrices as in b).

Plot the original square and transformed squares for each transformation.

2) Modify the program in part 1) so that it reads in as input a black and white image, scans through all its pixels starting with the top left corner and then scanning row by row from left to right. It still also takes as an input a matrix that describes the 2D transformation. Apply each of the above transformations using the same matrices as in part 1) to each of the pixels. Plot the original image and transformed images for each transformation.

Hints

• Apply the transformation only on the black pixels, i.e. when scanning first check if the pixel is black before applying the transformation.

• Round off the transformed pixel coordinates to get integer values.

• Initialize the output image to all white pixels, and then only make pixels at coordinates obtained from the transformation black.

• The original and modified image can be displayed using Matlab function imshowpair(A,B,'montage').

Explanation / Answer

Syntax

fill(X,Y,C)
fill(X,Y,ColorSpec)
fill(X1,Y1,C1,X2,Y2,C2,...)
fill(...,'PropertyName',PropertyValue)
fill(ax,...)
h = fill(...)

Description

The fill function creates colored polygons.

fill(X,Y,C) creates filled polygons from the data in X and Y with vertex color specified by C. C is a vector or matrix used as an index into the colormap. If C is a row vector, length(C) must equal size(X,2) and size(Y,2); if C is a column vector, length(C) must equal size(X,1) and size(Y,1). If necessary, fill closes the polygon by connecting the last vertex to the first. The values in X and Y can be numeric, datetime, duration, or categorical values.

fill(X,Y,ColorSpec) fills two-dimensional polygons specified by X and Y with the color specified by ColorSpec.

fill(X1,Y1,C1,X2,Y2,C2,...) specifies multiple two-dimensional filled areas.

fill(...,'PropertyName',PropertyValue) allows you to specify property names and values for a patch graphics object.

fill(ax,...) creates the polygons in the axes specified by ax instead of in the current axes (gca). The option ax can precede any of the input argument combinations in the previous syntaxes.

h = fill(...) returns a vector of patch objects.

%Triangle=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sides = 3;
t = (1/(2*sides):1/(sides):1)*2*pi-pi/3;
b = User_input(3);
x = b*sin(t)+5/8*xmax;
y = b*cos(t)+3/4*ymax;
fill(x,y,'black');