phystricks
Classes | Functions
phystricks.src.Utilities Namespace Reference

Classes

class  ConversionAngles
 
class  degreeUnit
 
class  radianUnit
 

Functions

def is_real (z)
 
def test_imaginary_part (z, epsilon=0.0001)
 
def test_imaginary_part_point (P, epsilon=0.0001)
 
def distance_sq (P, Q, numerical=False)
 return the squared distance between P and Q More...
 
def distance (P, Q)
 
def inner_product (v, w, numerical=False)
 Return the inner product of vectors v and w More...
 
def Intersection (f, g, a=None, b=None, numerical=False)
 When f and g are objects with an attribute equation, return the list of points of intersections. More...
 
def point_to_box_intersection (P, box, pspict=None)
 The intersection between the line from the given point and the center of the given box. More...
 
def PointToPolaire (P=None, x=None, y=None, origin=None, numerical=True)
 
def EnsurephyFunction (f)
 
def EnsureParametricCurve (curve)
 
def check_too_large (obj, pspict=None)
 
def general_function_get_point (fun, x, advised=True)
 
def latinize (word)
 
def counterName ()
 
def newlengthName ()
 
def sublist (l, condition)
 
def make_psp_list (pspict, pspicts)
 
def no_symbol (arg)
 
def get_equal_lengths_code (s1, s2, n=1, d=0.1, l=0.1, angle=45, pspict=None, pspicts=None)
 
def put_equal_lengths_code (s1, s2, n=1, d=0.1, l=0.1, angle=45, pspict=None, pspicts=None)
 
def number_to_string (x, digits)
 turn the given number into a string with some conversion and approximations rules. More...
 

Function Documentation

def phystricks.src.Utilities.check_too_large (   obj,
  pspict = None 
)
def phystricks.src.Utilities.counterName ( )
def phystricks.src.Utilities.distance (   P,
  Q 
)
return the distance between P and Q 
def phystricks.src.Utilities.distance_sq (   P,
  Q,
  numerical = False 
)

return the squared distance between P and Q

Parameters
numericalIf True, use numerical approximations and return a numerical approximation.
def phystricks.src.Utilities.EnsureParametricCurve (   curve)
def phystricks.src.Utilities.EnsurephyFunction (   f)
def phystricks.src.Utilities.general_function_get_point (   fun,
  x,
  advised = True 
)
Return a point on the graph of the function with the given x, i.e. it return the point (x,f(x)).

Also set an attribute advised_mark_angle to the point. This angle is the normal exterior to the graph; visually this is usually the best place to put a mark. Typically you use this as
P=f.get_point(3)
P.mark(radius,P.advised_mark_angle,"$P$")

NOTE:
If you don't plan to put a mark on the point, you are invited
to use advised=False in order to speed up the computations.
def phystricks.src.Utilities.get_equal_lengths_code (   s1,
  s2,
  n = 1,
  d = 0.1,
  l = 0.1,
  angle = 45,
  pspict = None,
  pspicts = None 
)
def phystricks.src.Utilities.inner_product (   v,
  w,
  numerical = False 
)

Return the inner product of vectors v and w

Parameters
va vector
wa vector
numericala boolean

If numerical is true, the computations are done on numerical approximations of the coordinates.

def phystricks.src.Utilities.Intersection (   f,
  g,
  a = None,
  b = None,
  numerical = False 
)

When f and g are objects with an attribute equation, return the list of points of intersections.

  • The list of point is sorted by order of x coordinates.
  • Return only real solutions.

Only numerical approximations are returned as there are some errors otherwise. As an example the following #solving return points that are not even near from the circle $ x^2+y^2=9 $ :

1 solve( [ -1/3*sqrt(3)*y + 1/3*sqrt(3)*(-0.19245008972987399*sqrt(3) - 3) + x == 0,x^2 + y^2 - 9 == 0 ],[x,y] )

Examples

1 sage: from phystricks import *
2 sage: fun=phyFunction(x**2-5*x+6)
3 sage: droite=phyFunction(2)
4 sage: pts = Intersection(fun,droite)
5 sage: for P in pts:print P
6 <Point(1,2)>
7 <Point(4,2)>
1 sage: f=phyFunction(sin(x))
2 sage: g=phyFunction(cos(x))
3 sage: pts=Intersection(f,g,-2*pi,2*pi,numerical=True)
4 sage: for P in pts:print P
5 <Point(-5.497787143782138,0.707106781186548)>
6 <Point(-2.3561944901923466,-0.707106781186546)>
7 <Point(0.7853981633974484,0.707106781186548)>
8 <Point(3.926990816987241,-0.707106781186547)>

If 'numerical' is True, it search for the intersection points of the functions 'f' and 'g' (it only work with functions). In this case an interval is required.

def phystricks.src.Utilities.is_real (   z)
def phystricks.src.Utilities.latinize (   word)
return a "latinized" version of a string.

From a string, return something that can be used as point name, file name.
In particular, remove the special characters, put everything in lowercase,
and turn the numbers into letters.

This function is used in order to turn the script name into a
string that can be a filename for the LaTeX's intermediate file.

INPUT:

- ``word`` - string

OUTPUT:
string

EXAMPLES::

    sage: from phystricks.SmallComputations import *
    sage: latinize("/home/MyName/.sage/my_script11.py")
    'homeMyNameDsagemyscriptOODpy'

::

    sage: from phystricks.SmallComputations import *
    sage: latinize("/home/MyName/.sage/my_script13.py")
    'homeMyNameDsagemyscriptOThDpy'
def phystricks.src.Utilities.make_psp_list (   pspict,
  pspicts 
)
def phystricks.src.Utilities.newlengthName ( )
def phystricks.src.Utilities.no_symbol (   arg)
def phystricks.src.Utilities.number_to_string (   x,
  digits 
)

turn the given number into a string with some conversion and approximations rules.

When one coordinate if very small (lower than 0.0001), it is rounded to zero in order to avoid string like "0.2335e-6" in the pstricks code.

The parameter digit is not the same as the one in Sage's numerical_approx. Here we compute a numerical approximation (the one of sage) and then we cut the resulting string to the desired numbers of digits. The rounding is thus not always the expected one. The reason is this kind of expression :

1 a=7.73542889062775*cos(11/9*pi + 1.30951587282752) - 7.55775391156456*cos(5/18*pi) + 2.5*cos(2/9*pi)
2 print(numerical_approx(a))
3 print(numerical_approx(a,digits=5))

The first print is deterministic (0.329851686365047), while the second one is not.

Remark : undefined behaviour is the integer part of x requires more digits than digits.

def phystricks.src.Utilities.point_to_box_intersection (   P,
  box,
  pspict = None 
)

The intersection between the line from the given point and the center of the given box.

  • P : a point
  • box : a box, which means a duck which has attributes xmin, xmax, ymin, ymax

Consider the line from P to the center of the box and return the intersection points.

Returns
a list of Point.
  • The list always contains exactly 2 points
  • They are sorted by order of distance to P
def phystricks.src.Utilities.PointToPolaire (   P = None,
  x = None,
  y = None,
  origin = None,
  numerical = True 
)
Return the polar coordinates of a point.

INPUT:
- ``P`` - (default=None) a point
- ``x,y`` - (defautl=None) the coordinates of the points

EXAMPLES:

You can provide a point::

    sage: from phystricks import Point
    sage: from phystricks.SmallComputations import *
    sage: print PointToPolaire(Point(1,1))
    PolarCoordinates, r=sqrt(2),degree=45,radian=1/4*pi

or directly the coordinates ::

    sage: print PointToPolaire(x=1,y=1)
    PolarCoordinates, r=sqrt(2),degree=45,radian=1/4*pi
def phystricks.src.Utilities.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
def phystricks.src.Utilities.sublist (   l,
  condition 
)
Extract a sublist of 'l' made of the elements that satisfy the condition.

Do not return a new list, but is an iterator.
def phystricks.src.Utilities.test_imaginary_part (   z,
  epsilon = 0.0001 
)
Return a tuple '(isreal,w)' where 'isreal' is a boolean saying if 'z' is real (in the sense that it is real and does not contain 'I' in its string representation) and 'w' is 'z' when the imaginary part is larger than epsilon and an 'numerical_approx' of 'z' when its imaginary part is smaller than 'epsilon'

With the collateral effect that it returns a numerical approximation.
def phystricks.src.Utilities.test_imaginary_part_point (   P,
  epsilon = 0.0001 
)
return the tuple '(isreal,P)' whit the same description of 'test_imaginary_part'