Esempio n. 1
0
 def divide_in_two(self, n=1, d=0.1, l=0.1, angle=45, pspict=None, pspicts=None):
     from yanntricks.src.Utilities import make_psp_list
     pspicts = make_psp_list(pspict, pspicts)
     for psp in pspicts:
         a = self.get_divide_in_two(
             n=n, d=d, l=l, angle=angle, pspicts=pspicts)
         self.added_objects.fusion(a)
Esempio n. 2
0
    def get_measure(self, measure_distance, mark_distance, mark_angle=None,
                    text=None, position=None, pspict=None, pspicts=None):
        """
        The difference between 'put_measure' and 'get_measure'
        is that 'get_measure' returns the measure graph while
        'put_measure' adds the measure graph to the segment.

        This allows constructions like
        mesL=Segment(F,D).get_measure(-0.2,0.1,90,"\( 10\)",pspict=pspict,position="S")
        and then draw mesL. The Segment(F,D) object is not drawn.

        If 'mark_angle' is 'None', then the angle
        will be perpendicular to 'self'
        """
        from yanntricks.src.Utilities import make_psp_list
        from yanntricks.src.MeasureLengthGraph import MeasureLength
        pspicts = make_psp_list(pspict, pspicts)

        if mark_angle is None and position not in ["N", "S", "E", "W"]:
            mark_angle = self.angle()+90*degree
        measure = MeasureLength(self, measure_distance)

        measure.put_mark(mark_distance, mark_angle, text,
                         position=position, pspicts=pspicts)
        return measure
Esempio n. 3
0
 def put_measure(self, measure_distance, mark_distance, mark_angle=None,
                 text="", position=None, pspict=None, pspicts=None):
     from yanntricks.src.Utilities import make_psp_list
     pspicts = make_psp_list(pspict, pspicts)
     for psp in pspicts:
         measure = self.get_measure(measure_distance, mark_distance, mark_angle,
                                    text, position=position, pspict=psp)
         self.added_objects.append(psp, measure)
Esempio n. 4
0
 def get_divide_in_two(self, n=1, d=0.1, l=0.1, angle=45, pspict=None, pspicts=None):
     from yanntricks.src.Utilities import make_psp_list
     pspicts = make_psp_list(pspict, pspicts)
     M = self.midpoint()
     s1 = Segment(self.I, M)
     s2 = Segment(M, self.F)
     a = AddedObjects()
     for psp in pspicts:
         s1.put_code(n=n, d=d, l=l, pspict=psp)
         s2.put_code(n=n, d=d, l=l, pspict=psp)
         a.fusion(s1.added_objects)
         a.fusion(s2.added_objects)
     return a
Esempio n. 5
0
    def put_mark(self,
                 dist=None,
                 angle=None,
                 text="",
                 mark_point=None,
                 added_angle=None,
                 position=None,
                 pspict=None,
                 pspicts=None):
        """
        Put a mark on an object


        If you want to put a mark on an object
        P.put_mark(0.1,text="foobar",pspict=pspict,position="N")

        mark_point is a function which returns the
        position of the mark point.

        If you give no position (i.e. no "S","N", etc.) the position will
        be automatic regarding the angle.

        - ``angle`` is given in degree.
        set `position` to "center" is dangerous because
        it puts the center of the box at given angle and distance.
        Thus the text can be ill placed, especially if the given
        `dist` is lower than the half of the box size.

        `center_direction` : the mark is placed in such a way
        that the center is at given angle, and the box's border
        at given distance.
        """
        pspicts = make_psp_list(pspict, pspicts)

        for psp in pspicts:
            mark = self.get_mark(dist,
                                 angle,
                                 text,
                                 mark_point=mark_point,
                                 added_angle=added_angle,
                                 position=position,
                                 pspict=psp)

            if position in ["N", "S", "E", "W"] and angle is not None:
                logging("When you want a position like N,S,E, or W,\
                        the mark angle should not be given.")
            self.added_objects.append(psp, mark)

        self.mark = mark
Esempio n. 6
0
def get_equal_lengths_code(s1,
                           s2,
                           n=1,
                           d=0.1,
                           l=0.1,
                           angle=45,
                           pspict=None,
                           pspicts=None):
    from yanntricks.src.ObjectGraph import AddedObjects
    from yanntricks.src.Utilities import make_psp_list
    added1 = AddedObjects()
    added2 = AddedObjects()
    pspicts = make_psp_list(pspict, pspicts)
    for psp in pspicts:
        c1 = s1.get_code(n=n, d=d, l=l, angle=angle, pspict=psp)
        c2 = s2.get_code(n=n, d=d, l=l, angle=angle, pspict=psp)
        added1.append(psp, c1)
        added2.append(psp, c2)
    return added1, added2
Esempio n. 7
0
def put_equal_lengths_code(s1,
                           s2,
                           n=1,
                           d=0.1,
                           l=0.1,
                           angle=45,
                           pspict=None,
                           pspicts=None):
    """Add the code for equal length between segments s1 and s2"""
    pspicts = make_psp_list(pspict, pspicts)
    for psp in pspicts:
        added = get_equal_lengths_code(s1,
                                       s2,
                                       n,
                                       d,
                                       l,
                                       angle=angle,
                                       pspict=psp)
        c1 = added[0]
        c2 = added[1]
        s1.added_objects.fusion(c1)
        s2.added_objects.fusion(c2)
    def put_mark(self,
                 dist,
                 text_list=None,
                 points_names=None,
                 mark_point=None,
                 pspict=None,
                 pspicts=None):
        from yanntricks.src.affine_vector import AffineVector
        from yanntricks.src.Visual import visual_vector
        from yanntricks.src.Visual import polar_to_visual_polar

        pspicts = make_psp_list(pspict, pspicts)

        n = len(self.points_list)
        if not text_list and not points_names:
            text_list = [
                "\({}\)".format(x) for x in string.ascii_uppercase[0:n]
            ]
        # One can do :
        # polygon.put_mark(0.2,points_names=" B ",pspict=pspict)
        # or
        # polygon.put_mark(0.3,text_list=["","\( F\)","\( E\)"],pspict=pspict)
        # where 'polygon' is a triangle.
        # In both cases we have an empty string as mark and then a box
        # of size zero.
        # We thus have to following error
        # TypeError: cannot evaluate symbolic expression numerically
        # on the second pass, because the size of the box being zero,
        # the line equations somehow trivializes themselves and Sage
        # founds infinitely many intersections.
        # This is why we do not something like :
        # text_list=[ "\( {} \)".format(x) for x in points_names ]
        if text_list:
            for i in range(len(text_list)):
                if text_list[i] == "":
                    text_list[i] = None
        if points_names:
            text_list = []
            for x in points_names:
                if x == " ":
                    text_list.append(None)
                else:
                    text_list.append("\( {} \)".format(x))
        for i, P in enumerate(self.points_list):
            text = text_list[i]
            if text is not None:
                A = self.points_list[(i - 1) % n]
                B = self.points_list[(i + 1) % n]
                v1 = AffineVector(A, P).fix_origin(P).normalize(1)
                v2 = AffineVector(B, P).fix_origin(P).normalize(1)

                # 'direction' is a vector based at 'P' that points
                # in the direction as external to the angle as possible.
                # This is the "external" angle bisector
                # Why not `direction=v1+v2` ? Because we are victim
                # of the problem described
                # in the comment of AffineVectorGraph.__add__
                direction = v1.extend(v2)
                angle = direction.angle()
                for psp in pspicts:
                    P.put_mark(dist=dist,
                               angle=angle,
                               added_angle=0,
                               text=text,
                               position="center_direction",
                               pspict=psp)
                    self.added_objects.append(psp, P)