Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #incentre7.py works ok. Puts in 3 yellow bisector lines that meet at incentre
- import math
- import matplotlib.pyplot as plt
- def line_equation2(p1, p2):
- x1, y1 = p1
- x2, y2 = p2
- m = (y2 - y1) / (x2 - x1) if x2 != x1 else float('inf')
- b = y1 - m * x1 if m != float('inf') else None
- #print("m,b",m,b)
- return (m,b)
- def intersection2(L1,L2): #where L1 is line (m,c)
- m1,b1 = L1
- m2,b2 = L2 #Pb lines here
- if m1 == m2:
- return None # Lines are parallel
- if m1 == float('inf'):
- x = b1
- y = m2 * x + b2
- elif m2 == float('inf'):
- x = b2
- y = m1 * x + b1
- else:
- x = (b2 - b1) / (m1 - m2)
- y = m1 * x + b1
- return (x, y) #so returns a point as an ordered pair
- def line_equation(p1, p2):
- x1, y1 = p1
- x2, y2 = p2
- m = (y2 - y1) / (x2 - x1) if x2 != x1 else float('inf')
- b = y1 - m * x1 if m != float('inf') else None
- return (m, b)
- def equations_of_sides_of_triangle(VA,VB,VC):
- Line_AB= line_equation(VA,VB)
- Line_BC= line_equation(VB,VC)
- Line_CA= line_equation(VC,VA)
- return Line_AB,Line_BC,Line_CA
- def incentre_info(V1,V2,V3):
- ## def line_equation(p1, p2):
- ## x1, y1 = p1
- ## x2, y2 = p2
- ## m = (y2 - y1) / (x2 - x1) if x2 != x1 else float('inf')
- ## b = y1 - m * x1 if m != float('inf') else None
- Line_AB= line_equation(V1,V2)
- Line_BC= line_equation(V2,V3)
- Line_CA= line_equation(V3,V1)
- x1,y1=V1
- x2,y2 = V2
- x3,y3 = V3
- # Calculate the lengths of the three sides
- print('Vertices are A,B,C ', x1,y1,x2,y2,x3,y3)
- c = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
- a = math.sqrt((x3 - x2)**2 + (y3 - y2)**2)
- b = math.sqrt((x1 - x3)**2 + (y1 - y3)**2)
- # Calculate the semi-perimeter
- s = (a + b + c) / 2
- # Calculate the area of the triangle
- area = 0.5 * (a * b * math.sin(math.acos((a**2 + b**2 - c**2) / (2 * a * b))))
- # Calculate the center and radius of the incircle
- x_center = (a * x1 + b * x2 + c * x3) / (a + b + c)
- y_center = (a * y1 + b * y2 + c * y3) / (a + b + c)
- I = (x_center,y_center) #I = incentre
- radius = area / s
- #medianA = line_equation(vertexA,mpBC) #median from A
- angle_bisector_lineA = line_equation2(V1,I) #median from A
- angle_bisector_lineB = line_equation2(V2,I) #median from A
- angle_bisector_lineC = line_equation2(V3,I) #median from A
- foot_of_bisector_of_A = intersection2(angle_bisector_lineA,Line_BC)
- foot_of_bisector_of_B = intersection2(angle_bisector_lineB,Line_CA)
- foot_of_bisector_of_C = intersection2(angle_bisector_lineC,Line_AB)
- angle_bisectors = (angle_bisector_lineA,angle_bisector_lineB,angle_bisector_lineC)
- #angle_bisectors2 = [angle_bisector_lineA,angle_bisector_lineB,angle_bisector_lineC]
- feet_of_angle_bisectors =(foot_of_bisector_of_A, foot_of_bisector_of_B,foot_of_bisector_of_C)
- #return angle_bisector_lineA,angle_bisector_lineB,angle_bisector_lineC, foot_of_bisector_of_A, foot_of_bisector_of_B,foot_of_bisector_of_C
- group_angle_bisectors = I, angle_bisectors, feet_of_angle_bisectors
- # return I, angle_bisectors, feet_of_angle_bisectors #so returns I-tuple, 3 tuples for lines, 3 tuples for feet
- return group_angle_bisectors
- vertexA = (0,0)
- vertexB =(60,10)
- vertexC =(30,60)
- angleBisectorInfo = incentre_info(vertexA,vertexB,vertexC)
- incentrePoint, bisectors, bisector_feet = angleBisectorInfo
- incentrex, incentrey = incentrePoint
- fA,fB,fC = bisector_feet
- fAx,fAy =fA
- fBx,fBy =fB
- fCx,fCy =fC
- fig, ax = plt.subplots(figsize=(6, 6))
- Ax,Ay = vertexA
- Bx,By = vertexB
- Cx,Cy = vertexC
- circle = plt.Circle((incentrex, incentrey), 0.5, fill=False, color='y')
- ax.add_artist(circle)
- ax.plot([Ax,Bx,Cx,Ax], [Ay,By,Cy,Ay], 'b-', linewidth=2) #this plots the triangle
- ax.plot([Ax,fAx], [Ay, fAy], 'y-', linewidth=1)
- ax.plot([Bx,fBx], [By, fBy], 'y-', linewidth=1)
- ax.plot([Cx,fCx], [Cy, fCy], 'y-', linewidth=1)
- plt.show()
- three_lines=equations_of_sides_of_triangle(vertexA,vertexB,vertexC)
- print("three lines are ", three_lines)
- #result = drop_perpendicular(x1,y1, x2, y2, x3, y3):
- result=incentre_info(vertexA,vertexB,vertexC)
- print(f"incentre information:incentre,angle_bisectors,feet=,{result}")
- #print('Area = ', area)
- #Find feet of angle_bisectors and sides of triangle ie. where does ..
- #..angle_bisector_lineA cut line_BC.
- #Use intersection2(L1,L2). ie intersection2(angle_bisector_lineA,line_BC)...
- #Call this foot_of_bisector_ofA
- #foot_of_bisector_of_A = intersection2(angle_bisector_lineA,line_BC)
- #print("Footof bisector of A is ", foot_of_besector_of_A)
- #The feet look OK for bisector of A,B but not for C
- # No, seems Ok now correction been made.
- #Next add incentre coords to final major return statement around line 75
- #works ok. See return statement around line 79.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement