def eyes_add_highlight(image, face_landmarks): """Add highlight in eyes This function can uses for many people """ highlight = cv2.imread( CURRENT_DIRNAME + '/eyes_highlight.png', cv2.IMREAD_UNCHANGED) line1 = Segment(Point(landmark[134]), Point(landmark[145])) line2 = Segment(Point(landmark[139]), Point(landmark[150])) ls = intersection(line1, line2) dx, dy = (landmark[150] - landmark[139]) / 5 x, y = int(ls[0].x) - dx, int(ls[0].y) - dy w = np.linalg.norm(landmark[150] - landmark[139]) ratio = w / highlight.shape[1] * 100 x = int(x - highlight.shape[0] * (ratio / 100) / 2) y = int(y - highlight.shape[1] * (ratio / 100) / 2) image = merge(image, highlight, x, y, ratio) line1 = Segment(Point(landmark[114]), Point(landmark[124])) line2 = Segment(Point(landmark[120]), Point(landmark[129])) ls = intersection(line1, line2) dx, dy = (landmark[129] - landmark[120]) / 5 x, y = int(ls[0].x) - dx, int(ls[0].y) - dy w = np.linalg.norm(landmark[129] - landmark[120]) ratio = w / highlight.shape[1] * 100 x = int(x - highlight.shape[0] * (ratio / 100) / 2) y = int(y - highlight.shape[1] * (ratio / 100) / 2) image = merge(image, highlight, x, y, ratio) return image
def line_walk_double_edges_e(he, ray, b): nxt = he.nxt prev = he.prev v1 = he.node v2 = nxt.node v3 = prev.node s = Segment(v1.p, v2.p) inter = intersection(s, ray) if inter != [] and is_segment(inter[0]): end_node = v1 if ray.contains(v2.p): end_node = v2 yield from line_walk_double_edges_v(end_node, Ray(end_node.p, b), b) raise StopIteration e1 = Segment(v1.p, v3.p) e2 = Segment(v3.p, v2.p) inter1 = intersection(e1, ray) inter2 = intersection(e2, ray) if inter1 != [] and inter2 != []: yield from line_walk_double_edges_v(v3, Ray(inter1[0], b), b) raise StopIteration if inter1 != []: yield e1 if (prev.twin != None): yield from line_walk_double_edges_e(prev.twin, Ray(inter1[0], b), b) raise StopIteration if inter2 != []: yield e2 if (nxt.twin != None): yield from line_walk_double_edges_e(nxt.twin, Ray(inter2[0], b), b) raise StopIteration raise StopIteration
def findCircle(circle): p3 = intersection(circle, l2)[0] # Kraschar här. l3 = l2.perpendicular_line(p3) p5 = intersection(l3, l0)[0] p6 = intersection(l3, X)[0] t1 = Triangle(p5, p2, p6) return t1.incircle
def get_intersections(self, wire): inters = [] for segment1 in self.segments: for segment2 in wire.segments: if intersection(segment1, segment2): inters.append(intersection(segment1, segment2)[0]) return inters
def line_walk_nodes_and_edges_and_triangles_v(node, ray, b): for n_triangles in node.triangles: for n_edge in n_triangles.edges: end_node = None if n_edge.nodes[0] == node: end_node = n_edge.nodes[1] elif n_edge.nodes[1] == node: end_node = n_edge.nodes[0] else: continue s = Segment(node.p, end_node.p) inter = intersection(s, ray) if inter != [] and is_segment(inter[0]): yield s yield from line_walk_nodes_and_edges_and_triangles_v(end_node, Ray(end_node.p, b), b) raise StopIteration for n_triangles in node.triangles: for n_edge in n_triangles.edges: if n_edge.nodes[0] != node and n_edge.nodes[1] != node: node_i = n_edge.nodes[0] node_j = n_edge.nodes[1] s = Segment(node_i.p, node_j.p) inter = intersection(s, ray) if inter != []: yield s yield from line_walk_nodes_and_edges_and_triangles_e(node_i, node_j, Ray(inter[0], b), b) raise StopIteration raise StopIteration
def during_collision(cue_point, radius, stick_point, ball_coord): future_point = cue_point collision_ball_info = cue_point min_distance = 1e9 temp_ray = Ray(cue_point, stick_point) temp_Line = Line(cue_point, stick_point) temp_circle = Circle(cue_point, radius) temp_collision_points = intersection(temp_Line, temp_circle) if temp_ray.contains(temp_collision_points[0]): white_ray = Ray(cue_point, temp_collision_points[1]) else: white_ray = Ray(cue_point, temp_collision_points[0]) for coord in ball_coord: enlarged_ball = Circle(Point(coord[0], coord[1]), coord[2] + radius) intersect_point = intersection(white_ray, enlarged_ball) if len(intersect_point) == 2 and cue_point.distance( intersect_point[0]) >= cue_point.distance(intersect_point[1]): temp_point = intersect_point[1] elif len(intersect_point) == 2 or len(intersect_point) == 1: temp_point = intersect_point[0] else: continue dist = cue_point.distance(temp_point) if min_distance > dist: min_distance = dist future_point = temp_point collision_ball_info = coord return future_point, collision_ball_info
def line_walk_nodes_and_edges_and_triangles_e(v1, v2, ray, b): s = Segment(v1.p, v2.p) edge = list(set(v1.edges) & set(v2.edges))[0] inter = intersection(s, ray) if (inter != [] and is_segment(inter[0])): end_node1 = edge.nodes[0] end_node2 = edge.nodes[1] if ray.contains(end_node2.p): end_node1 = end_node2 yield from line_walk_nodes_and_edges_and_triangles_v(end_node1, Ray(end_node1.p, b), b) raise StopIteration s_b = turn(cgPoint(int(b.x), int(b.y)), cgPoint(int(v1.p.x), int(v1.p.y)), cgPoint(int(v2.p.x), int(v2.p.y))) se = None for index, n_triangle in enumerate(edge.triangles): mb_e = set(n_triangle.edges) mb_e.remove(edge) mb_e = list(mb_e) o_v = list(set(mb_e[0].nodes) & set(mb_e[1].nodes))[0] if s_b != turn(cgPoint(int(o_v.p.x), int(o_v.p.y)), cgPoint(int(v1.p.x), int(v1.p.y)), cgPoint(int(v2.p.x), int(v2.p.y))): continue t_e1 = mb_e[0].nodes t_e2 = mb_e[1].nodes v1 = t_e1[0] v1_n = t_e1[1] e1 = Segment(v1.p, v1_n.p) v2 = t_e2[0] v2_n = t_e2[1] e2 = Segment(v2.p, v2_n.p) inter1 = intersection(e1, ray) inter2 = intersection(e2, ray) if inter1 != [] and inter2 != []: yield from line_walk_nodes_and_edges_and_triangles_v(o_v, Ray(inter1[0], b), b) raise StopIteration if inter1 != []: yield e1 yield from line_walk_nodes_and_edges_and_triangles_e(v1, v1_n, Ray(inter1[0], b), b) raise StopIteration if inter2 != []: yield e2 yield from line_walk_nodes_and_edges_and_triangles_e(v2, v2_n, Ray(inter2[0], b), b) raise StopIteration raise StopIteration
def find_circle(circle,A,C,D,i): AD = Line(A,D) svg.append(AD,"AD",i) K = intersection(circle, AD)[0] svg.append(K,"K",i) tangentK = Line(A,D).perpendicular_line(K) svg.append(tangentK,"tangK",i) P1 = intersection(tangentK, Line(A,C))[0] svg.append(P1,"P1",i) P2 = intersection(tangentK, xaxis)[0] svg.append(P2,"P2",i) T = Triangle(P1,A,P2) svg.append(T,"T",i) return T.incircle
def line_walk_nodes_and_triangles_e(v1, v2, ray, b): s_b = turn(cgPoint(int(b.x), int(b.y)), cgPoint(int(v1.p.x), int(v1.p.y)), cgPoint(int(v2.p.x), int(v2.p.y))) s = Segment(v1.p, v2.p) inter = intersection(s, ray) if inter != [] and is_segment(inter[0]): end_node = v1 if ray.contains(v2.p): end_node = v2 yield from line_walk_nodes_and_triangles_v(end_node, Ray(end_node.p, b), b) tp = set(v1.triangles) & set(v2.triangles) tp.discard(None) vs = list(tp) vp = [] for i in vs: ts = set(i.nodes) ts.discard(v1) ts.discard(v2) vp = vp + list(ts) v3 = [i for i in vp if s_b == turn(cgPoint(int(i.p.x), int(i.p.y)), cgPoint(int(v1.p.x), int(v1.p.y)), cgPoint(int(v2.p.x), int(v2.p.y))) ] if v3 == []: raise StopIteration e1 = Segment(v1.p, v3[0].p) e2 = Segment(v2.p, v3[0].p) inter1 = intersection(e1, ray) inter2 = intersection(e2, ray) if inter1 != [] and inter2 != []: yield from line_walk_nodes_and_triangles_v(v3[0], Ray(inter1[0], b), b) raise StopIteration if inter1 != []: yield e1 yield from line_walk_nodes_and_triangles_e(v1, v3[0], Ray(inter1[0], b), b) raise StopIteration if inter2 != []: yield e2 yield from line_walk_nodes_and_triangles_e(v2, v3[0], Ray(inter2[0], b), b) raise StopIteration raise StopIteration
def trazas_entre_puntos(self): segmento = Segment3D(self.punto_1, self.punto_2) interseccion_pv = intersection(segmento, self.plano_vertical) interseccion_ph = intersection(segmento, self.plano_horizontal) if interseccion_pv: if not isinstance(interseccion_pv[0], Segment3D): if interseccion_pv[0].z > 0: self.traza_v_entre_puntos = "PV+" else: self.traza_v_entre_puntos = "PV-" if interseccion_ph: if not isinstance(interseccion_ph[0], Segment3D): if interseccion_ph[0].y >= 0: self.traza_h_entre_puntos = "PH+" else: self.traza_h_entre_puntos = "PH-"
def predict_path(circle_coordinates,cue_ball_coordinate,cue_stick_coordinate,frame): global prev_stick_point, prev_cue_point if len(cue_ball_coordinate) < 3 or len(cue_stick_coordinate) < 2: print("No point detected") return frame cue_point = Point(cue_ball_coordinate[0], cue_ball_coordinate[1]) stick_point = Point(cue_stick_coordinate[0], cue_stick_coordinate[1]) future_point, collision_ball_info = during_collision(cue_point, cue_ball_coordinate[2],stick_point,circle_coordinates) prev_stick_point = stick_point prev_cue_point = cue_point flag = 0 if future_point == cue_point: print("No collision") else: print("Collision") cv.circle(frame, (int(collision_ball_info[0]), int(collision_ball_info[1])), 2*int(collision_ball_info[2]), (0, 255, 255), 2) cv.circle(frame, (int(future_point.x), int(future_point.y)), int(cue_ball_coordinate[2]), (255, 255, 255), -1) temp_point = Point(collision_ball_info[0],collision_ball_info[1]) colored_future_point = intersection(Ray(future_point,temp_point),Circle(temp_point,collision_ball_info[2]*5)) cv.line(frame, (cue_point.x, cue_point.y), (future_point.x, future_point.y), (255, 255, 255), thickness=2) cv.line(frame, ((int)(collision_ball_info[0]), (int)(collision_ball_info[1])), ((int)(colored_future_point[0].x), (int)(colored_future_point[0].y)), (0, 255, 0), thickness=2) cv.circle(frame, (int(cue_stick_coordinate[0]), int(cue_stick_coordinate[1])), 3, (123, 55, 55), 4) cv.circle(frame, (int(cue_ball_coordinate[0]), int(cue_ball_coordinate[1])),int(cue_ball_coordinate[2])*2, (100, 100, 100), 2) cv.circle(frame, (int(cue_ball_coordinate[0]), int(cue_ball_coordinate[1])), 1, (255, 100, 100), 2) return frame
def main(): image_address = str(input('Enter the image name: ')) image_address = "pool_Images/" + image_address print(image_address) ball_coord, cue_coord, stick_coord = detection.detect_coordinates2(image_address) #print(cue_coord, ball_coord, stick_coord) if len(cue_coord) == 0 or len(stick_coord) == 0: print("No point detected") return cue_point = Point(cue_coord[0], cue_coord[1]) stick_point = Point(stick_coord[0], stick_coord[1]) path_of_white_ball(cue_point, stick_coord, cue_coord[2]) #path_of_white_ball(p1, p2, RADIUS) future_point, collision_ball_info = during_collision(cue_point, cue_coord[2],stick_point,ball_coord) if future_point == cue_point: print("No collision") return else: frame = cv.imread(image_address, 1) cv.circle(frame, (int(collision_ball_info[0]), int(collision_ball_info[1])), 2*int(collision_ball_info[2]), (0, 255, 255), 2) cv.circle(frame, (int(future_point.x), int(future_point.y)), int(cue_coord[2]), (255, 255, 255), -1) temp_point = Point(collision_ball_info[0],collision_ball_info[1]) colored_future_point = intersection(Ray(future_point,temp_point),Circle(temp_point,collision_ball_info[2]*5)) cv.line(frame, (cue_point.x, cue_point.y), (future_point.x, future_point.y), (255, 255, 255), thickness=2) cv.line(frame, ((int)(collision_ball_info[0]), (int)(collision_ball_info[1])), ((int)(colored_future_point[0].x), (int)(colored_future_point[0].y)), (0, 255, 0), thickness=2) while 1: cv.namedWindow('Image',cv.WND_PROP_FULLSCREEN) cv.imshow('Image', frame) if cv.waitKey(1) & 0xFF == 27: break cv.destroyAllWindows()
def draw_trait_ray(self, trait, clr='b', line_style='-'): # find the ending point on one of the bLines ips = [] for bl in self.bLines: ips.extend( sym.intersection(trait.obj, bl) ) for i in range(len(ips)-1,-1,-1): if not isinstance(ips[i], sym.Point): ips.pop(i) elif not ( (self.xMin <= ips[i].x <= self.xMax) and (self.yMin <= ips[i].y <= self.yMax) ): ips.pop(i) # plot the ray x = np.float(trait.obj.p1.x.evalf()) y = np.float(trait.obj.p1.y.evalf()) dx = np.float(ips[0].x.evalf()) - np.float(trait.obj.p1.x.evalf()) dy = np.float(ips[0].y.evalf()) - np.float(trait.obj.p1.y.evalf()) ray = self.axes.arrow( np.float(x),np.float(y), np.float(dx),np.float(dy), # shape='right', # linewidth = 1, head_width = 0.1, head_length = 0.2, linestyle=line_style, fc=clr, ec=clr, alpha=self.alpha) # self.axes.plot([trait.obj.p1.x, trait.obj.p2.x], [trait.obj.p1.y, trait.obj.p2.y], 'g') self.draw() return ray
def attachment_point_polygon(point,polygon): if polygon.encloses_point(point): is_attachment = True elif intersection(point,polygon): is_attachment = True else: is_attachment = False return is_attachment
def calcular_partes(self): puntos = list(self.limites) partes = {'I': [], 'II': [], 'III': [], 'IV': []} plano = self.sympy for segmento in self.plano_vertical_bordes: interseccion = intersection(plano, segmento) if interseccion: if isinstance(interseccion[0], Segment3D): puntos.append(segmento.points[0].coordinates) puntos.append(segmento.points[1].coordinates) else: puntos.append(interseccion[0].coordinates) for segmento in self.plano_horizontal_bordes: interseccion = intersection(plano, segmento) if interseccion: if isinstance(interseccion[0], Segment3D): puntos.append(segmento.points[0].coordinates) puntos.append(segmento.points[1].coordinates) else: puntos.append(interseccion[0].coordinates) interseccion = intersection( Segment3D(Point3D(500, 0, 0), Point3D(-500, 0, 0)), plano) if interseccion: if isinstance(interseccion[0], Segment3D): puntos.append((500, 0, 0)) puntos.append((-500, 0, 0)) else: puntos.append(interseccion[0].coordinates) for punto in puntos: if punto[1] >= 0 and punto[2] >= 0: partes['I'].append(punto) if punto[1] <= 0 and punto[2] >= 0: partes['II'].append(punto) if punto[1] <= 0 and punto[2] <= 0: partes['III'].append(punto) if punto[1] >= 0 and punto[2] <= 0: partes['IV'].append(punto) # partes = dict((k, list(map(self.ordenar_vertices, v))) for k, v in partes.items()) partes['I'] = self.ordenar_vertices(partes['I']) partes['II'] = self.ordenar_vertices(partes['II']) partes['III'] = self.ordenar_vertices(partes['III']) partes['IV'] = self.ordenar_vertices(partes['IV']) return partes
def extremos(self, recta: Line3D) -> tuple: intersecciones = [] for i in range(6): interseccion = intersection(recta, self.planos[i]) if interseccion: interseccion = interseccion[0] if all(abs(i) <= 500 for i in interseccion.coordinates): intersecciones.append(interseccion.coordinates) return tuple(set(intersecciones))
def path_of_white_ball(p1, p2, r): pathBallW[:] = [] middle_ray = Line(p1, p2) cue_circle = Circle(p1, r) normal_line = middle_ray.perpendicular_line(p1) points = intersection(cue_circle, normal_line) pathBallW.append(middle_ray.parallel_line(points[0])) pathBallW.append(middle_ray) pathBallW.append(middle_ray.parallel_line(points[1]))
def __compute_1st_vanishing_points(self): road_l1 = Line(Point(self.p1), Point(self.p2)) road_l2 = Line(Point(self.p3), Point(self.p4)) road_intersection = intersection(road_l1, road_l2) u0 = float(road_intersection[0][0]) v0 = float(road_intersection[0][1]) return u0, v0
def interseccion(e1, e2): s = str(intersection(e1, e2)) xp = "" xy = "" indice1 = s.find(",") indice2 = s.find(")") px = float(eval(s[9:indice1])) py = float(eval(s[indice1 + 2:indice2])) return [px, py]
def get_l_focal(hue=45): """ hueから L_focal を得る """ # まずは L_cusp を求める # --------------------- lab_709, lab_2020, rgb = get_lab_edge(hue) chroma_709 = get_chroma(lab_709) chroma_2020 = get_chroma(lab_2020) bt709_cusp_idx = np.argmax(chroma_709) bt2020_cusp_idx = np.argmax(chroma_2020) bt709_point = sympy.Point(chroma_709[bt709_cusp_idx], lab_709[bt709_cusp_idx, 0]) bt2020_point = sympy.Point(chroma_2020[bt2020_cusp_idx], lab_2020[bt2020_cusp_idx, 0]) chroma_line = sympy.Line(bt709_point, bt2020_point) lightness_line = sympy.Line(sympy.Point(0, 0), sympy.Point(0, 100)) intersection = sympy.intersection(chroma_line, lightness_line)[0].evalf() l_cusp = np.array(intersection) # BT.2407 に従って補正 # --------------------- # plot ax1 = pu.plot_1_graph(fontsize=20, figsize=(10, 8), graph_title=None, graph_title_size=None, xlabel="Chroma", ylabel="Lightness", axis_label_size=None, legend_size=17, xlim=[0, 220], ylim=[0, 100], xtick=None, ytick=None, xtick_size=None, ytick_size=None, linewidth=3) ax1.plot(chroma_709, lab_709[..., 0], c="#808080", label='BT.709') ax1.plot(chroma_2020, lab_2020[..., 0], c="#000000", label='BT.2020') ax1.plot(chroma_709[bt709_cusp_idx], lab_709[bt709_cusp_idx, 0], 'or', markersize=10, alpha=0.5) ax1.plot(chroma_2020[bt2020_cusp_idx], lab_2020[bt2020_cusp_idx, 0], 'or', markersize=10, alpha=0.5) ax1.plot(l_cusp[0], l_cusp[1], 'ok', markersize=10, alpha=0.5) # annotation ax1.annotate(r'L^*_{cusp}', xy=(l_cusp[0], l_cusp[1]), xytext=(l_cusp[0] + 10, l_cusp[1] + 10), arrowprops=dict(facecolor='black', shrink=0.1)) ax1.plot([chroma_2020[bt2020_cusp_idx], l_cusp[0]], [lab_2020[bt2020_cusp_idx, 0], l_cusp[1]], '--k', alpha=0.3) plt.legend(loc='upper right') plt.show()
def __compute_2nd_vanishing_points(self): # perp_l1 = Line(Point(self.p2), Point(self.p3)) perp_l1 = Line(Point(self.p1), Point(self.p4)) # horizon_l = Line(Point(0, self.v0), (1, self.v0)) horizon_l = Line(Point(self.p2), Point(self.p3)) perp_intersection = intersection(perp_l1, horizon_l) u1 = float(perp_intersection[0][0]) return u1
def line_walk_double_edges_v(node, ray, b): list_of_n_triangles = node.get_neighbor_triangles() for t in list_of_n_triangles: c_he = t.he while(c_he.node != node): c_he = c_he.nxt he_prev = c_he.prev he_nxt = c_he.nxt v1 = c_he.node v2 = he_nxt.node v3 = he_prev.node s = Segment(v1.p, v2.p) inter = intersection(s, ray) if inter != [] and is_segment(inter[0]): yield s yield from line_walk_double_edges_v(v2, Ray(v2.p, b), b) raise StopIteration s = Segment(v1.p, v3.p) inter = intersection(s, ray) if inter != [] and is_segment(inter[0]): yield s yield from line_walk_double_edges_v(v3, Ray(v3.p, b), b) raise StopIteration s = Segment(v3.p, v2.p) inter = intersection(s, ray) if inter != []: yield s if he_nxt.twin != None: yield from line_walk_double_edges_e(he_nxt.twin, Ray(inter[0], b), b) raise StopIteration else: raise StopIteration raise StopIteration
def line_walk_double_edges(triang, a, v1, v2, b): b, ray = inf_ray(a, b, 1000) e = Segment(v1, v2) if is_vertex_of_segment(a, e): node_a = None for index, n in triang[0].items(): if n.p.equals(a): node_a = n break yield from line_walk_double_edges_v(node_a, ray, b) else: l_he = [] for index, he in triang[1].items(): if he.node == None: continue if ((he.node.p.equals(v1) and he.nxt.node.p.equals(v2)) or (he.node.p.equals(v2) and he.nxt.node.p.equals(v1))): l_he.append(he) if len(l_he) == 2: nxt = l_he[0].nxt prev = l_he[0].prev v1 = l_he[0].node.p v2 = nxt.node.p v3 = prev.node.p fi = intersection(Segment(v1, v2), ray) si = intersection(Segment(v2, v3), ray) ti = intersection(Segment(v3, v1), ray) if (fi != [] and is_segment(fi[0])) or si != [] or ti != []: yield e yield from line_walk_double_edges_e(l_he[0], ray, b) else: yield e yield from line_walk_double_edges_e(l_he[1], ray, b) else: yield e yield from line_walk_double_edges_e(l_he[0], ray, b)
def calcular_traza_h(self): traza_h = intersection(self.sympy, self.plano_horizontal) if traza_h: if not isinstance(traza_h[0], Line3D): traza_h = tuple(traza_h[0]) if all(abs(i) <= 500 for i in traza_h): return traza_h else: return "Contenida en PH" else: return False
def calcular_traza_v(self): traza_v = intersection(self.sympy, self.plano_vertical) if traza_v: if not isinstance(traza_v[0], Line3D): traza_v = tuple(traza_v[0]) if all(abs(i) <= 500 for i in traza_v): return traza_v else: return "Contenida en PV" else: return False
def makeSphere(p1,p2,p3,p4): sp1=Point3D(seq(p1)) sp2=Point3D(seq(p2)) sp3=Point3D(seq(p3)) sp4=Point3D(seq(p4)) # helper planes e12=Plane((sp1+sp2)/2,sp2-sp1) e23=Plane((sp2+sp3)/2,sp3-sp2) e14=Plane((sp1+sp4)/2,sp4-sp1) # intersect to find the circumcenter its=e12.intersection(e23) l=its[0] r=sympy.Ray3D(l) ins=sympy.intersection(e14,r) m=ins[0] # check the radius r1=m.distance(sp1) r1 m.distance(sp2) m.distance(sp3) r1.evalf() # visualize k1=App.ActiveDocument.addObject("Part::Sphere","Sphere") k1.Placement.Base=p1 k1.Radius=0.2 k1.ViewObject.ShapeColor=(1.0,0.0,0.0) k2=App.ActiveDocument.addObject("Part::Sphere","Sphere") k2.Placement.Base=p2 k2.Radius=0.2 k2.ViewObject.ShapeColor=(1.0,0.0,0.0) k3=App.ActiveDocument.addObject("Part::Sphere","Sphere") k3.Placement.Base=p3 k3.Radius=0.2 k3.ViewObject.ShapeColor=(1.0,0.0,0.0) k4=App.ActiveDocument.addObject("Part::Sphere","Sphere") k4.Placement.Base=p4 k4.Radius=0.2 k4.ViewObject.ShapeColor=(1.0,0.0,0.0) k=App.ActiveDocument.addObject("Part::Sphere","Sphere") k.Radius.Value=r1.evalf() k.Placement.Base=FreeCAD.Vector(m.x.evalf(),m.y.evalf(),m.z.evalf()) k.ViewObject.Transparency=80 App.activeDocument().recompute()
def intersection_of_three_circel(x1, y1, r1, x2, y2, r2, x3, y3, r3): # Todo handle edge cases if any c1 = Circle(Point(x1, y1), r1) c2 = Circle(Point(x2, y2), r2) c3 = Circle(Point(x3, y3), r3) ans = intersection(c1, c2, c3) if len(ans) != 0: ans = [(p.x, p.y) for p in ans] return ans else: return None
def line_walk_node_with_neighbours_v(node, ray, b): for n_node in node.neigh_nodes: p = n_node.p s = Segment(node.p, p) inter = intersection(s, ray) if inter != [] and is_segment(inter[0]): yield s yield from line_walk_node_with_neighbours_v(n_node, Ray(p, b), b) raise StopIteration for i, j in itertools.combinations(node.neigh_nodes, r=2): if i in set(j.neigh_nodes): s = Segment(i.p, j.p) inter = intersection(s, ray) if inter != []: yield s yield from line_walk_node_with_neighbours_e(i, j, Ray(inter[0], b), b) raise StopIteration
def line_walk_node_with_neighbours_e(v1, v2, ray, b): s_b = turn(cgPoint(int(b.x), int(b.y)), cgPoint(int(v1.p.x), int(v1.p.y)), cgPoint(int(v2.p.x), int(v2.p.y))) s = Segment(v1.p, v2.p) inter = intersection(s, ray) if inter != [] and is_segment(inter[0]): end_node = v1 if ray.contains(v2.p): end_node = v2 yield from line_walk_node_with_neighbours_v(end_node, Ray(end_node.p, b), b) raise StopIteration vs = list(set(v1.neigh_nodes) & set(v2.neigh_nodes)) v3 = [i for i in vs if s_b == turn(cgPoint(int(i.p.x), int(i.p.y)), cgPoint(int(v1.p.x), int(v1.p.y)), cgPoint(int(v2.p.x), int(v2.p.y))) ] if v3 == []: raise StopIteration e1 = Segment(v1.p, v3[0].p) e2 = Segment(v2.p, v3[0].p) inter1 = intersection(e1, ray) inter2 = intersection(e2, ray) if inter1 != [] and inter2 != []: yield from line_walk_node_with_neighbours_v(v3[0], Ray(inter1[0], b), b) raise StopIteration if inter1 != []: yield e1 yield from line_walk_node_with_neighbours_e(v1, v3[0], Ray(inter1[0], b), b) raise StopIteration if inter2 != []: yield e2 yield from line_walk_node_with_neighbours_e(v2, v3[0], Ray(inter2[0], b), b) raise StopIteration
def limites(self): plano = self.sympy buenos = [] # Intersección con las doce aristas del cubo for i in range(12): inter = intersection(plano, self.aristas[i]) if inter: if not isinstance(inter[0], Segment3D): buenos.append( (int(inter[0][0]), int(inter[0][1]), int(inter[0][2]))) # Elimina duplicados buenos = list(set(buenos)) return self.ordenar_vertices(buenos)
def line_walk_nodes_and_triangles_v(node, ray, b): for n_triangles in node.triangles: if n_triangles == None: continue for n_node in n_triangles.nodes: if n_node == node: continue end_node = n_node.p s = Segment(node.p, end_node) inter = intersection(s, ray) if inter != [] and is_segment(inter[0]): yield s yield from line_walk_nodes_and_triangles_v(n_node, Ray(end_node, b), b) raise StopIteration for n_triangles in node.triangles: if n_triangles == None: continue ds = set(n_triangles.nodes) ds.remove(node) pnts = list(ds) node_i = pnts[0] node_j = pnts[1] s = Segment(node_i.p, node_j.p) inter = intersection(s, ray) if inter != []: yield s yield from line_walk_nodes_and_triangles_e(node_i, node_j, Ray(inter[0], b), b) raise StopIteration raise StopIteration
def segments_intersect(x1, y1, x2, y2, x3, y3, x4, y4): seg1 = sympy.Segment(sympy.Point(x1, y1), sympy.Point(x2, y2)) seg2 = sympy.Segment(sympy.Point(x3, y3), sympy.Point(x4, y4)) return sympy.intersection(seg1, seg2) != []