Miscelaneous Python 2
Miscelaneous Python 2
import numpy as np
x=np.matrix([[0,0],[5,0],[3,3]])
x1=(x[0,0],x[1,0],x[2,0])
y1=(x[0,1],x[1,1],x[2,1])
a=sqrt((x[1,0]-x[0,0])**2+(x[1,1]-x[0,1])**2)
print(a)
b=sqrt((x[2,0]-x[0,0])**2+(x[2,1]-x[0,1])**2)
print(b)
c=sqrt((x[2,0]-x[1,0])**2+(x[2,1]-x[1,1])**2)
print(c)
# Perimeter of triangle
p=a+b+c
print(p)
# Area of a triangle
s=(a+b+c)/2
A=s*(s-a)*(s-b)*(s-c)
area=sqrt(A)
print(area)
import numpy as np
x=np.matrix([4,-2])
t1=np.matrix([[1,0],[0,-1]])
x=x*t1
print(x)
t2=np.matrix([[-1,0],[0,-1]])
x=x*t2
print(x)
t3=np.matrix([[1,-3],[2,1]])
x=x*t3
print(x)
a=np.cos(57)
b=np.sin(57)
t4=np.matrix([[a,b],[-b,a]])
x=x*t4
print(x)
# Generate line passing through points (2,3)and (4,1) and find equation of line
p=Point(2,3)
q=Point(4,1)
l=Line(p,q)
l.equation()
# Using python generate triangle with vertices A[0,0],B[4,0],[4,3] and check whether it is right angled
x1=(x[0,0],x[1,0],x[2,0])
y1=(x[0,1],x[1,1],x[2,1])
a=sqrt((x[1,0]-x[0,0])**2+(x[1,1]-x[0,1])**2)
print(a)
b=sqrt((x[2,0]-x[0,0])**2+(x[2,1]-x[0,1])**2)
print(b)
c=sqrt((x[2,0]-x[1,0])**2+(x[2,1]-x[1,1])**2)
print(c)
else:
# Write python program to plot 2D x-axix,y-axis in black color . In the same digram, plot
import numpy as np
x=np.matrix([[5,4],[7,4],[6,6]])
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="Triangle",color="Green")
import numpy as np
x=np.matrix([[2,2],[10,2],[10,8],[2,8]])
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="Rectangle",color="blue")
p=[-10,10]
q=[0,0]
plot(p,q)
plot(q,p)
x=matrix([[6,2],[10,4],[8,7],[4,8],[2,4]])
x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[4,0],x[0,0])
y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[4,1],x[0,1])
plot(x1,y1,label="Polygon",color="red")
grid()
import numpy as np
x=np.matrix([[0,0],[4,0],[2,4]])
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="Iso Triangle",color="orange")
# Using python rotate line segment by 180 degree having end points (1,0),(2,-1)
import numpy as np
x=np.matrix([[1,0],[2,-1]])
x1=(x[0,0],x[1,0])
y1=(x[0,1],x[1,1])
plot(x1,y1,label="Given Segment",color="orange")
a=np.cos(180)
b=np.sin(180)
t=np.matrix([[a,b],[-b,a]])
x=x*t
x1=(x[0,0],x[1,0])
y1=(x[0,1],x[1,1])
plot(x1,y1,label="Rotated Segment",color="red")