def position(distances, coordinates): """Finds position in solar system in reference to the planets in the system Parameters ---------- distances : array_like() Distances to each planet in the system coordinates : array_like() coordinates of the planets in the system Returns ------- array_like position relative to the input planets """ circles = [] for i in distances: circles.append((geometry.Circle(coordinates[i], distances[i]))) intersect = np.zeros((len(circles), 2)) for i in range(0, len(circles) - 3, 2): inter = np.array(geometry.intersection(circles[i], circles[i + 1])) for k in range(2): intersect[i + k] = inter[k] pt1 = 0 pt2 = 0 for i in range(2, len(intersect)): pt1 += np.sum((intersect[0] - intersect[i])**2) pt2 += np.sum((intersect[1] - intersect[i])**2) if pt1 < pt2: return intersect[0, 0], intersect[0, 1] else: return intersect[1, 0], intersect[1, 1]
def testSympyCircle(): print "++ Sympy Arc ++" p1 = Point(0, 1) arg = {"ARC_0": p1, "ARC_1": 5, "ARC_2": 0, "ARC_3": 6.2831} arc = Arc(arg) sympCircle = arc.getSympy() print "sympCircle", sympCircle sympCircel = geoSympy.Circle(geoSympy.Point(10, 10), 10) arc.setFromSympy(sympCircel) print "Pythonca Arc ", arc print "-- Sympy Arc --"
def circle_line_intersection(A: Union[tuple[float, float], geometry.Point2D], B: Union[tuple[float, float], geometry.Point2D], x0: float, y0: float, r: float) -> Optional[list[tuple[float, float]]]: """ Finds the intersection point(s) between: * Circle with center :math:`x_0, y_0` and radius :math:`r` * Line between two points :math:`A \\rightarrow B`. Returns None in case the line does not intersect the circle. Parameters ---------- A : Union[tuple[float], geometry.Point2D] start of the line B : Union[tuple[float], geometry.Point2D] end of the line x0 : float x-coordinate for circle center y0 : float y-coordinate for circle center r : float radius of circle Returns ------- Optional[list[tuple[float, float]]] One or two intersection points between the circle and the line, or None in case the line and circle do no intersect. """ if isinstance(A, tuple): A = geometry.Point2D(A[0], A[1]) if isinstance(B, tuple): B = geometry.Point2D(B[0], B[1]) circle = geometry.Circle((x0, y0), r) line = geometry.Segment2D(A, B) points = circle.intersection(line) if not points: return None return [(float(p[0]), float(p[1])) for p in points]
def add_cell(self, network): cell = Circle((self.centre_x, self.centre_y), self.radius) nodes = network.vertices ridges = network.ridge_vertices nodes_to_delete = [] ridges_to_delete = [] for i in range(len(nodes)): if cell.contains_point(nodes[i]) == True: nodes_to_delete = np.append(nodes_to_delete, i) for i in range(len(ridges)): if ridges[i][0] in nodes_to_delete and ridges[i][ 1] in nodes_to_delete: ridges_to_delete = np.append(ridges_to_delete, i) ridges_to_delete = np.array(sorted(ridges_to_delete, reverse=True)) for ridge in ridges_to_delete: network.ridge_vertices = np.delete(network.ridge_vertices, int(ridge), axis=0) center = sg.Point(self.centre_x, self.centre_y) circ = sg.Circle(center, self.radius) k = 0 for node in nodes_to_delete: node = int(node) for ridge in network.ridge_vertices: if ridge[0] == node: if len(nodes[node]) == 3: In_point = sg.Point(nodes[node][0], nodes[node][1], nodes[node][2]) Out_point = sg.Point(nodes[ridge[1]][0], nodes[ridge[1]][1], nodes[ridge[1]][1]) elif len(nodes[node]) == 2: In_point = sg.Point(nodes[node][0], nodes[node][1]) Out_point = sg.Point(nodes[ridge[1]][0], nodes[ridge[1]][1]) line = sg.Line(In_point, Out_point) intersec = sg.intersection(circ, line) if length_square(nodes[ridge[1]] - intersec[0]) >= length_square( nodes[ridge[1]] - intersec[1]): nodes = np.append( nodes, [[float(intersec[1].x), float(intersec[1].y)]], axis=0) else: nodes = np.append( nodes, [[float(intersec[0].x), float(intersec[0].y)]], axis=0) ridge[0] = len(nodes) - 1 k += 1 if ridge[1] == node: if len(nodes[node]) == 3: In_point = sg.Point(nodes[node][0], nodes[node][1], nodes[node][2]) Out_point = sg.Point(nodes[ridge[0]][0], nodes[ridge[0]][1], nodes[ridge[0]][1]) elif len(nodes[node]) == 2: In_point = sg.Point(nodes[node][0], nodes[node][1]) Out_point = sg.Point(nodes[ridge[0]][0], nodes[ridge[0]][1]) line = sg.Line(In_point, Out_point) intersec = sg.intersection(circ, line) if length_square(nodes[ridge[0]] - intersec[0]) >= length_square( nodes[ridge[0]] - intersec[1]): nodes = np.append( nodes, [[float(intersec[1].x), float(intersec[1].y)]], axis=0) else: nodes = np.append( nodes, [[float(intersec[0].x), float(intersec[0].y)]], axis=0) ridge[1] = len(nodes) - 1 k += 1 nodes_to_delete = np.array(sorted(nodes_to_delete, reverse=True)) for point in nodes_to_delete: nodes = np.delete(nodes, int(point), 0) # Renumber points after deleting some for ridge in network.ridge_vertices: for i in range(2): r = 0 for node in nodes_to_delete: if node < ridge[i]: r += 1 ridge[i] = ridge[i] - r network.vertices = nodes network.vertices_ini = np.array(network.vertices.tolist()) network = network.create_ridge_node_list() network = network.sort_nodes() network.interior_nodes = network.interior_nodes[:-k] self.boundary_cell = list(range(len(nodes) - k, len(nodes))) return network
def wspolrzednePktPrzekroju(geometria, temp): r""" Funkcja służąca do obliczenia niezbędnych wymiarów wirnika. Na poniższym rysunku został przedstawiony przekrój wirnika i punkty określające jego wymiary. .. figure:: ./image/przekroj.png :align: center :alt: Szkic przekroju wirnika :figclass: align-center :scale: 20% Szkic przekroju wirnika Punkty te odpowiadają następującym wymiarowm pobranym z GUI: * Promień otworu - odl. od osi pionowej do punktu A * Promień zewnętrzny - odl. od osi pionowej do punktu B * Promień u wylotu - odl. od osi pion * Wysokość łopatki - odcinek :math:`|BC|` * Kąt alfa - kąt :math:`\alpha` * Promień zaokrąglenia - odcinek :math:`|RD|=|RE|` * Wysokość pod naddatek - odcinek :math:`|EF|` * Wysokość wirnika - odległość od punktu F do osi poziomej. W celu stworzenia geometrii w programie GMSH należy obliczyć położenie punktu :math:`D`. Punkt ten jest określane poprzez sprawdzenie punktów wspólnych okręglu zakreślonego w punkcie :math:`R` o promieniu :math:`|RD|` z prostą przechodzącą przez punkt :math:`C` odchyloną od poziomu o kąt :math:`\alpha`. Zadanie to zostało wykonane przy użyciu modułu SymPy. :param geometria: obiekt klasy Geometry zawierający dane geometryczne wirnika :type geometria: Geometry :param temp: tymczasowy kontener na dane, użyty w celu przechowywania informacji. :type temp: dictionary :return temp: uaktualniony kontener na dane. """ # Deklaracja zmiennych alfa = geometria.alfa h1 = geometria.h1 h2 = geometria.h2 h3 = geometria.h3 r3 = geometria.r3 r4 = geometria.r4 R = geometria.R # Deklaracja punktow na przekroju A = M([r3, h1]) C = M([r4, h2]) D = M([r4, h3]) R_pos = M([(r4 + R), C[1]]) temp['C'] = C temp['R_pos'] = R_pos # Tworzenie funkcji liniowej okreslajacej pochylenie wirnika a = np.tan(np.deg2rad(-alfa)) b = h1 - a * r3 funLin = lambda x: a * x + b temp['funLin'] = funLin # Wykorzystanie biblioteki Sympy do okreslenia punktu przeciecia sie # zaokraglonej czesci wirnika z pochylona plaszczyzna p1 = sg.Point(A[0], A[1]) p2 = sg.Point(r3 - 2.0, funLin(r3 - 2.0)) l = sg.Line(p1, p2) pc = sg.Point(R_pos[0], R_pos[1]) c = sg.Circle(pc, R) temp['pc'] = pc # Punkty przeciecia sie okregu z prosta punkty = sg.intersection(c, l) # Okresl czy istnieja punkty przeciecia i wybierz poprawne if len(punkty) == 0: text = "Powierzchnia wylotu nie moze zostać stworzona. Zmien wartosc \ wymiaru wysokosci lopatki, kat alfa, badz promien zaokraglenia" raise ValueError(text) if len(punkty) == 2: w = min(punkty, key=lambda p: p.y) B = M([sympy.N(w).x, sympy.N(w).y]) else: w = punkty B = M([sympy.N(punkty).x, sympy.N(punkty).y]) # Zbierz wszystkie punkty w jednej macierzy 'pkty_YZ' pkty_YZ = M([A, B, C, D, R_pos]) # Przystosuj zmienne do obliczen w GMSH'u for i in pkty_YZ: i[0], i[1] = float(i[0]), float(i[1]) i[0] = -i[0] # Dodaj trzeci wymiar do obliczonych punktow pkty_XYZ = np.insert(pkty_YZ, 0, 0.0, axis=1) temp['pkty_XYZ'] = pkty_XYZ return temp
def __init__(self, name, *args): x, y, radius = map(self.parse_rational, args) super().__init__(name, geo.Circle(geo.Point(x, y), radius))
def plot_map(self): if self.launch_location == 'izu': #for IZU URA-SABAKU!! # Set limit range in maps self.set_coordinate_izu() # for tamura version # Set map image img_map = Image.open("./map/Izu_map_mag.png") img_list = np.asarray(img_map) img_height = img_map.size[0] img_width = img_map.size[1] img_origin = np.array( [722, 749]) # TODO : compute by lat/long of launcher point #pixel2meter = (139.431463 - 139.41283)/1800.0 * lon2met pixel2meter = 0.946981208125 # Define image range img_left = -1.0 * img_origin[0] * pixel2meter img_right = (img_width - img_origin[0]) * pixel2meter img_top = img_origin[1] * pixel2meter img_bottom = -1.0 * (img_height - img_origin[1]) * pixel2meter fig = plt.figure(figsize=(12, 10)) # plot setting ax = fig.add_subplot(111) color_line = '#ffff33' # Yellow color_circle = 'r' # Red # Set circle object cir_rail = patches.Circle(xy=self.xy_rail, radius=self.lim_radius, ec=color_circle, fill=False) cir_switch = patches.Circle(xy=self.xy_switch, radius=self.lim_radius, ec=color_circle, fill=False) cir_tent = patches.Circle(xy=self.xy_tent, radius=self.lim_radius, ec=color_circle, fill=False) ax.add_patch(cir_rail) ax.add_patch(cir_switch) ax.add_patch(cir_tent) # plot map plt.imshow(img_list, extent=(img_left, img_right, img_bottom, img_top)) # Write landing permission range plt.plot(self.xy_rail[0], self.xy_rail[1], 'r.', color=color_circle, markersize=12) plt.plot(self.xy_switch[0], self.xy_switch[1], '.', color=color_circle) plt.plot(self.xy_tent[0], self.xy_tent[1], '.', color=color_circle) plt.plot(self.xy_range[:, 0], self.xy_range[:, 1], '--', color=color_line) """ # plot landing point for 2018/3/23 plt.plot(self.xy_land[0], self.xy_land[1], 'r*', markersize = 12, label='actual langing point') """ elif self.launch_location == 'noshiro_sea': #for NOSHIRO SEA!! # Set limit range in maps self.set_coordinate_noshiro() # Set map image img_map = Image.open("./map/noshiro_new_rotate.png") img_list = np.asarray(img_map) img_height = img_map.size[1] # print(img_map.size) img_width = img_map.size[0] img_origin = np.array( [894, 647]) # TODO : compute by lat/long of launcher point #pixel2meter pixel2meter = 8.96708 # Define image range img_left = -1.0 * img_origin[0] * pixel2meter img_right = (img_width - img_origin[0]) * pixel2meter img_top = img_origin[1] * pixel2meter img_bottom = -1.0 * (img_height - img_origin[1]) * pixel2meter #calculate intersections of "inside_circle" and "over_line" center1 = sg.Point(self.xy_center[0], self.xy_center[1]) radius1 = self.hachiya_radius circle1 = sg.Circle(center1, radius1) line = sg.Line(sg.Point(self.xy_point[0, 0], self.xy_point[0, 1]), sg.Point(self.xy_point[1, 0], self.xy_point[1, 1])) result1 = sg.intersection(circle1, line) intersection1_1 = np.array( [float(result1[0].x), float(result1[0].y)]) intersection1_2 = np.array( [float(result1[1].x), float(result1[1].y)]) #caluculate equation of hachiya_line(="over_line") self.a = (self.xy_point[1, 1] - self.xy_point[0, 1]) / ( self.xy_point[1, 0] - self.xy_point[0, 0]) self.b = (self.xy_point[0, 1] * self.xy_point[1, 0] - self.xy_point[1, 1] * self.xy_point[0, 0]) / ( self.xy_point[1, 0] - self.xy_point[0, 0]) self.x = np.arange(intersection1_1[0], intersection1_2[0], 1) self.y = self.a * self.x + self.b self.hachiya_line = np.array([self.a, self.b]) # plot setting plt.figure(figsize=(10, 10)) ax = plt.axes() color_line = '#ffff33' # Yellow color_circle = 'r' # Red # Set circle object cir_rail = patches.Circle(xy=self.xy_rail, radius=self.lim_radius, ec=color_line, fill=False) #cir_switch = patches.Circle(xy=self.xy_switch, radius=self.lim_radius, ec=color_circle, fill=False) #cir_tent = patches.Circle(xy=self.xy_tent, radius=self.lim_radius, ec=color_circle, fill=False) cir_center = patches.Circle(xy=self.xy_center, radius=self.hachiya_radius, ec=color_circle, fill=False) ax.add_patch(cir_rail) #ax.add_patch(cir_switch) #ax.add_patch(cir_tent) ax.add_patch(cir_center) # plot map plt.imshow(img_list, extent=(img_left, img_right, img_bottom, img_top)) # Write landing permission range plt.plot(self.x, self.y, "r") plt.plot(self.xy_rail[0], self.xy_rail[1], '.', color=color_circle) #plt.plot(self.xy_switch[0], self.xy_switch[1], '.', color=color_circle) #plt.plot(self.xy_tent[0], self.xy_tent[1], '.', color=color_circle) #plt.plot(self.xy_range[:,0], self.xy_range[:,1], '--', color=color_line) plt.plot(self.xy_center[0], self.xy_center[1], '.', color=color_circle) else: raise NotImplementedError( 'Available location is: izu or noshiro_sea') return None