def is_isosceles(graph, this_triangle): is_isosceles_result = False vertex_point = '' aside_points = () """ every vertex """ for point_vertex in this_triangle: point_aside = tuple_del(this_triangle, point_vertex) if (graph.query( equal(segment(point_aside[0], point_vertex), segment(point_aside[1], point_vertex)), 'segment')) or (graph.query( equal(angle(point_vertex, point_aside[0], point_aside[1]), angle(point_vertex, point_aside[1], point_aside[0])), 'angle')): is_isosceles_result = True vertex_point = point_vertex aside_points = point_aside return is_isosceles_result, vertex_point, aside_points """ return judge result """ return is_isosceles_result, vertex_point, aside_points
def math_str_to_unit(this_unit_math_str): """ judge unit type""" if ('+' not in this_unit_math_str) and ('*' not in this_unit_math_str): if '°' in this_unit_math_str: return degree(int(this_unit_math_str[:-1])) elif '∠' in this_unit_math_str: return angle(this_unit_math_str[1], this_unit_math_str[2], this_unit_math_str[3]) else: return segment(this_unit_math_str[0], this_unit_math_str[1]) """ complex split """ split_sum_list = [] sub_sum = '' for sub_sum_part in this_unit_math_str.split('+'): sub_sum = sub_sum + sub_sum_part + '+' if sub_sum.count('(') - sub_sum.count(')') == 0: split_sum_list.append(sub_sum[:-1]) sub_sum = '' result_unit = sum_units() for sub_sum in split_sum_list: split_multiply_list = [] sub_multiply = '' for sub_multiply_part in sub_sum.split('*'): sub_multiply = sub_multiply + sub_multiply_part + '*' if sub_multiply.count('(') - sub_multiply.count(')') == 0: if sub_multiply[0] == '(' and sub_multiply[-2] == ')': sub_multiply = sub_multiply[1:-2] else: sub_multiply = sub_multiply[:-1] split_multiply_list.append(sub_multiply) sub_multiply = '' result_sub_sum_unit = multiply_units() for sub_multiply in split_multiply_list: result_sub_sum_unit = multiply_units( result_sub_sum_unit, math_str_to_unit(sub_multiply)) result_unit = sum_units(result_unit, result_sub_sum_unit) return result_unit
def is_congruent(graph, triangle_1, triangle_2): is_congruent_result = False three_points_1 = () three_points_2 = () """ every double vertex """ for point_vertex_1 in triangle_1: point_aside_1 = tuple_del(triangle_1, point_vertex_1) for point_vertex_2 in triangle_2: point_aside_2 = tuple_del(triangle_2, point_vertex_2) """ A or S """ if graph.query( equal( angle(point_aside_1[0], point_vertex_1, point_aside_1[1]), angle(point_aside_2[0], point_vertex_2, point_aside_2[1])), 'angle'): for point_aside_1_1 in point_aside_1: point_aside_1_2 = tuple_del(point_aside_1, point_aside_1_1)[0] point_aside_2_1 = point_aside_2[0] point_aside_2_2 = point_aside_2[1] """ AS """ if graph.query( equal(segment(point_aside_1_1, point_vertex_1), segment(point_aside_2_1, point_vertex_2)), 'segment'): """ ASS """ if graph.query( equal(segment(point_aside_1_2, point_vertex_1), segment(point_aside_2_2, point_vertex_2)), 'segment'): is_congruent_result = True three_points_1 = (point_aside_1_1, point_vertex_1, point_aside_1_2) three_points_2 = (point_aside_2_1, point_vertex_2, point_aside_2_2) return is_congruent_result, three_points_1, three_points_2 elif graph.query( equal(segment(point_aside_1[0], point_aside_1[1]), segment(point_aside_2[0], point_aside_2[1])), 'segment'): for point_aside_1_1 in point_aside_1: point_aside_1_2 = tuple_del(point_aside_1, point_aside_1_1)[0] point_aside_2_1 = point_aside_2[0] point_aside_2_2 = point_aside_2[1] """ SS or SA""" if graph.query( equal(segment(point_aside_1_1, point_vertex_1), segment(point_aside_2_1, point_vertex_2)), 'segment'): """ SSS """ if graph.query( equal(segment(point_aside_1_2, point_vertex_1), segment(point_aside_2_2, point_vertex_2)), 'segment'): is_congruent_result = True three_points_1 = (point_aside_1_1, point_vertex_1, point_aside_1_2) three_points_2 = (point_aside_2_1, point_vertex_2, point_aside_2_2) return is_congruent_result, three_points_1, three_points_2 elif graph.query( equal( angle(point_vertex_1, point_aside_1_1, point_aside_1_2), angle(point_vertex_2, point_aside_2_1, point_aside_2_2)), 'angle'): """ SAA """ if graph.query( equal( angle(point_vertex_1, point_aside_1_2, point_aside_1_1), angle(point_vertex_2, point_aside_2_2, point_aside_2_1)), 'angle'): is_congruent_result = True three_points_1 = (point_aside_1_1, point_vertex_1, point_aside_1_2) three_points_2 = (point_aside_2_1, point_vertex_2, point_aside_2_2) return is_congruent_result, three_points_1, three_points_2 """ return judge result """ return is_congruent_result, three_points_1, three_points_2
def space_and_collinear_transform(graph): """ find collinear """ three_points_list = list(combinations(graph.points.keys(), 3)) triangles_list = three_points_list.copy() collinear_list = [] for this_three_point in three_points_list: yes_collinear, vertex_point, aside_points = is_collinear( graph, this_three_point) if yes_collinear: triangles_list.remove(this_three_point) collinear_list.append( (aside_points[0], vertex_point, aside_points[1])) graph.triangles_list = triangles_list graph.collinear_list = collinear_list """ collinear transform """ for this_collinear in collinear_list: graph.add_equal( equal( sum_units( segment(this_collinear[0], this_collinear[1]), segment(this_collinear[2], this_collinear[1])), segment(this_collinear[0], this_collinear[2])), 'segment') out_points = tuple_except_tuple(graph.points.keys(), this_collinear) for point_out in out_points: if not is_collinear( graph, (point_out, this_collinear[0], this_collinear[1]))[0]: graph.add_equal( equal( sum_units( angle(point_out, this_collinear[1], this_collinear[0]), angle(point_out, this_collinear[1], this_collinear[2])), degree(180)), 'angle') graph.add_equal( equal( angle(point_out, this_collinear[0], this_collinear[1]), angle(point_out, this_collinear[0], this_collinear[2])), 'angle') graph.add_equal( equal( angle(point_out, this_collinear[2], this_collinear[1]), angle(point_out, this_collinear[2], this_collinear[0])), 'angle') """ not collinear transform """ for this_triangle in triangles_list: out_points = tuple_except_tuple(graph.points.keys(), this_triangle) for point_vertex in this_triangle: point_aside = tuple_del(this_triangle, point_vertex) for point_out in out_points: degree_1 = cal_an_angle_degree(graph, point_out, point_vertex, point_aside[0]) degree_2 = cal_an_angle_degree(graph, point_out, point_vertex, point_aside[1]) degree_sum = cal_an_angle_degree( graph, point_aside[0], point_vertex, point_aside[1]) if degree_1 > 5.0 and degree_2 > 5.0 and abs( degree_sum - degree_1 - degree_2) < 2.0: graph.add_equal( equal( sum_units( angle(point_out, point_vertex, point_aside[0]), angle(point_out, point_vertex, point_aside[1])), angle(point_aside[0], point_vertex, point_aside[1])), 'angle')
def quadrilateral_theorem_transform(graph): triangles_list = graph.triangles_list for this_triangle in triangles_list: out_points = tuple_except_tuple(graph.points.keys(), this_triangle) for point_vertex in this_triangle: point_aside = tuple_del(this_triangle, point_vertex) for point_out in out_points: """ coexist with a circle """ if graph.query( equal( sum_units( angle(point_out, point_vertex, point_aside[0]), angle(point_out, point_vertex, point_aside[1])), angle(point_aside[0], point_vertex, point_aside[1])), 'angle'): if graph.query(equal(sum_units(angle(point_aside[0], point_vertex, point_aside[1]), angle(point_aside[0], point_out, point_aside[1])), degree(180)), 'angle') or \ graph.query(equal(angle(point_out, point_vertex, point_aside[1]), angle(point_out, point_aside[0], point_aside[1])), 'angle') or \ graph.query(equal(angle(point_out, point_vertex, point_aside[0]), angle(point_out, point_aside[1], point_aside[0])), 'angle'): graph.add_equal( equal( angle(point_out, point_vertex, point_aside[1]), angle(point_out, point_aside[0], point_aside[1])), 'angle') graph.add_equal( equal( angle(point_out, point_vertex, point_aside[0]), angle(point_out, point_aside[1], point_aside[0])), 'angle') graph.add_equal( equal( angle(point_vertex, point_out, point_aside[1]), angle(point_vertex, point_aside[0], point_aside[1])), 'angle') graph.add_equal( equal( angle(point_vertex, point_out, point_aside[0]), angle(point_vertex, point_aside[1], point_aside[0])), 'angle')
def triangle_theorem_transform(graph): triangles_list = graph.triangles_list triangles_num = len(triangles_list) for no_1 in range(triangles_num): this_triangle = triangles_list[no_1] """ interior angle summation 180° """ graph.add_equal( equal( sum_units( angle(this_triangle[1], this_triangle[0], this_triangle[2]), angle(this_triangle[0], this_triangle[1], this_triangle[2]), angle(this_triangle[0], this_triangle[2], this_triangle[1])), degree(180)), 'angle') """ isosceles """ yes_isosceles, vertex_point, aside_points = is_isosceles( graph, this_triangle) if yes_isosceles: graph.add_equal( equal(segment(vertex_point, aside_points[0]), segment(vertex_point, aside_points[1])), 'segment') graph.add_equal( equal( angle(vertex_point, aside_points[0], aside_points[1]), angle(vertex_point, aside_points[1], aside_points[0])), 'angle') """ congruent and similar """ for no_2 in range(no_1 + 1, triangles_num): another_triangle = triangles_list[no_2] """ congruent """ yes_congruent, three_points_1, three_points_2 = is_congruent( graph, this_triangle, another_triangle) if yes_congruent: graph.add_equal( equal( segment(three_points_1[0], three_points_1[1]), segment(three_points_2[0], three_points_2[1])), 'segment') graph.add_equal( equal( segment(three_points_1[0], three_points_1[2]), segment(three_points_2[0], three_points_2[2])), 'segment') graph.add_equal( equal( segment(three_points_1[1], three_points_1[2]), segment(three_points_2[1], three_points_2[2])), 'segment') graph.add_equal( equal( angle(three_points_1[1], three_points_1[0], three_points_1[2]), angle(three_points_2[1], three_points_2[0], three_points_2[2])), 'angle') graph.add_equal( equal( angle(three_points_1[0], three_points_1[1], three_points_1[2]), angle(three_points_2[0], three_points_2[1], three_points_2[2])), 'angle') graph.add_equal( equal( angle(three_points_1[0], three_points_1[2], three_points_1[1]), angle(three_points_2[0], three_points_2[2], three_points_2[1])), 'angle') """ similar """ yes_similar, three_points_1, three_points_2 = is_similar( graph, this_triangle, another_triangle) if yes_similar: graph.add_equal( equal( multiply_units( segment(three_points_1[0], three_points_1[1]), segment(three_points_2[1], three_points_2[2])), multiply_units( segment(three_points_1[1], three_points_1[2]), segment(three_points_2[0], three_points_2[1]))), 'segment') graph.add_equal( equal( multiply_units( segment(three_points_1[0], three_points_1[1]), segment(three_points_2[0], three_points_2[2])), multiply_units( segment(three_points_1[0], three_points_1[2]), segment(three_points_2[0], three_points_2[1]))), 'segment') graph.add_equal( equal( multiply_units( segment(three_points_1[0], three_points_1[2]), segment(three_points_2[1], three_points_2[2])), multiply_units( segment(three_points_1[1], three_points_1[2]), segment(three_points_2[0], three_points_2[2]))), 'segment') graph.add_equal( equal( angle(three_points_1[1], three_points_1[0], three_points_1[2]), angle(three_points_2[1], three_points_2[0], three_points_2[2])), 'angle') graph.add_equal( equal( angle(three_points_1[0], three_points_1[1], three_points_1[2]), angle(three_points_2[0], three_points_2[1], three_points_2[2])), 'angle') graph.add_equal( equal( angle(three_points_1[0], three_points_1[2], three_points_1[1]), angle(three_points_2[0], three_points_2[2], three_points_2[1])), 'angle')