Professional Documents
Culture Documents
EXPERIMENT-9
By – Shivank Gupta 2K19/CO/364
AIM
Write a program to implement rotation of an object
Code:
import math
plt.style.use('seaborn')
plt.figure(figsize=(7,7))
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.xlim(-50,150)
plt.ylim(-50,150)
plt.title("Rotation")
def line(x1,y1,x2,y2,c,l) :
xl = [x1, x2]
yl = [y1, y2]
plt.plot(xl, yl, color=c,label = l)
def polygon(x1,y1,x2,y2,x3,y3,x4,y4,c,l) :
sa = 0 * math.pi / 180
xl = []
yl = []
theta = sa
x = r * math.cos(theta)
y = r * math.sin(theta)
xl.append(x+xc)
yl.append(y+yc)
theta += 0.01
sa = 0 * math.pi / 180
xl = []
yl = []
theta = sa
x = rx * math.cos(theta)
y = ry * math.sin(theta)
xl.append(x+xc)
yl.append(y+yc)
theta += 0.01
print("1. Line")
print("2. Polygon")
print("3. Circle")
print("4. Ellipse")
choice = int(input("Enter your choice : "))
if choice == 1 :
x1 = int(input("x1 : "))
y1 = int(input("y1 : "))
x2 = int(input("x2 : "))
y2 = int(input("y2 : "))
line(x1,y1,x2,y2,"red","Original Line")
elif choice == 2 :
x1 = int(input("x1 : "))
y1 = int(input("y1 : "))
x2 = int(input("x2 : "))
y2 = int(input("y2 : "))
x3 = int(input("x3 : "))
y3 = int(input("y3 : "))
x4 = int(input("x4 : "))
y4 = int(input("y4 : "))
elif choice == 3 :
x = int(input("x : "))
y = int(input("y : "))
r = int(input("r : "))
theta = int(input("theta : "))
x_ = x * math.cos(theta) - y * math.sin(theta)
y_ = x * math.sin(theta) + y * math.cos(theta)
elif choice == 4 :
x = int(input("x : "))
y = int(input("y : "))
rx = int(input("rx : "))
ry = int(input("ry : "))
x_ = x * math.cos(theta) - y * math.sin(theta)
y_ = x * math.sin(theta) + y * math.cos(theta)
plt.show()
OUTPUT :