0% found this document useful (0 votes)
3 views

Assignment 4

The document contains a series of Python code snippets using the SymPy library to perform geometric transformations on points, including translation, scaling, reflection, and rotation. Each question demonstrates different transformations applied to specified points, resulting in new coordinates. The outputs of these transformations are printed for verification.

Uploaded by

munnabhaiya.7001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment 4

The document contains a series of Python code snippets using the SymPy library to perform geometric transformations on points, including translation, scaling, reflection, and rotation. Each question demonstrates different transformations applied to specified points, resulting in new coordinates. The outputs of these transformations are printed for verification.

Uploaded by

munnabhaiya.7001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Q1.

i).from sympy import* p=Point(3,-1)


P1=p.transform(Matrix([[1,0,0],[0,-1,0],[0,0,1]])) print(P1)
Point2D(3, 1)

ii).p=Point(3,-1)
P1=p.transform(Matrix([[1,0,0],[0,-1,0],[0,0,1]]))
P2=p.transform(Matrix([[2,0,0],[0,1,0],[0,0,1]]))
print(P1) print(P2) Point2D(3, 1)
Point2D(6, -1)

iii)p=Point(3,-1)
P3=p.transform(Matrix([[1,0,0],[0,-1.5,0],[0,0,1]])) print(P3)
Point2D(3, 3/2)

iv)p=Point(3,-1)
P4=p.transform(Matrix([[0,1,0],[1,0,0],[0,0,1]])) print(P4)
Point2D(-1, 3)

Q2.
i)p=Point(4,-2)
P1=p.transform(Matrix([[-1,0,0],[0,1,0],[0,0,1]])) print(P1)
Point2D(-4, -2)

ii)p=Point(4,-2)
P1=p.transform(Matrix([[3,0,0],[0,1,0],[0,0,1]])) print(P1)
Point2D(12, -2)

iii)p=Point(4,-2)
P3=p.transform(Matrix([[1,0,0],[0,2.5,0],[0,0,1]])) print(P3)
Point2D(4, -5)

iv)p=Point(4,-2)
P4=p.transform(Matrix([[0,-1,0],[-1,0,0],[0,0,1]])) print(P4)
Point2D(2, -4)

Q3.
from sympy import* p=Point(-2,4)
i.P1=p.transform(Matrix([[1,0,0],[0,1,0],[0,0,1]]))
ii.P2=p.transform(Matrix([[2,0,0],[0,1,0],[0,0,1]]))
iii.P3=p.transform(Matrix([[1,0,0],[4,1,0],[0,0,1]]))
iv.P4=p.rotate(pi/3) print(P1) print(P2) print(P3)
print(P4) Point2D(-2, -10)
Point2D(-7, 28)
Point2D(14, -10)
Point2D(-2*sqrt(3) - 1, 2 - sqrt(3))

Q4.
from sympy import* p=Point(-2,4)
P1=p.transform(Matrix([[1,0,0],[0,-1,0],[0,0,1]]))
P2=p.transform(Matrix([[6,0,0],[0,1,0],[0,0,1]]))
P3=p.transform(Matrix([[1,0,0],[4,1,0],[0,0,1]]))
P4=p.rotate(pi/6) print(P1) print(P2) print(P3)
print(P4) Point2D(-2, -4)
Point2D(-12, 4)
Point2D(14, 4)
Point2D(-2 - sqrt(3), -1 + 2*sqrt(3))

Q5. #5 from sympy


import*
p=Point(2,3)
P1=p.transform(Matrix([[1,0,0],[0,-1,0],[0,0,1]]))
P2=p.transform(Matrix([[2,0,0],[0,1,0],[0,0,1]]))
P3=p.transform(Matrix([[1,0,0],[0,1.5,0],[0,0,1]]))
P4=p.transform(Matrix([[0,1,0],[7,1,0],[0,0,1]]))
print(P1) print(P2)
print(P3) print(P4)
Point2D(2, -3)
Point2D(4, 3)
Point2D(2, 9/2)
Point2D(3, 2)

Q6. import numpy as np


#first rotation about origin through 90
rotation=np.array([[0,1,0],[-1,0,0],[0,0,1]])
#2nd transformation scaling
scaling=np.array([[5,0,0],[0,1,0],[0,0,1]])
#3rd reflection=-x
reflect=np.array([[-1,0,0],[0,-1,0],[0,0,1]])

#combined transformation
combined=np.eye(3)
#apply rotation
combined=np.matmul(combined,rotation)
#apply scaling
combined=np.matmul(combined,scaling)
#apply reflection
combined=np.matmul(combined,reflect)
print(combined)
A=np.array([5,3,1])
B=np.array([1,4,1])
A_transfered=np.matmul(combined,A)
B_transfered=np.matmul(combined,B)

[[ 0. -1. 0.]
[ 5. 0. 0.]
[ 0. 0. 1.]]

Q7. import numpy as np


#first rotation about origin through 30
rotation=np.array([[np.cos(30),np.sin(30),0],[-np.sin(30), np.cos(30),0],[0,0,1]])
#2nd transformation scaling in y by 4
scaling=np.array([[1,0,0], [0,4,0], [0,0,1]])
#3rd is reflection through origin
reflect=np.array([[-1,0,0],[0,-1,0], [0,0,1]])
#combined transformation
combined=np.eye(3)
#apply rotation
combined=np.matmul(combined,rotation)
#apply scaling
combined=np.matmul(combined, scaling)
#apply reflection
combined=np.matmul(combined, reflect)
print(combined)
A=np.array([3,2,1])
B=np.array([2,-3,1])
A_transfered=np.matmul(combined,A)
B_transfered=np.matmul(combined,B)
print('\n in A transfered is' ,A_transfered)
print('\n in B transfered is', B_transfered)

[[-0.15425145 3.9521265 0. ]
[-0.98803162 -0.6170058 0. ]
[ 0. 0. 1. ]]

[ 7.44149864 -4.19810647 1. ]

[-12.16488239 -0.12504585 1. ]]

Q8. from sympy


import* Q=Point(-
2,4)
x,y=symbols('x,y')
P1=p.rotate(pi/3.75)
P2=p.transform(Matrix([[2,0,0],[0,1,0],[0,0,1]])) P3=p.reflect(Line(2*x-y+3))
P4=p.transform(Matrix([[1,0,0],[7,1,0],[0,0,1]]))
print(P1) print(P2) print(P3) print(P4)
Point2D(-3*sqrt(sqrt(5)/8 + 5/8)/2 + 3*sqrt(3)*(1/4 - sqrt(5)/4)/2 - sqrt(5)/4 + 1/4 +
sqrt(3)*sqrt(sqrt(5)/8 + 5/8), -3*sqrt(5)/8 + 3/8 - sqrt(3)*(1/4 - sqrt(5)/4) + sqrt(sqrt(5)/8 + 5/8)
+ 3*sqrt(3)*sqrt(sqrt(5)/8 + 5/8)/2)
Point2D(-4, 4)
Point2D(2, 2)
Point2D(26, 4)

Q9. from sympy import*


p=Point(-2,4)
x,y=symbols('x,y')
P1=p.reflect (Line (3*x+4*y-5))
P2=p.transform(Matrix([[6,0,0], [0,1,0], [0,0,1]]))
P3=p.transform(Matrix([[6,0,0], [0,4.1,0], [0,0,1]]))
P4=p.reflect (Line (2*x-y+3))
print(P1)
print (P2)
print(P3)
print(P4)

Point2D(-16/5,12/5)
Point2D(-12,4)
Point2D(-12,82/5)
Point2D(2,2)

You might also like