tree forest

follow the instruction on the pdf the zip file for the data is on this link please do it correctly

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

https://we.tl/t-MB8Xp69tyW

INFO371 Lab 2: Rotate wireframe images
January 29, 2024
Introduction
See lecture notes, 5.4 “Application: wireframe images” for more background.
Images can be rotated by just matrix-multiplying those with rotation matrix
(
)
cos α − sin α
R(α) =
.
sin α cos α
This matrix rotates an object matrix by angle α clockwise if you post-multiply the object matrix by it:
Aα = A · R(α)
where A is a n × 2 matrix of x and y coordinates. Each row of this matrix corresponds to one vector that
points to one of the points of this image. For instance, the following matrix gives us a flipped-1-shaped
figure: A as


0 0
A = 0 2 .
1 1
The image can be plotted by
import numpy as np
import matplotlib.pyplot as plt
# create the image
A = np.array([[0,0], [0,2], [1,1]])
# plot the image
ax = plt.subplot(1,1,1)
ax.plot(A[:,0], A[:,1], marker=’o’)
ax.set_aspect(“equal”)
plt.show()
1
2.00
1.75
1.50
1.25
1.00
0.75
0.50
0.25
0.00
0.0
0.5
1.0
We ask for a line-point plot (marker=”o”) and use aspect ratio “equal” to ensure that x and y lengths
are of equal scale on the figure so that it will not be distorted when rotating.
1
Rotate Crazy Hat
Below, your task is to rotate Crazy Hat’s image. It is a similar wireframe image, the only difference that
different elements of should not be connected (they belong to different groups). The instructions below
suggest an efficient way to achieve it, but you can also get there differently.
1.1
Load and plot
1. Read the data points from “crazy_hat.tsv” (available on canvas) from disk. A small excerpt of it
looks like this:
import pandas as pd
ch = pd.read_csv(“../../data/toy/crazy-hat.tsv”, sep=”\t”)
ch.head()
##
x
y
## 0
0 22
## 1 16 -18
## 2 -16 -18
## 3
0 22
## 4 -3
7
group
outline
outline
outline
outline
leye
This contains three variables: x, y, and group. x and y are the point coordinates while group
indicates which points should be connected: your should connect points inside the same group (e.g.
all four outline points) but not between different groups (e.g. do not connect outline with leye).
2
2. Separate the data into coordinate matrix (call this X) and group id-s (call this groups). You can
get matrix out of data frame columns with the .values attribute.
Note that when you rotate image below, you only have to manipulate X, groups will remain the
same.
3. Plot the figure: plot all x-y pairs and sequentially connect the dots. Pay attention to connect the
points that belong to the same group (in the given order) but do not connect points of different
groups groups.
Hint: you can do this by a loop over unique group values (remember np.unique), and by plotting
and connecting only points for this group inside the loop.
Hint 2: normally data plotting does not care about x/y scales. You may want to force both to be
in the same scale with
ax = plt.subplot(1, 1, 1)
ax.set_aspect(“equal”)
ax.plot(…)
4. Convert your plotting code into a function that takes two arguments: X and groups. You may add
more argumetns if you wish, like color, image size, etc. Demonstrate that the function works with
Crazy Hat data.
1.2
Rotation matrix
1. Now create a function Rot that takes the angle α, and returns the rotation matrix to rotate image
by this angle. Check out np.sin, np.cos, and remember that radians = π · degrees/180.
Note: you can achieve the results here in different ways, but your code will be clean and easy to
follow if you follow the advice here: a plotting function that takes in the coordinate matrix, and a
function that returns the rotation matrix.
2. Now rotate the Crazy Hat figure. Select a few different angles of your choice. Remember that
matrix multiplication sign is @, not *!
You can first rotate X and thereafter plot the rotated X, or alternatively just plot X · Rot(α).
1.3
Properties of rotation matrix
Are rotations commutative? Matrix multiplication are not commutative in general. But rotations should
be: if you rotate clockwise by 90 degrees, and thereafter counterclockwise by 45 degrees, the result should
be clockwise rotation by 45 degrees. And obviously, you can start with 45-degree counterclockwise rotation
first, and the results should still be the same.
1. Demonstrate that your rotations are additive: show that if you rotate the image twice by 45 degrees,
the result is the same as rotated by 90 degrees.
2. Show that the rotations are commutative: rotating by α first and by β afterwards is the same as
rotating by β first and α afterwards.
As a proof just demonstrate this is true for a selected α and β (e.g. α = −45 deg and β = 90 deg).
3
2
Extra task: not graded
So far we talked about rotation matrices. A 2 × 2 matrix must meet very strict requirements to be a
rotation matrix (all elements must be ⩽ 1, it’s determinant must be 1, main diagonal must be constant, it
must be antisymmetric). However, every matrix will distort the image in a certain way when multiplied
by it.
1. Create a few 2 × 2 matrices of your choice (e.g. random numbers or linear ranges), and plot Crazy
Hat distorted through these matrices.
4

Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER