def __add__(self, other): from yanntricks.src.Constructors import Vector if isinstance(other, tuple): if len(other) == 2: I = self.I Dx = self.Dx + other[0] Dy = self.Dy + other[1] return AffineVector(self.I, self.I.translate(Vector(Dx, Dy))) if other.I != self.I: raise OperationNotPermitedException("You can only add vectors\ with same base point.") I = self.I Dx = self.Dx + other.Dx Dy = self.Dy + other.Dy return AffineVector(self.I, self.I.translate(Vector(Dx, Dy)))
def get_tangent_vector(self, llam, advised=False): """ returns the tangent vector to the curve for the value of the parameter given by llam. The vector is normed to 1. INPUT:: - ``llam`` - the value of the parameter on which we want the tangent. - ``advised`` - (default = False) if True, the initial point is returned with its advised_mark_angle. This takes quite a long time of computation (and creates infinite loops in some circumstances) EXAMPLES:: sage: from yanntricks import * sage: F=ParametricCurve(x,x**2) sage: print F.get_tangent_vector(0) <vector I=<Point(0,0)> F=<Point(1,0)>> sage: print F.get_tangent_vector(1) <vector I=<Point(1,1)> F=<Point(1/5*sqrt(5) + 1,2/5*sqrt(5) + 1)>> """ from yanntricks.src.Constructors import AffineVector initial = self.get_point(llam, advised) return AffineVector( initial, Point(initial.x + self.derivative().f1(llam), initial.y + self.derivative().f2(llam))).normalize()
def projection(self, seg): """ Return the projection of 'self' on the segment 'seg' (you can also pass a vector). """ from yanntricks.src.Constructors import AffineVector I = self.I.projection(seg) F = self.F.projection(seg) return AffineVector(I, F)
def __neg__(self): """ return -self. That is an affine vector attached to the same point, but with the opposite direction. """ nx = self.I.x - self.Dx ny = self.I.y - self.Dy return AffineVector(self.I, Point(nx, ny))
def rotation(self, angle): from yanntricks.src.Constructors import AffineVector s = self.segment.rotation(angle) return AffineVector(s.I, s.F)
def orthogonal(self): from yanntricks.src.Constructors import AffineVector ortho_seg = self.segment.orthogonal() I = ortho_seg.I F = ortho_seg.F return AffineVector(I, F)
def numerical_approx(self): from yanntricks.src.Constructors import AffineVector I = Point(numerical_approx(self.I.x), numerical_approx(self.I.y)) F = Point(numerical_approx(self.F.x), numerical_approx(self.F.y)) return AffineVector(I, F)
def fix_visual_size(self, l, xunit=None, yunit=None, pspict=None): s = self.segment.fix_visual_size(l, xunit, yunit, pspict) return AffineVector(s.I, s.F)
def __mul__(self, coef): I = self.I nx = self.I.x + self.Dx * coef ny = self.I.y + self.Dy * coef F = Point(nx, ny) return AffineVector(I, F)
def extend(self, other): I = self.I F = self.F.translate(other.Dx, other.Dy) return AffineVector(I, F)
def fix_origin(self, P): """ Return the affine vector that is equal to 'self' but attached to point P. """ return AffineVector(P, Point(P.x + self.Dx, P.y + self.Dy))
def translate(self, v): return AffineVector(self.I.translate(v), self.F.translate(v))
def copy(self): return AffineVector(self.I, self.F)