Esempio n. 1
0
    def getPoint(self, theta, advised=True, numerical=False):
        """
        Return a point at angle <theta> (degree) on the circle. 

        INPUT:
        - ``theta`` - the angle given in degree.
        """
        from yanntricks.src.radian_unit import radian
        curve = self.parametric_curve()
        # Le s est à supprimer
        s = curve.get_point(radian(theta, numerical=numerical),
                            advised=advised)
        return curve.get_point(radian(theta, numerical=numerical),
                               advised=advised)
Esempio n. 2
0
def PolarSegment(P, r, theta):
    """
    return a segment on the base point P (class Point) of 
    length r and angle theta (degree)
    """
    alpha = radian(theta)
    return Segment(P, Point(P.x + r * cos(alpha), P.y + r * sin(alpha)))
Esempio n. 3
0
def PolarPoint(r, theta):
    """
    return the point at polar coordinates (r,theta).

    INPUT:

    - ``r`` - the distance from origine
    - ``theta`` - the angle

    EXAMPLES::

        sage: from yanntricks import *
        sage: print PolarPoint(2,45)
        <Point(sqrt(2),sqrt(2))>
    """
    return Point(r * cos(radian(theta)), r * sin(radian(theta)))
Esempio n. 4
0
    def rotate(self, theta):
        """
        Return a new ParametricCurve which graph is rotated by <theta> with respect to self.

        theta is given in degree.
        """
        from yanntricks.src.Constructors import ParametricCurve
        from yanntricks.src.radian_unit import radian
        alpha = radian(theta)
        g1 = cos(alpha) * self.f1 + sin(alpha) * self.f2
        g2 = -sin(alpha) * self.f1 + cos(alpha) * self.f2
        return ParametricCurve(g1, g2)
Esempio n. 5
0
    def action_on_pspict(self, pspict):
        from yanntricks.src.radian_unit import radian
        from yanntricks.src.AngleMeasure import AngleMeasure
        from yanntricks.src.Constructors import CustomSurface
        alphaI = radian(self.angleI,
                        number=True,
                        keep_max=True,
                        keep_large=True)
        alphaF = radian(self.angleF,
                        number=True,
                        keep_max=True,
                        keep_large=True)

        # self.angleI and self.angleF should be AngleMeasure,
        # but sometimes the user writes something like
        # C.angleI=20

        if isinstance(self.angleF, AngleMeasure):
            f = self.angleF.degree
        else:
            f = self.angleF
        if f == 360:  # Because the function radian simplifies modulo 2pi.
            alphaF = 2 * pi
        G = self.parametric_curve(alphaI, alphaF)
        G.parameters = self.parameters.copy()
        if self.parameters._filled or self.parameters._hatched:
            custom = CustomSurface([self.parametric_curve(alphaI, alphaF)])
            custom.parameters = self.parameters.copy()
            pspict.DrawGraphs(custom)

        if self.wavy:
            waviness = self.waviness
            G.wave(waviness.dx, waviness.dy)
            pspict.DrawGraphs(G)
        else:
            pspict.DrawGraphs(G)
Esempio n. 6
0
    def __init__(self, alpha, k):
        """
        This is the oblique projection of angle `alpha` and scale factor `k`.

        `alpha` is given in degree. It is immediately converted in order to have positive number. If you give -45, it will be converted to 315
        """
        from yanntricks.src.AngleMeasure import AngleMeasure
        self.k = k
        if self.k >= 1:
            print("Are you sure that you want such a scale factor : ",
                  float(self.k))
        self.alpha = alpha
        a = AngleMeasure(value_degree=self.alpha).positive()
        self.alpha = a.degree
        self.theta = radian(self.alpha)
        self.kc = self.k * cos(self.theta)
        self.ks = self.k * sin(self.theta)
Esempio n. 7
0
    def getPolarPoint(self, r, theta, pspict=None):
        """
        Return the point located at distance r and angle theta from point self.

        INPUT:

        - ``r`` - A number.

        - ``theta`` - the angle (degree or :class:`AngleMeasure`).

        - ``pspict`` - the pspicture in which the point is supposed to live. If `pspict` is given, we compute the deformation due to the dilatation.  Be careful: in that case `r` is given as absolute value and the visual effect will not be affected by dilatations.

        OUTPUT: A point.

        EXAMPLES::

            sage: from yanntricks import *
            sage: P=Point(1,2)
            sage: print P.get_polar_point(sqrt(2),45)
            <Point(2,3)>

        """
        from yanntricks.src.AngleMeasure import AngleMeasure
        from yanntricks.src.Constructors import Vector
        from yanntricks.src.radian_unit import radian
        from yanntricks.src.Exceptions import ShouldNotHappenException
        if isinstance(r, AngleMeasure):
            raise ShouldNotHappenException(
                "You are passing AngleMeasure instead of a number (the radius)."
            )
        if isinstance(theta, AngleMeasure):
            alpha = theta.radian
        else:
            alpha = radian(theta, number=True)
        if pspict:
            A = pspict.xunit
            B = pspict.yunit
            xP = r * cos(alpha) / A
            yP = r * sin(alpha) / B
            return self.translate(Vector(xP, yP))
        return Point(self.x + r * cos(alpha), self.y + r * sin(alpha))
    def __init__(self,
                 angle_measure=None,
                 value_degree=None,
                 value_radian=None,
                 keep_negative=False):
        from yanntricks.src.polar_coordinates import PolarCoordinates
        from yanntricks.src.degree_unit import degree
        from yanntricks.src.radian_unit import radian

        given_value_degree = value_degree
        given_value_radian = value_radian

        for k in [value_degree, value_radian]:
            if isinstance(k, AngleMeasure):
                angle_measure = k
                value_degree = None
                value_radian = None
        for k in [value_degree, value_radian]:
            if isinstance(k, PolarCoordinates):
                angle_measure = k
                value_degree = None
                value_radian = None
        if angle_measure:
            value_degree = angle_measure.degree
            value_radian = angle_measure.radian
        else:

            if value_degree is not None:
                # If the fractional part of the given degree is too small,
                # we round it.

                # We have to test is 'value_degree' is None because
                # `numerical_approx(None)` is the complex number 0.00000

                s = numerical_approx(value_degree)

                k = abs(s).frac()
                if k < 0.000001:
                    value_degree = s.integer_part()

            if value_degree is not None:
                value_radian = radian(value_degree, keep_max=True)
                if keep_negative and value_degree < 0 and value_radian > 0:
                    print("This is strange ...")
                    value_radian = value_radian - 2 * pi
            if value_degree == None:
                value_degree = degree(value_radian, keep_max=True)
                if keep_negative and value_radian < 0 and value_degree > 0:
                    print("This is strange ...")
                    value_degree = value_degree - 360

        # From here 'value_degree' and 'value_radian' are fixed and
        # we perform some checks.

        self.degree = value_degree
        self.radian = value_radian

        if self.degree > 359 and self.radian < 0.1:
            print("Problem with an angle : ", self.degree, self.radian)
            print("dep degree", given_value_degree,
                  numerical_approx(given_value_degree))
            print("dep_radian", given_value_radian,
                  numerical_approx(given_value_radian))
            print("final degree", numerical_approx(value_degree))
            print("final radian", numerical_approx(value_radian))
            raise ValueError
        if self.degree == None or self.radian == None:
            raise ValueError("Something wrong")