Introduction to Visual Media Programming
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
MAS2011 Introduction to Visual Media Programming
Your name and student id must appear at the top of every answer sheet. Otherwise, the page will
not be evaluated.
(1) Compute the matrix multiplications C=AB, and D=BA using the following two 2x2 matrices:
= (
1 2
−1 1
) , = (
1 2
1 −1
)
(2) Complete the python function that returns the array of the vertices of regular polygon for
an input N and radius R. For example, the function returns an array of three vertices on
the circle of radius 10 when N=3, R=10.
def getRegularPolygon(N, R=1.0):
vertices = []
# provide your code here
return np.array(vertices)
(3) You are given a position vector v=[10, 5]. Compute the length (or magnitude) of the vector
v and the angle θ of the vector v (with respect to the x-axis).
(4) You are going to design a python’s class object to represent a rectangle. When you create
10 instances of them, each of which will move in the direction randomly chosen at the
initialization stage, starting at the random initial location, bouncing when it hits any of the
four walls of the game screen. You are going to use the Sprite class of pygame. Provide its
class description.
class MyBlock(Sprite):
# your code here
# -----------------------------
(5) You are asked to design a function to detect collision detection between two circular
objects. The Circle class has radius and position (x, y) as its member variables. The function
must return True if the two input circles overlap each other. Provide the function:
def collision_circles(A, B):
# A, B: instances of class Circle
#
(6) Provide a function to detect collisions between two instances of class Rectangle which has
rect as its member variable. It must return True if the two input rectangles overlap.
def collision_rect(A, B):
# A, B: instances of class Rectangle
#
(7) Now you are about to make a function for collision detection between two regular triangles,
wandering around inside the screen due to rotational and translational motion. Describe
your algorithmic idea for detecting whether the two triangles are overlapping. It does not
have to be in python code.
(8) In the shmup shooting game of yours, developed during the class, the mobs (meteors)
come down but do not try to intentionally kill your fighter spaceship. Why? How can
you change this principle?
(9) You are playing Tic-Tac-Toe game and now thinking at the state displayed by the figure
below. You are simulating the minimax algorithm in your brain so that you may win the
game. Here your task is to draw the game tree. When you reach the final states in the tree
then roll-up (or come back) to the top state so that you make the most promising move
or action. The game score is 1 if you win at the last state, -1 if you lose, and 0 otherwise.
In short, draw the game tree for the minimax algorithm. You are playing marker is ‘X’.
(top state)
⚫ You are given a 2x10 image whose pixels values are as follows:
(10) Apply linear filtering (cross-correlation) operation to the image for the following gradient
kernel:
K =
(11) Compute the linear filtering result for the following smoothing kernel:
K =
1 2 3 4 5 6 7 8 9 10
1 1 1 101 101 101 101 1 1 1
-1 1
1/2 1/2
⚫ (For problems 12 – 15) You are given a rectangle: V = [ [0, 0], [100, 0], [100, 20], [0, 20] ].
The position vectors are in [x, y] representation.
(12) Matrices:
A. What is the matrix R(30) for 30 degrees rotation?
B. What is the translation matrix T(50, 0) for tx=50 and ty=0?
(13) Draw or sketch the view when you apply H1 = R(30) T(50, 0) to the rectangle’s vertices.
You must specify a few important coordinates and angles
(14) Draw or sketch the view when you apply H2 = T(50, 0) R(30) to the rectangle’s vertices.
You must specify a few important coordinates.
(15) You are going to draw the following figure by applying a sequence of rotations and
translations to the rectangle array V. Provide appropriate python code to draw the figure.
You must specify appropriate sequences of transformation matrices. Assume that you
already have a function draw(V, H) that applies the composite transformation H to the
polygon vertex array V.