Prac 4
Prac 4
In [3]: 1 x=[2,3,7]
2 y=[4,-6,8]
3 def get_area(X,y):
4 area=0.5*(x[0]*(y[1]-y[2])+x[1]*(y[2]-y[0])+x[2]*(y[0]-y[1]))
5 return int(area)
6 coordinates=zip(x,y)
7 print(f"area of triangle ABC is {get_area(x,y)}sq.unit")
In [6]: 1 p1,p2=Point(0,0),Point(10,10)
2 s1=Segment(p1,p2)
3 s1.midpoint
Out[6]: 𝑃𝑜𝑖𝑛𝑡2𝐷(5,5)
In [11]: 1 import matplotlib.pyplot as plt
2 x1,y1=0,0
3 x2,y2=10,10
4 midpoint=((x1+x2)/2,(y1+y2)/2)
5 plt.figure(figsize=(6,6))
6 plt.plot([x1,x2],[y1,y2],label='Line segment',color='blue')
7 plt.scatter(midpoint[0],midpoint[1],color='red',label='midpoint(5,5)')
8 plt.text(midpoint[0]+0.2,midpoint[1]+0.2,f'Midpoint{midpoint}',color='red'
9 plt.axis('equal')
10 plt.grid(True)
11 plt.legend()
12 plt.show()
In [15]: 1 import math
2 import matplotlib.pyplot as plt
3 def distance (p1,p2):
4 return math.sqrt((p2[0]-p1[0])**2 + (p2[1]-p1[1])**2)
5 def is_right_angle_triangle(a,b,c):
6 sides=sorted([a,b,c])
7 return math.isclose(sides[0]**2+sides[1]**2,sides[2]**2)
8 A=(0,0)
9 B=(4,0)
10 C=(4,3)
11 AB=distance(A,B)
12 BC=distance(B,C)
13 CA=distance(C,A)
14 if is_right_angle_triangle(AB,BC,CA):
15 print("the triangle is right angled triangle")
16 else:
17 print("the tringle is not right angled triangle")
18 plt.figure(figsize=(6,6))
19 plt.plot([A[0],B[0]],[A[1],B[1]],label=f"AB:{AB:.2f}",color="blue")
20 plt.plot([B[0],C[0]],[B[1],C[1]],label=f"BC:{BC:.2f}",color="red")
21 plt.plot([C[0],A[0]],[C[1],A[1]],label=f"CA:{CA:.2f}",color="green")
22 plt.scatter([A[0],B[0],C[0]],[A[1],B[1],c[1]],color="black")
23 plt.text(A[0],A[1],'A(0,0)',fontsize=12,verticalalignment='bottom',horizon
24 plt.text(B[0],B[1],'B(3,4)',fontsize=12,verticalalignment='bottom',horizon
25 plt.text(C[0],C[1],'C(0,0)',fontsize=12,verticalalignment='top',horizontal
26 plt.xlim(-1,7)
27 plt.ylim(-1,5)
28 plt.title("Triangle and Right-Angle check")
29 plt.xlabel("X-axis")
30 plt.ylabel("Y-axis")
31 plt.legend()
32 plt.show()