0% found this document useful (0 votes)
9 views15 pages

2-D Transformation-1

The document contains Python code that demonstrates various geometric transformations using Matplotlib and NumPy, including reflections, rotations, and translations of points and shapes in a 2D frame. It includes visualizations for transformations such as reflecting points across axes and lines, rotating shapes around the origin, and translating shapes to different positions. Each section of the code plots the original and transformed shapes, providing a visual representation of the transformations applied.

Uploaded by

yashodapawar10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views15 pages

2-D Transformation-1

The document contains Python code that demonstrates various geometric transformations using Matplotlib and NumPy, including reflections, rotations, and translations of points and shapes in a 2D frame. It includes visualizations for transformations such as reflecting points across axes and lines, rotating shapes around the origin, and translating shapes to different positions. Each section of the code plots the original and transformed shapes, providing a visual representation of the transformations applied.

Uploaded by

yashodapawar10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

# 2- dimensional frame #

from matplotlib.pyplot import*

import numpy as np

p=[-20,20]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

grid()

legend()

show()

# Reflected point

from matplotlib.pyplot import*

from numpy import*

p=[-10,10]

q=[0,0]

plot(p,q,label='x-axis',color='black')

plot(q,p,label='y-axis',color='black')

x=matrix([[2.5,2.5]])

x1=(x[0,0],x[0,0])

y1=(x[0,1],x[0,1])

plot(x1,y1,'*',label='Given point',color='red')

t=matrix([[1,0],[0,-1]])
x=x*t

x1=(x[0,0],x[0,0])

y1=(x[0,1],x[0,1])

print(x1,y1)

plot(x1,y1,'*',label='reflected point',color='blue')

legend()

grid()

show()

# Square #

from matplotlib.pyplot import*

import numpy as np

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

x=np.matrix([[2.5,2.5],[5,2.5],[5,5],[2.5,5]])

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

plot(x1,y1,label='original object',color='blue')
# Line #

from matplotlib.pyplot import*

import numpy as np

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

z=np.matrix([[-2.5,-2.5],[-5,-5]])

z1=(z[0,0],z[1,0])

z2=(z[0,1],z[1,1])

plot(z1,z2,label='original object',color='green')

grid()

# Reflection of square through X-axis (Manually) #

from matplotlib.pyplot import*

import numpy as np

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

x=np.matrix([[2.5,2.5],[5,2.5],[5,5],[2.5,5]])

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

plot(x1,y1,label='original object',color='blue')

x=np.matrix([[2.5,-2.5],[5,-2.5],[5,-5],[2.5,-5]])
x2=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y2=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

plot(x2,y2,label='reflected object',color='green')

grid()

legend()

show()

# Reflection of square through X-axis (Matrix Multiplication) #

from matplotlib.pyplot import*

import numpy as np

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

x=np.matrix([[2.5,2.5],[5,2.5],[5,5],[2.5,5]])

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

plot(x1,y1,label='original object',color='blue')

t=np.matrix([[1,0],[0,-1]])

x=x*t

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

plot(x1,y1,label='Reflected Object',color='Green')

grid()

legend()
show()

# Reflection through the line y=x #

from matplotlib.pyplot import*

import numpy as np

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

z=np.matrix([[-10,-10],[10,10]])

z1=(z[0,0],z[1,0])

z2=(z[0,1],z[1,1])

plot(z1,z2,label='Given line',color='red')

x=np.matrix([[2.5,7.5],[5,7.5],[2.5,10]])

x1=(x[0,0],x[1,0],x[2,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[0,1])

plot(x1,y1,label='original object',color='blue')

x=np.matrix([[7.5,2.5],[7.5,5],[10,2.5]])

x1=(x[0,0],x[1,0],x[2,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[0,1])

plot(x1,y1,label='reflectedl object',color='green')

grid()

legend()

show()
# Reflection through the line y=- x #

from matplotlib.pyplot import*

import numpy as np

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

z=np.matrix([[10,-10],[- 10,10]])

z1=(z[0,0],z[1,0])

z2=(z[0,1],z[1,1])

plot(z1,z2,label='Given line',color='red')

x=np.matrix([[2.5,7.5],[5,7.5],[2.5,10]])

x1=(x[0,0],x[1,0],x[2,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[0,1])

plot(x1,y1,label='original object',color='blue')

x=np.matrix([[-7.5,-2.5],[-7.5,-5],[-10,-2.5]])

x1=(x[0,0],x[1,0],x[2,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[0,1])

plot(x1,y1,label='reflected object',color='green')

grid()

legend()

show()
# Rotation about origin by an angle 90 #

from matplotlib.pyplot import*

import numpy as np

import math as m

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

a=m.cos(np.pi/2)

b=m.sin(np.pi/2)

x=np.matrix([[2.5,2.5],[5,2.5],[5,5],[2.5,5]])

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

plot(x1,y1,label='original object',color='blue')

t=np.matrix([[a,b],[-b,a]])

x2=(x[0,0],x[1,0])

y2=(x[0,1],x[1,1])

x=x*t

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

plot(x1,y1,label='Reflected Object',color='Green')

grid()

legend()

show()
# Rotation about origin by an angle 35 #

from matplotlib.pyplot import*

import numpy as np

import math as m

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

x=np.matrix([[2.5,2.5],[5,2.5],[5,5],[2.5,5]])

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

plot(x1,y1,label='original object',color='blue')

a=m.cos(7*np.pi/36)

b=m.sin(7*np.pi/36)

t=np.matrix([[a,b],[-b,a]])

x=x*t

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

plot(x1,y1,label='Reflected Object',color='Green')

grid()

legend()

show()
# Rotation about point (2,5) #

from matplotlib.pyplot import*

import numpy as np

import math as m

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

x=np.matrix([[2.5,2.5,1],[5,2.5,1],[5,5,1],[2.5,5,1]])

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='original object',color='blue')

t1=np.matrix([[1,0,0],[0,1,0],[-2,-5,1]])

x=x*t1

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='Translated Object1',color='Green')

t2=np.matrix([[0,1,0],[-1,0,0],[0,0,1]])

x=x*t2

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])
plot(x1,y1,Z1,label='Reflected Object2',color='red')

t3=np.matrix([[1,0,0],[0,1,0],[2,5,1]])

x=x*t3

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='INV Object',color='black')

print(x1,y1,z1)

grid()

legend()

show()

# Rotation about point (2,5) using combine transformation matrix #

from matplotlib.pyplot import*

import numpy as np

import math as m

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

x=np.matrix([[2.5,2.5,1],[5,2.5,1],[5,5,1],[2.5,5,1]])

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])
plot(x1,y1,Z1,label='original object',color='blue')

t1=np.matrix([[1,0,0],[0,1,0],[-2,-5,1]])

t2=np.matrix([[0,1,0],[-1,0,0],[0,0,1]])

t3=np.matrix([[1,0,0],[0,1,0],[2,5,1]])

t=t1*t2*t3

x=x*t

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='Rotated Object',color='black')

print(x1,y1,z1)

grid()

legend()

show()

# Reflection through the line y=5 #

from matplotlib.pyplot import*

import numpy as np

import math as m

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')
x=np.matrix([[2.5,2.5,1],[5,2.5,1],[5,5,1],[2.5,5,1]])

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='original object',color='blue')

t1=np.matrix([[1,0,0],[0,1,0],[0,-5,1]])

x=x*t1

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='Translated Object1',color='Green')

t2=np.matrix([[1,0,0],[0,-1,0],[0,0,1]])

x=x*t2

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='Reflected Object2',color='red')

t3=np.matrix([[1,0,0],[0,1,0],[0,5,1]])

x=x*t3

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='INV Object3',color='black')

print(x1,y1,z1)
grid()

legend()

show()

# Reflection through the line y=5 by combine transformation matrix#

from matplotlib.pyplot import*

import numpy as np

import math as m

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

x=np.matrix([[2.5,2.5,1],[5,2.5,1],[5,5,1],[2.5,5,1]])

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='original object',color='blue')

t1=np.matrix([[1,0,0],[0,1,0],[0,-5,1]])

t2=np.matrix([[1,0,0],[0,-1,0],[0,0,1]])

t3=np.matrix([[1,0,0],[0,1,0],[0,5,1]])

t=t1*t2*t3

x=x*t

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])
Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='Reflected Object3',color='black')

print(x1,y1,z1)

grid()

legend()

show()

# Reflection through the line y=x+1 #

from matplotlib.pyplot import*

import numpy as np

import math as m

p=[-10,10]

q=[0,0]

plot(p,q,label='x axis',color='black')

plot(q,p,label='y axis',color='black')

x=np.matrix([[2.5,2.5,1],[5,2.5,1],[5,5,1],[2.5,5,1]])

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='original object',color='blue')

t1=np.matrix([[1,0,0],[0,1,0],[0,-1,1]])

t2=np.matrix([[0.707,-0.707,0],[0.707,0.707,0],[0,0,1]])
t3=np.matrix([[1,0,0],[0,-1,0],[0,0,1]])

t4=np.matrix([[0.707,0.707,0],[-0.707,0.707,0],[0,0,1]])

t5=np.matrix([[1,0,0],[0,1,0],[0,1,1]])

t=t1*t2*t3*t4*t5

x=x*t

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

Z1=(x[0,2],x[1,2],x[2,2],x[3,2],x[0,2])

plot(x1,y1,Z1,label='Reflected Object3',color='black')

print(x1,y1,z1)

grid()

legend()

show()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy