def setUp(self):
     eclipse1FocalPoint1 = ellipse.Point(-2.236, 0)
     eclipse1FocalPoint2 = ellipse.Point(2.236, 0)
     self.e1 = ellipse.Ellipse(eclipse1FocalPoint1, eclipse1FocalPoint2, 6)
     eclipse2FocalPoint1 = ellipse.Point(-1.8284, -0.5)
     eclipse2FocalPoint2 = ellipse.Point(3.8284, -0.5)
     self.e2 = ellipse.Ellipse(eclipse2FocalPoint1, eclipse2FocalPoint2, 6)
     self.testRect = ellipse.Rectangle(-8.236, -6, 8.236, 6)
コード例 #2
0
    def run(self):

        # Succesively add a new polygon that contributes to reduce overall error
        # until stopping criteria is achieved

        min_err = self.fitness(self.source)
        cur = copy.deepcopy(self.source)
        improvements = 0

        for i in range(self.iterations):

            next = copy.deepcopy(cur)

            if self.type == 1:

                c = circle.Circle(self.height, self.width, 0.1)
                info = c.getInfo()

                cv2.circle(cur, info[0], info[1], info[2], -1)
                cv2.addWeighted(cur, info[3], next, 1 - info[3], 0, next)

            elif self.type == 2:

                e = ellipse.Ellipse(self.height, self.width, 0.1)
                info = e.getInfo()

                cv2.ellipse(cur, info[0], info[1], info[2], 0, 360, info[3],
                            -1)
                cv2.addWeighted(cur, info[4], next, 1 - info[4], 0, next)

            elif self.type == 3:

                t = triangle.Triangle(self.height, self.width, 0.1)
                info = t.getInfo()

                cv2.fillConvexPoly(cur, np.asarray(info[0]), info[1])
                cv2.addWeighted(cur, info[2], next, 1 - info[2], 0, next)

            elif self.type == 4:

                r = quadrilateral.Quadrilateral(self.height, self.width, 0.1)
                info = r.getInfo()

                cv2.fillConvexPoly(cur, np.asarray(info[0]), info[1])
                cv2.addWeighted(cur, info[2], next, 1 - info[2], 0, next)

            # Compute dissimilarity
            err = self.fitness(next)

            # Update the solution that provides more fitness
            if err < min_err:
                min_err = err
                improvements = improvements + 1
                cur = copy.deepcopy(next)
                cv2.imwrite(
                    "Refine_Error_" + str(i) + "_" + str(min_err) + ".jpg",
                    cur)

            if improvements == self.maximprovements:
                break
コード例 #3
0
ファイル: eye_img_processor.py プロジェクト: elmadjian/3DGE
 def __fit_ellipse(self, crop, cnt):
     empty_box = np.zeros(crop.shape)
     cv2.drawContours(empty_box, cnt, -1, 255, 2)
     points = np.where(empty_box == 255)
     vertices = np.array([points[0], points[1]]).T
     ellipse = ell.Ellipse([vertices[:, 1], vertices[:, 0]])
     return ellipse
コード例 #4
0
def step():
    """
    One step of constricted RRT* generation, see paper for more details
    """
    x_rand = sample()
    x_nearest = new_nearest_neighbour(x_rand)
    x_new = steer(x_nearest, x_rand)
    if obstacle_free(x_nearest, x_new):
        X_near = new_neighbourhood(x_new)
        x_min = x_nearest
        c_min = x_nearest.cost + x_nearest.dist_to(x_new)
        for x_near in X_near:
            if obstacle_free(
                    x_near,
                    x_new) and (x_near.cost + x_near.dist_to(x_new) < c_min):
                x_min = x_near
                c_min = (x_near.cost + x_near.dist_to(x_new) < c_min)
        x_new_node = add_node(x_new, x_min, True)
        for x_near in X_near:
            if obstacle_free(x_near, x_new) and (
                    x_new_node.cost + x_near.dist_to(x_new) < x_near.cost):
                x_near.change_parent(x_new_node)
    # Here I check for goal paths and draw the circle
    updated = False
    if shared.root_path:
        updated = goal_path_resolve(shared.root_path[0])
    updated = updated or goal_path_resolve(shared.nodes[-1])
    if updated:
        diameter = shared.root_path_length
        center = ((shared.root_path[0].x + shared.root_path[-1].x) / 2,
                  (shared.root_path[0].y + shared.root_path[-1].y) / 2)
        if shared.region:
            shared.region.remove_from_batch()
        shared.region = ellipse.Ellipse(center[0], center[1], diameter)
        shared.region.add_to_batch()
コード例 #5
0
def step():
    """
    One step of informed RRT* generation, see paper for more details
    """
    x_rand = sample()
    x_nearest = new_nearest_neighbour(x_rand)
    x_new = steer(x_nearest, x_rand)
    if obstacle_free(x_nearest, x_new):
        X_near = new_neighbourhood(x_new)
        x_min = x_nearest
        c_min = x_nearest.cost + x_nearest.dist_to(x_new)
        for x_near in X_near:
            if obstacle_free(
                    x_near,
                    x_new) and (x_near.cost + x_near.dist_to(x_new) < c_min):
                x_min = x_near
                c_min = (x_near.cost + x_near.dist_to(x_new) < c_min)
        x_new_node = add_node(x_new, x_min, True)
        for x_near in X_near:
            if obstacle_free(x_near, x_new) and (
                    x_new_node.cost + x_near.dist_to(x_new) < x_near.cost):
                x_near.change_parent(x_new_node)
        # Here I check for goal regions and draw the ellipse
        updated = False
        if shared.root_path:
            updated = goal_path_resolve(shared.root_path[0])
        updated = updated or goal_path_resolve(shared.nodes[-1])
        if updated:
            major = shared.root_path_length
            minor = math.sqrt(major**2 - shared.root_path[0].dist_to(
                (shared.root_path[-1].x, shared.root_path[-1].y))**2)
            angle = math.atan2(shared.root_path[0].y - shared.root_path[-1].y,
                               shared.root_path[0].x - shared.root_path[-1].x)
            center = ((shared.root_path[0].x + shared.root_path[-1].x) / 2,
                      (shared.root_path[0].y + shared.root_path[-1].y) / 2)
            if shared.region:
                shared.region.remove_from_batch()
            shared.region = ellipse.Ellipse(center[0], center[1], major, minor,
                                            angle)
            shared.region.add_to_batch()
 def setUp(self):
     eclipse1FocalPoint1 = ellipse.Point(5, -1)
     eclipse1FocalPoint2 = ellipse.Point(-1, -1)
     self.e = ellipse.Ellipse(eclipse1FocalPoint1, eclipse1FocalPoint2, 10)
コード例 #7
0
    def __init__(self, parent, controller):

        global POINT_ACTUEL  # Point (x, y) pointé par le curseur de la souris
        POINT_ACTUEL = point_2d.Point_2D(0, 0)

        global LISTE_POINTS_CRITIQUES
        LISTE_POINTS_CRITIQUES = []

        global POINT_CRITIQUE_FIG

        global LISTE_POINTS_CRITIQUES_FIGS
        LISTE_POINTS_CRITIQUES_FIGS = []

        tk.Frame.__init__(self, parent)
        LABEL_titre = tk.Label(self, text="Graphe", font=LARGE_FONT)
        LABEL_titre.pack(pady=10, padx=10)

        ###########################################
        ''' FRAMES D'INTERFACE '''

        # pack_propagate(False) permet d'éviter que la frame se redimensionne toute seule à cause des données
        # qu'elle contient

        FRAME_droite = tk.LabelFrame(self,
                                     text="Menu",
                                     padx=10,
                                     pady=10,
                                     font=MEDIUM_FONT)  # Frame droite
        FRAME_droite.pack(side=tk.RIGHT)

        FRAME_options = tk.LabelFrame(FRAME_droite,
                                      text="Options",
                                      width=330,
                                      padx=10,
                                      pady=20,
                                      font=MEDIUM_FONT)  # Frames des options
        FRAME_options.pack()

        FRAME_donnees = tk.LabelFrame(FRAME_droite,
                                      text="Données",
                                      padx=10,
                                      pady=20,
                                      width=330,
                                      height=230,
                                      font=MEDIUM_FONT)  # Frames des données

        SUB_FRAME_donnees_curseur = tk.LabelFrame(FRAME_donnees,
                                                  text="Curseur",
                                                  width=110,
                                                  height=80)

        SUB_FRAME_donnees_gradient_fonction = tk.LabelFrame(
            FRAME_donnees,
            text="Grdt. fonct.",
            width=110,
            height=80,
            fg="blue")  # Frame des coord. du gradt de la fnct

        SUB_FRAME_donnees_gradient_contrainte = tk.LabelFrame(
            FRAME_donnees, text="Grdt. contr.", width=110, height=80,
            fg="red")  # Frame des coord. du gradt. de la contr

        SUB_FRAME_donnees_gradient_contrainte.pack(side=tk.RIGHT)
        SUB_FRAME_donnees_gradient_contrainte.pack_propagate(False)

        SUB_FRAME_donnees_gradient_fonction.pack(side=tk.RIGHT)
        SUB_FRAME_donnees_gradient_fonction.pack_propagate(False)

        SUB_FRAME_donnees_curseur.pack(side=tk.RIGHT)
        SUB_FRAME_donnees_curseur.pack_propagate(False)

        FRAME_lambda = tk.LabelFrame(FRAME_droite,
                                     width=330,
                                     height=30,
                                     font=SMALL_FONT)
        FRAME_lambda.pack()
        FRAME_lambda.pack_propagate(False)

        FRAME_donnees.pack()
        FRAME_donnees.pack_propagate(False)

        ###########################################
        ###########################################

        f = Figure(figsize=(6, 6), dpi=100)
        a = f.add_subplot(111)

        x, y = np.meshgrid(np.linspace(-1.2, 1.2, 201),
                           np.linspace(-1.2, 1.2, 201))
        z = fnct.fonction_rosenbrock(x, y)

        graphe = a.contour(x, y, z, 25, zorder=0)
        a.autoscale(False)  # évite que le graphe se redimensionne

        # DEFINITION DES POINTS D'UNE ELLIPSE
        ellipse_data = ellipse.Ellipse(point_2d.Point_2D(0, 0), 1.0, 0.6)

        # DEFINITION DES POINTS D'UN CERCLE
        cercle_data = cercle.Cercle(point_2d.Point_2D(0, 0), 0.5)

        # DEFINITION DE LA FIGURE D'UNE ELLIPSE
        global ELLIPSE_FIGURE
        ELLIPSE_FIGURE = mpatches.Ellipse([0, 0],
                                          1,
                                          0.6,
                                          linewidth=1,
                                          fill=0,
                                          color="red")

        # DEFINITION DE LA FIGURE D'UN CERCLE
        global CERCLE_FIGURE
        CERCLE_FIGURE = mpatches.Circle([0, 0],
                                        0.5,
                                        linewidth=1,
                                        fill=0,
                                        color="green")

        #####################################
        #####################################



        ListeContraintes = \
            [tk.StringVar(value="Ellipse", name="Ellipse").get(), tk.StringVar(value="Cercle", name="Cercle").get()]

        TableauContraintes = \
            [
                ELLIPSE_FIGURE,
                CERCLE_FIGURE
            ]

        global CONTRAINTE_CHOISIE
        CONTRAINTE_CHOISIE = tk.StringVar()
        CONTRAINTE_CHOISIE.set(ListeContraintes[0])

        global FIGURE_CONTRAINTE
        FIGURE_CONTRAINTE = TableauContraintes[0]

        a.add_patch(FIGURE_CONTRAINTE)

        global CONTRAINTE_PRESENTE
        CONTRAINTE_PRESENTE = True

        def RetirerContrainte():

            global ELLIPSE_FIGURE
            global CONTRAINTE_PRESENTE

            if not CONTRAINTE_PRESENTE:
                return

            FIGURE_CONTRAINTE.remove()

            CONTRAINTE_PRESENTE = False
            canvas.draw()
            return

        def AjouterContrainte():

            global FIGURE_CONTRAINTE
            global ELLIPSE_FIGURE
            global CONTRAINTE_PRESENTE

            if CONTRAINTE_PRESENTE == True:
                return

            if CONTRAINTE_PRESENTE == False:

                a.add_patch(FIGURE_CONTRAINTE)
                CONTRAINTE_PRESENTE = True
                canvas.draw()

            return

        def choix_contrainte(*args):

            global FIGURE_CONTRAINTE
            global CONTRAINTE_CHOISIE
            global CONTRAINTE_PRESENTE

            FIGURE_CONTRAINTE.remove()
            FIGURE_CONTRAINTE = TableauContraintes[ListeContraintes.index(
                CONTRAINTE_CHOISIE.get())]
            a.add_patch(FIGURE_CONTRAINTE)
            canvas.draw()

            CONTRAINTE_PRESENTE = True

            return

        CONTRAINTE_CHOISIE.trace("w", choix_contrainte)

        #####################################
        #####################################

        canvas = FigureCanvasTkAgg(f, self)
        canvas.draw()

        canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)

        # toolbar = NavigationToolbar2Tk(canvas, self)
        # toolbar.update()
        canvas._tkcanvas.pack()

        ########## AJOUT/ENLEVEMENT DE CONTRAINTE ELLIPTIQUE ###########
        # La variable contrainte_presente permet d'ajouter ou de retirer
        # une contrainte, elle est globale car manipulée dans la fonction
        # AjouterRetirerContrainte

        global AFFICHER_GRDT_CONTRAINTE
        AFFICHER_GRDT_CONTRAINTE = False

        def afficher_gradient_contrainte():
            global AFFICHER_GRDT_CONTRAINTE
            if AFFICHER_GRDT_CONTRAINTE == False:
                AFFICHER_GRDT_CONTRAINTE = True
            else:
                AFFICHER_GRDT_CONTRAINTE = False

        ###############################################################
        # VALEUR MULTIPLICATEUR DE LAGRANGE

        global VALEUR_MULTIPLICATEUR
        VALEUR_MULTIPLICATEUR = 0
        global LABEL_MULTIPLICATEUR
        LABEL_MULTIPLICATEUR = tk.Label(FRAME_lambda,
                                        text="Aucun point critique rencontré",
                                        fg="red",
                                        font=SMALL_FONT)
        LABEL_MULTIPLICATEUR.pack()

        global CURSEUR_X
        global CURSEUR_Y

        global LABEL_CURSEUR_X
        global LABEL_CURSEUR_Y

        global LABEL_GRADIENT_FONCTION_X
        global LABEL_GRADIENT_FONCTION_Y

        global LABEL_GRADIENT_CONTRAINTE_X
        global LABEL_GRADIENT_CONTRAINTE_Y

        CURSEUR_X = 0
        CURSEUR_Y = 0

        ## DONNEES CURSEUR ##
        LABEL_CURSEUR_X = tk.Label(SUB_FRAME_donnees_curseur,
                                   text="X: " + str(CURSEUR_X),
                                   font=SMALL_FONT)
        LABEL_CURSEUR_Y = tk.Label(SUB_FRAME_donnees_curseur,
                                   text="Y: " + str(CURSEUR_Y),
                                   font=SMALL_FONT)

        LABEL_CURSEUR_X.pack()
        LABEL_CURSEUR_Y.pack()
        #####################

        ## DONNEES GRADIENT FONCTION ##
        LABEL_GRADIENT_FONCTION_X = tk.Label(
            SUB_FRAME_donnees_gradient_fonction,
            text="X: " + str(0),
            font=SMALL_FONT)
        LABEL_GRADIENT_FONCTION_Y = tk.Label(
            SUB_FRAME_donnees_gradient_fonction,
            text="Y: " + str(0),
            font=SMALL_FONT)

        LABEL_GRADIENT_FONCTION_X.pack()
        LABEL_GRADIENT_FONCTION_Y.pack()
        ###############################

        ## DONNEES GRADIENT CONTRAINTE ##
        LABEL_GRADIENT_CONTRAINTE_X = tk.Label(
            SUB_FRAME_donnees_gradient_contrainte,
            text="X: " + str(0),
            font=SMALL_FONT)
        LABEL_GRADIENT_CONTRAINTE_Y = tk.Label(
            SUB_FRAME_donnees_gradient_contrainte,
            text="Y: " + str(0),
            font=SMALL_FONT)

        LABEL_GRADIENT_CONTRAINTE_X.pack()
        LABEL_GRADIENT_CONTRAINTE_Y.pack()
        #################################

        ###############################################################

        global POINT_CRITIQUE_PRESENT
        POINT_CRITIQUE_PRESENT = False

        def Survol(event):

            if not event.inaxes:  # if the mouse cursor is not on the graph, do nothing
                return

            ### VARIABLES GLOBALES ###

            global AFFICHER_GRDT_CONTRAINTE
            global POINT_ACTUEL  # point où se trouve le curseur

            global VALEUR_MULTIPLICATEUR
            global LABEL_MULTIPLICATEUR

            global CURSEUR_X
            global CURSEUR_Y

            global LABEL_CURSEUR_X
            global LABEL_CURSEUR_Y

            global LABEL_GRADIENT_FONCTION_X
            global LABEL_GRADIENT_FONCTION_Y

            global LABEL_GRADIENT_CONTRAINTE_X
            global LABEL_GRADIENT_CONTRAINTE_Y

            global POINT_CRITIQUE_PRESENT

            global LISTE_POINTS_CRITIQUES

            ##############################

            LABEL_CURSEUR_X.pack_forget()
            LABEL_CURSEUR_Y.pack_forget()
            CURSEUR_X = np.round(event.xdata, 3)
            CURSEUR_Y = np.round(event.ydata, 3)
            LABEL_CURSEUR_X = tk.Label(SUB_FRAME_donnees_curseur,
                                       text="X: " + str(CURSEUR_X),
                                       font=SMALL_FONT)
            LABEL_CURSEUR_Y = tk.Label(SUB_FRAME_donnees_curseur,
                                       text="Y: " + str(CURSEUR_Y),
                                       font=SMALL_FONT)
            LABEL_CURSEUR_X.pack()
            LABEL_CURSEUR_Y.pack()

            ##########################

            POINT_ACTUEL = point_2d.Point_2D(event.xdata, event.ydata)

            fig_gradient_rosenbrock = mpatches.FancyArrowPatch(
                (POINT_ACTUEL.x_, POINT_ACTUEL.y_),
                (fnct.gradient_rosenbrock_X(POINT_ACTUEL.x_, POINT_ACTUEL.y_),
                 fnct.gradient_rosenbrock_Y(POINT_ACTUEL.x_, POINT_ACTUEL.y_)),
                mutation_scale=15)

            a.add_patch(fig_gradient_rosenbrock)

            point_contrainte = POINT_ACTUEL.trouver_point_proche(
                ellipse_data.points_)

            fig_gradient_contrainte = mpatches.FancyArrowPatch(
                (point_contrainte.x_, point_contrainte.y_),
                (ellipse_data.gradient_x(point_contrainte),
                 ellipse_data.gradient_y(point_contrainte)),
                mutation_scale=8,
                color='r')


            if AFFICHER_GRDT_CONTRAINTE == True and POINT_ACTUEL.def_distance(point_contrainte)<0.1\
                    and CONTRAINTE_PRESENTE == True:
                a.add_patch(fig_gradient_contrainte)

            canvas.draw()

            if CONTRAINTE_CHOISIE.get() == ListeContraintes[0]:
                vecteur_gradient_contrainte = vecteur.Vecteur(
                    point_contrainte,
                    point_2d.Point_2D(
                        ellipse_data.gradient_x(point_contrainte),
                        ellipse_data.gradient_y(point_contrainte)))
            if CONTRAINTE_CHOISIE.get() == ListeContraintes[1]:
                vecteur_gradient_contrainte = vecteur.Vecteur(
                    point_contrainte,
                    point_2d.Point_2D(
                        cercle_data.gradient_x(point_contrainte),
                        cercle_data.gradient_y(point_contrainte)))

            vecteur_gradient_rosenbrock = vecteur.Vecteur(
                POINT_ACTUEL,
                point_2d.Point_2D(
                    fnct.gradient_rosenbrock_X(POINT_ACTUEL.x_,
                                               POINT_ACTUEL.y_),
                    fnct.gradient_rosenbrock_Y(POINT_ACTUEL.x_,
                                               POINT_ACTUEL.y_)))

            LABEL_GRADIENT_FONCTION_X.pack_forget()
            LABEL_GRADIENT_FONCTION_Y.pack_forget()
            LABEL_GRADIENT_FONCTION_X = tk.Label(
                SUB_FRAME_donnees_gradient_fonction,
                text="X: " + str(np.round(vecteur_gradient_rosenbrock.x_, 2)),
                font=SMALL_FONT)
            LABEL_GRADIENT_FONCTION_Y = tk.Label(
                SUB_FRAME_donnees_gradient_fonction,
                text="Y: " + str(np.round(vecteur_gradient_rosenbrock.y_, 2)),
                font=SMALL_FONT)
            LABEL_GRADIENT_FONCTION_X.pack()
            LABEL_GRADIENT_FONCTION_Y.pack()

            if AFFICHER_GRDT_CONTRAINTE == True and vecteur_gradient_contrainte.verifier_colinearite(
                    vecteur_gradient_rosenbrock):

                VALEUR_MULTIPLICATEUR = np.round(
                    vecteur_gradient_contrainte.get_multiplicateur(
                        vecteur_gradient_rosenbrock), 2)
                LABEL_MULTIPLICATEUR.pack_forget()
                LABEL_MULTIPLICATEUR = tk.Label(
                    FRAME_lambda,
                    fg="green",
                    text="Valeur approx. de λ : " +
                    str(np.round(VALEUR_MULTIPLICATEUR, 1)),
                    font=SMALL_FONT)
                LABEL_MULTIPLICATEUR.pack()

                LABEL_GRADIENT_CONTRAINTE_X.pack_forget()
                LABEL_GRADIENT_CONTRAINTE_Y.pack_forget()
                LABEL_GRADIENT_CONTRAINTE_X = tk.Label(
                    SUB_FRAME_donnees_gradient_contrainte,
                    text="X: " +
                    str(np.round(vecteur_gradient_contrainte.x_, 2)),
                    font=SMALL_FONT)
                LABEL_GRADIENT_CONTRAINTE_Y = tk.Label(
                    SUB_FRAME_donnees_gradient_contrainte,
                    text="Y: " +
                    str(np.round(vecteur_gradient_contrainte.y_, 2)),
                    font=SMALL_FONT)
                LABEL_GRADIENT_CONTRAINTE_X.pack()
                LABEL_GRADIENT_CONTRAINTE_Y.pack()

                ## PERMET D'AJOUTER UN POINT SUR LA FIGURE LORSQU'UN POINT CRITIQUE EST RENCONTRÉ

                # Si aucun point critique existant n'est proche du point critique observé
                if not point_contrainte.point_adjacent(LISTE_POINTS_CRITIQUES,
                                                       0.1):

                    # Alors on ajoute ce nouveau point critique à la liste des points critiques
                    LISTE_POINTS_CRITIQUES.append(point_contrainte)
                    # Puis on ajoute la figure représentant ce point critique à la liste des figures de points critiques
                    LISTE_POINTS_CRITIQUES_FIGS.append(
                        a.scatter(point_contrainte.x_,
                                  point_contrainte.y_,
                                  s=20,
                                  c="cyan",
                                  zorder=3))

                canvas.draw()

            else:
                LABEL_MULTIPLICATEUR.pack_forget()
                LABEL_MULTIPLICATEUR = tk.Label(
                    FRAME_lambda,
                    fg="red",
                    text="Le point actuel n'est pas critique",
                    font=SMALL_FONT)
                LABEL_MULTIPLICATEUR.pack()

            fig_gradient_rosenbrock.set_visible(False)
            fig_gradient_contrainte.set_visible(False)

        def enlever_point_critique_fig():
            global POINT_CRITIQUE_PRESENT
            global POINT_CRITIQUE_FIG

            global LISTE_POINTS_CRITIQUES
            global LISTE_POINTS_CRITIQUES_FIGS

            if not LISTE_POINTS_CRITIQUES_FIGS:
                return
            else:
                for POINT_CRITIQUE_FIG in LISTE_POINTS_CRITIQUES_FIGS:
                    POINT_CRITIQUE_FIG.remove()

                LISTE_POINTS_CRITIQUES_FIGS.clear()
                LISTE_POINTS_CRITIQUES.clear()

                canvas.draw()

        ''' BOUTONS D'INTERFACE '''

        BUTTON_menu_principal = tk.Button(
            FRAME_options,
            text="Retour Menu principal",
            pady=10,
            padx=5,
            command=lambda: controller.show_frame(StartPage),
            width=40)
        BUTTON_menu_principal.pack()

        BUTTON_ajouter_contrainte = tk.Button(FRAME_options,
                                              text="Ajouter Contrainte",
                                              pady=10,
                                              padx=5,
                                              command=AjouterContrainte,
                                              width=40)

        BUTTON_retirer_contrainte = tk.Button(FRAME_options,
                                              text="Retirer Contrainte",
                                              pady=10,
                                              padx=5,
                                              command=RetirerContrainte,
                                              width=40)

        BUTTON_ajouter_contrainte.pack()
        BUTTON_retirer_contrainte.pack()

        BUTTON_nettoyer_graphe = tk.Button(FRAME_options,
                                           text="Nettoyer graphe",
                                           padx=5,
                                           pady=10,
                                           width=40,
                                           command=enlever_point_critique_fig)
        BUTTON_nettoyer_graphe.pack()
        ''' ###################### '''
        ''' MENUS DEROULANTS D'INTERFACE '''

        # LABEL_choix_contraintes = tk.Label(FRAME_options, text="Choix de la contrainte:")
        # MENU_DEROULANT_contraintes = tk.OptionMenu(FRAME_options, CONTRAINTE_CHOISIE, *ListeContraintes)
        # LABEL_choix_contraintes.pack()
        # MENU_DEROULANT_contraintes.pack()
        ''' ###################### '''
        ''' CHECKBOXES D'INTERFACE '''

        CHECK_aff_gradient_contrainte = tk.Checkbutton(
            FRAME_options,
            text="Afficher gradient contrainte",
            command=afficher_gradient_contrainte,
            font=SMALL_FONT)
        CHECK_aff_gradient_contrainte.pack()
        ''' #####################  '''

        canvas.mpl_connect('motion_notify_event', Survol)
コード例 #8
0
ファイル: orbit.py プロジェクト: MuCephei/Stars
    def __init__(self, body_one, body_two, barycenter, vector_normal,
                 vector_inline, specific_orbital_energy, eccentricity):
        #sanitizing

        if isinstance(body_one, sphere.Sphere):
            self.body_one = body_one
        else:
            raise IncorrectInput("The first input must be a sphere")

        if isinstance(body_two, sphere.Sphere):
            self.body_two = body_two
        else:
            raise IncorrectInput("The second input must be a sphere")

        if isinstance(barycenter, coordinate.Coordinate):
            self.barycenter = barycenter * constants.AU
            #this module attemps to measure things in meters, but takes AU as input
        else:
            raise IncorrectInput("The third input must be a Coordinate")

        if isinstance(vector_normal, coordinate.Vector):
            self.vector_normal = vector_normal.unitVector()
            #I don't care about the length of a vector so it is standardized
        else:
            raise IncorrectInput("The fourth input must be a Vector")

        if isinstance(vector_inline, coordinate.Vector):
            self.vector_inline = vector_inline.unitVector()
            #this is a vector from the barycenter to the first focal point
            #the negative of this vector is from the barycenter to the second focal point
            #also this vector has no meaningfull magnitude so it is standardized
        else:
            raise IncorrectInput("The fifth input must be a Vector")

        if is_num.isNumber(specific_orbital_energy):
            self.specific_orbital_energy = float(specific_orbital_energy)
            #this is one of the more arbitrary parts of the whole system
            #it is possible to calculate the energy from a single position of the orbit
            #however I decided that was not the focus of the project and so it takes the energy as a number
        else:
            raise IncorrectInput("The sixth input must be a number")

        if self.specific_orbital_energy >= 0:
            raise IncorrectInput(
                "The inputs do not make a valid elliptical orbit.\nThe specific orbital energy must be less than 0"
            )

        if is_num.isNumber(eccentricity):
            self.eccentricity = float(eccentricity)
        else:
            raise IncorrectInput("The seventh input must be a number")

        #some conviences
        self.mass_sum = body_one.mass + body_two.mass

        self.standard_gravitation_parameter = constants.G * self.mass_sum
        #This is mu

        self.reduced_mass = (self.body_one.mass *
                             self.body_two.mass) / self.mass_sum

        self.mass_ratio_one = self.body_one.mass / self.mass_sum

        self.mass_ratio_two = self.body_two.mass / self.mass_sum

        self.semimajor_sum = -1 * self.standard_gravitation_parameter / (
            2 * self.specific_orbital_energy)
        self.semimajor_sum = self.semimajor_sum * constants.AU
        #this is a major calculation for the whole orbit

        self.semimajoraxis_one = self.semimajor_sum * self.mass_ratio_two

        self.semimajoraxis_two = self.semimajor_sum - self.semimajoraxis_one

        # self.angular_momentum = self.reduced_mass * math.sqrt(
        # 	constants.G * self.mass_sum * self.semimajor_sum * (1 - self.eccentricity **2))
        #turns out I never used this so I didn't need it

        self.period = 2 * math.pi * math.sqrt(
            self.semimajor_sum**3 / self.standard_gravitation_parameter)
        #also a major calculation that give the answer in years

        distance_to_focal_one = 2 * self.semimajoraxis_one * self.eccentricity
        distance_to_focal_two = -2 * self.semimajoraxis_two * self.eccentricity
        #this one is negative becuase it is in the oppositve direction of the inline vector

        self.focal_one = self.barycenter + (self.vector_inline *
                                            distance_to_focal_one)
        self.focal_two = self.barycenter + (self.vector_inline *
                                            distance_to_focal_two)

        self.ellipse_one = ellipse.Ellipse(self.focal_one, self.barycenter,
                                           self.vector_normal,
                                           2 * self.semimajoraxis_one)
        self.ellipse_two = ellipse.Ellipse(self.focal_two, self.barycenter,
                                           self.vector_normal,
                                           2 * self.semimajoraxis_two)
コード例 #9
0
ファイル: individual.py プロジェクト: foxis/PolyPic
    def __init__(self, *args):

        if len(args) == 5:

            # Randomly generate an individual taking as inputs: size , height , width ,  type , maxopacity

            self.size = args[0]
            self.height = args[1]
            self.width = args[2]
            self.type = args[3]

            self.genes = []

            for i in range(self.size):

                if self.type == 1:

                    self.genes.append(circle.Circle(args[1], args[2], args[4]))

                elif self.type == 2:

                    self.genes.append(
                        ellipse.Ellipse(args[1], args[2], args[4]))

                elif self.type == 3:

                    self.genes.append(
                        triangle.Triangle(args[1], args[2], args[4]))

                elif self.type == 4:

                    self.genes.append(
                        quadrilateral.Quadrilateral(args[1], args[2], args[4]))

        else:  # len(args) == 1 :

            # Implicity define an individual based on its genes encoding

            file = open(args[0], 'r')

            self.size = int(file.readline())
            self.height = int(file.readline())
            self.width = int(file.readline())
            self.type = int(file.readline())

            self.maxopacity = 0.3

            self.genes = []

            for i in range(self.size):

                if self.type == 1:

                    self.genes.append(
                        circle.Circle(self.height, self.width, self.maxopacity,
                                      file.readline()))

                elif self.type == 2:

                    self.genes.append(
                        ellipse.Ellipse(self.height, self.width,
                                        self.maxopacity, file.readline()))

                elif self.type == 3:

                    self.genes.append(
                        triangle.Triangle(self.height, self.width,
                                          self.maxopacity, file.readline()))

                elif self.type == 4:

                    self.genes.append(
                        quadrilateral.Quadrilateral(self.height, self.width,
                                                    self.maxopacity,
                                                    file.readline()))

            file.close()