def perpendicular_angle(parallel: Parallel, finder: Finder) -> None: line1 = finder.extend_line(parallel.line1) line2 = finder.extend_line(parallel.line2) link1 = finder.find_link_by_ends(*line1.ends) link2 = finder.find_link_by_ends(*line2.ends) col1 = Collineation('Collineation ' + line1.id, points=link1) col2 = Collineation('Collineation ' + line2.id, points=link2) for angle1, angle2 in _find_alternate_angels(col1, col2, finder): yield symbol(angle1, 'angle') - symbol(angle2, 'angle')
def common_vertex_angle_sum(common_vertex_angle: CommonVertexAngle, finder: Finder) -> None: lines = common_vertex_angle.lines num_lines = len(lines) for i in range(num_lines): for j in range(i + 1, num_lines): for k in range(j + 1, num_lines): angle_ij = finder.find_angle_by_sides(lines[i], lines[j]) angle_jk = finder.find_angle_by_sides(lines[j], lines[k]) angle_ik = finder.find_angle_by_sides(lines[i], lines[k]) yield symbol(angle_ij, 'angle') \ + symbol(angle_jk, 'angle') \ - symbol(angle_ik, 'angle')
def similar_triangle_determination(triangle: Triangle, finder: Finder) -> None: known_angles = triangle.known_angles if len(known_angles) < 3: return triangle_set = finder.find_all_triangles() for t in triangle_set: if t == triangle or len(t.known_angles) < 3: continue angles1 = [known_angles[0].angle, \ known_angles[1].angle, \ known_angles[2].angle] angles2 = [t.known_angles[0].angle, \ t.known_angles[1].angle, \ t.known_angles[2].angle] if set(angles1) == set(angles2): corresponding = [] for a1 in known_angles: for a2 in t.known_angles: if a1.angle == a2.angle: corresponding.append((a1, a2)) ratio = None for a1, a2 in corresponding: line1 = triangle.opposite_side(a1) line2 = t.opposite_side(a2) if line1.length is not None and line2.length is not None: ratio = line1.length / line2.length r = SimilarTriangle( '_'.join(['similar_triangle', triangle.id, t.id]), triangle1=triangle, triangle2=t, corresponding=corresponding, ratio=ratio) yield r
def collineation_line_length_sum(collineation: Collineation, finder: Finder) -> None: points = collineation.points num_points = len(points) if num_points < 3: return for i in range(num_points): for j in range(i + 1, num_points): for k in range(j + 1, num_points): line_ij = finder.find_line_by_ends(points[i], points[j]) line_jk = finder.find_line_by_ends(points[j], points[k]) line_ik = finder.find_line_by_ends(points[i], points[k]) yield symbol(line_ij, 'length') \ + symbol(line_jk, 'length') \ - symbol(line_ik, 'length')
def n_angle_sector_ratio(n_angle_sector: NAngleSector, finder: Finder) -> None: angle = n_angle_sector.angle line = n_angle_sector.line ratio = n_angle_sector.ratio nearer_line = n_angle_sector.nearer_line if nearer_line is None: nearer_line = angle.sides[0] angle_mid = finder.find_angle_by_sides(line, nearer_line) yield symbol(angle, 'angle') * ratio - symbol(angle_mid, 'angle')
def n_line_sector_ratio(n_line_sector: NLineSector, finder: Finder) -> None: line = n_line_sector.line ratio = n_line_sector.ratio A = n_line_sector.nearer_point if A is None: A = line.ends[0] B = n_line_sector.point AB = finder.find_line_by_ends(A, B) yield symbol(line, 'length') * ratio - symbol(AB, 'length')
def __init__(self, problem: Problem, equation_pool: EquationSolver, solving_path: Path, new_objects: set): self.problem = problem self.equation_pool = equation_pool self.solving_path = solving_path self.new_objects = new_objects self.finder = Finder(problem.entity, problem.relationships) self._theory_obj_pairs = self._gen_object_theory_pairs() self.targets_info = []
def perpendicular_angle(perpendicular: Perpendicular, finder: Finder) -> None: line1 = perpendicular.line1 line2 = perpendicular.line2 # Extend line first. line1 = finder.extend_line(line1) line2 = finder.extend_line(line2) # Find intersection. intersection = finder.find_lines_intersection(line1, line2) if len(intersection) != 1: raise Exception('Perpendicular relationship is suppposed to include ' 'two perpendicular line. Except 1, got {}.' .format(len(intersection))) cross_p = intersection[0] for p1 in line1.ends: for p2 in line2.ends: if p1 == cross_p or p2 == cross_p: continue line1_ = finder.find_line_by_ends(p1, cross_p) line2_ = finder.find_line_by_ends(p2, cross_p) angle = finder.find_angle_by_sides(line1_, line2_) yield symbol(angle, 'angle') - 90
def _get_angles_fixed_ends(col1: Collineation, col2: Collineation, end1: Point, end2: Point, finder: Finder): for top_p in col1.points: if top_p == end1: continue for bottom_p in col2.points: if bottom_p == end2: continue top_line = finder.find_line_by_ends(end1, top_p) middle_line = finder.find_line_by_ends(top_p, bottom_p) bottom_line = finder.find_line_by_ends(bottom_p, end2) # print('top line=============', top_line) # print('middle line============', middle_line) # print('bottom line============', bottom_line) if top_line is None \ or middle_line is None \ or bottom_line is None: continue top_angle = finder.find_angle_by_sides(top_line, middle_line) bottom_angle = finder.find_angle_by_sides(bottom_line, middle_line) # print('top angle==============', top_angle) # print('bottom angle==============', bottom_angle) if top_angle is not None and bottom_angle is not None: yield top_angle, bottom_angle