Welcome to phystricks’s documentation!

Contents:

Warning about the size

When converting the pictures to png, I used convert and 100 pixels by centimeters. This is approximative. If you want to see the real result, you have to look at the pdf documentation.

Purpose of the module

This module is aimed to create pstricks files ready to be included in LaTeX documents. You are writing a python script that creates a files that contains the LaTeX code of your figure. From the LaTeX point of view, you don’t have to know anything about creation of pictures.

For people who want to compile with pdflatex, the script is able to output pdf or png files.

Known bugs

  • The figure “ExempleArcParam”. The numbers on the axes are cut in the pdflatex version.

  • The figure “Some points on a parametric curve” is not centred. Idem dans GeomAnal.

  • The figure “cube” is cut at the top.

  • It is now hard to print the axes over the picture. One difficulty is that the axes of a pspicture

    are computed when the content of the pspicture is known. It is thus nonsense to write something like pspict.DrawGraph(pspict.axes)

  • Position of marks on the axes do not take dilatations into account

    _images/Picture_FIGLabelFigexAdhIntFrTroisPICTexAdhIntFrTrois-for_eps.png

Unknown bugs

Only Chuck Norris knows the list of unknown bugs.

Dependencies

As softwares you need

  • A working LaTeX distribution;
  • Sage as backend for computations. You can download it from the website;
  • LaTeXparser for the interaction with LaTeX;
  • the module phystricks itself can be downloaded from gitorious

Your LaTeX file has to import the following packages:

  • pstricks
  • pst-eucl
  • pstricks-add
  • pst-math
  • subfigure
  • graphicx
  • calc
  • catchfile

TODO: check if the package pst-func is still needed for implicit plots.

Hello word!

The first step is to draw a point. Here is the code to be written in you python’s script called first_example.py

#! /usr/bin/sage -python
# -*- coding: utf8 -*-

from phystricks import *

def OnePoint():
	pspict,fig = SinglePicture("OnePoint")			# Generic name of the figure

	##################### The main lines are here
	P = Point(1,1)
	P.parameters.color = "red"
	pspict.DrawGraph(P)
	########################

	fig.conclude()
	fig.write_the_file()

OnePoint()

Executing that script prints the following lines that have to be copy-pasted in your LaTeX file:

The result is on figure \ref{LabelFigOnePoint}.
\newcommand{\CaptionFigOnePoint}{<+Type your caption here+>}
\input{Fig_OnePoint.pstricks}
---
Testing pspicture FIGLabelFigOnePointPICTOnePoint ...
Seems to lack of test file.

The result will be a figure with the following picture:

_images/Picture_FIGLabelFigOnePointPICTOnePoint-for_eps.png

Notice that you don’t have to copy-paste at each compilation. The file Fig_OnePoint.pstricks is automatically changed each time you compile the picture.

Fighting with pdflatex and Arxiv

Let us continue the previous example. By default, the file Fig_OnePoint.pstricks will contain pstricks code that cannot be compiled by pdflatex (and which is not accepted by arxiv). This is why pdf and png outputs are available. If you launch your script by

$ first_example.py --pdf,

a pdf file of your picture will be produced and the file Fig_OnePoint.pstricks will be modified to contain \includegraphics{...}.

The same is true if you launch your script with $ first_example.py --png.

If you just want to produce the png files without use them in you LaTeX file, launch

$ first_example.py --create-png.

This is the way this documentation was produced.

BUG : some bounding boxes are still not well computed in the pdf and png version. You can see them here at some places. If you really need a png file of a picture that is impacted by this bug, I thinks there are three solutions :

  • wait for a next version of phystricks
  • send me a patch
  • do a screenshot of the dvi version.

Basic geometrical constructions

This module contains the basic graphics elements like points, segments and vectors. Each of them have the methods for basic geometric manipulations: rotations, dilatations, tangent vector, etc.

The end-user should not use the functions whose name begin with GraphOf or Geometric. Rather he has to use the constructors like Point(), AffineVector() and so on.

class phystricks.BasicGeometricObjects.Axes(C, bb)

Describe a system of axes (two axes).

By default they are orthogonal.

class phystricks.BasicGeometricObjects.BoundingBox(dSW=None, dNE=None, parent=None)

Represent the bounding box of something.

INPUT:

  • dSW - The point at the “South-West” corner of the bounding box.
  • dNE - The point at the “North-East” corner of the bounding box.
  • parent - the object of which this is the bounding box.

By default, the bounding box has mx=1000, Mx=-1000 and the same for y.

The attribute parent is used for drawing the bounding boxes that can vary with the dilatation. The usual way for drawing the bounding bow of the mark of an object is to put P.mark.bounding_box(pspict) in pspict.DrawGraph.

The problem arises when one dilates the figure after the call to DrawGraph. Indeed the bounding box of the mark will be the LaTeX’s size of the box containing the text. In order to be correct one has to take into account the parameters xunit/yunit that are not yet fixed at the time of DrawGraph.

EXAMPLE:

sage: pspict,fig = SinglePicture("DefinitionCartesiennes")  #random
sage: P=Point(1,1)
sage: P.put_mark(0.3,0,"$MMM$")
sage: bb = P.mark.bounding_box(pspict)  #random
sage: print bb
(1.30000000000000,1),(1.30000000000000,1)
sage: pspict.dilatation(2)
sage: bb = P.mark.bounding_box(pspict) #random
sage: print bb
(1.15000000000000,1),(1.15000000000000,1)

In the first call, the bounding box is not the same as in the second call.

AddCircleBB(Cer, xunit, yunit)

Add a deformed circle to the bounding box.

INPUT:

  • Cer - a circle.
  • xunit,yunit - the x and y deformation coefficients.

The given circle will be deformed by the coefficient xunit and yunid and the be added to self.

enlarge_a_little(Dx, Dy, epsilonX, epsilonY)

Essentially intended to the bounding box of a axis coordinate. The aim is to make the axis slightly larger than the picture in such a way that all the numbers are written

  1. If a coordinate is integer multiple of epsilon, (say n), we enlarge to n+epsilon, so that the number n appears on the axis.

  2. If a coordinate is non integer multiple, we enlarge to the next integer multiple (plus epsilon) so that the axis still has a number written

    further than the limit of the picture.

The aim is to make the axes slightly bigger than their (Dx,Dy) in order the last graduation to be visible.

extraX(l)

Enlarge the bounding box of a length l on both sides

extraX_left(l)

Enlarge the bounding box of a length l on the left

extraX_right(l)

Enlarge the bounding box of a length l on the right

phystricks.BasicGeometricObjects.Distance(P, Q)

return the distance between P and Q

phystricks.BasicGeometricObjects.Distance_sq(P, Q)

return the squared distance between P and Q

class phystricks.BasicGeometricObjects.FillParameters

Represent the parameters of filling a surface.

add_to_options(opt)

add self to a set of options.

INPUT:

OUTPUT:

Return opt with added properties.

EXAMPLES:

sage: opt=Options()
sage: fill=FillParameters()
sage: fill.color="blue"
sage: fill.add_to_options(opt)
sage: opt.code()
'fillcolor=blue,fillstyle=solid'
sage: fill.style="MyStyle"
sage: fill.add_to_options(opt)
sage: opt.code()
'fillcolor=blue,fillstyle=MyStyle'
class phystricks.BasicGeometricObjects.GeometricImplicitCurve(f)

Describe a curve given by an implicit equation.

INPUT:

  • f – a function of two variables or equation in two variables

End users should not use this class but use the constrcutor ImplicitCurve().

EXAMPLES:

sage: f(x,y)=x**2+1/x
sage: F=GeometricImplicitCurve(f(x,y)==2)
sage: G=GeometricImplicitCurve(x+y==2)   
graph(xrange, yrange, plot_points=100)

Return the graph corresponding to the implicit curve.

INPUT:

  • xrange - the X-range on which the curve will be plotted.
  • yrange - the Y-range on which the curve will be plotted.

EXAMPLE

sage: x,y=var('x,y')
sage: F=GeometricImplicitCurve(x-y==3)
sage: graph=F.graph((x,-3,3),(y,-2,2))
sage: print graph.bounding_box()
(1.0,-2.0),(3.0,0.0)
class phystricks.BasicGeometricObjects.GeometricRectangle

The four points of the square are designated by NW,NE,SW and SE.

class phystricks.BasicGeometricObjects.GeometricVectorField(fx, fy)

Describe a vector field

INPUT:

  • f - a tupe of function

EXAMPLES:

sage: x,y=var('x,y')
sage: f1=phyFunction(x**2)
sage: F = GeometricVectorField( f1,cos(x*y) )
sage: print F(3,pi/3)
vector I=Point(3,1/3*pi) F=Point(12,1/3*pi - 1)
divergence()

return the divergence of the vector field.

OUTPUT:

a two-variable function

EXAMPLES:

sage: x,y=var('x,y')
sage: F = GeometricVectorField( x , y )
sage: F.divergence()
(x, y) |--> 2

The divergence of the gravitational field vanishes:

sage: G=GeometricVectorField(x/(x**2+y**2),y/(x**2+y**2))
sage: G.divergence().simplify_full()
(x, y) |--> 0

The divergence is a function:

sage: a,b=var('a,b')
sage: H=GeometricVectorField( x**2,y**3 )
sage: H.divergence()(a,b)
3*b^2 + 2*a
graph(xvalues=None, yvalues=None, draw_points=None)

return a graph of self with the given points

INPUT:

  • xvalues - tuple (x,mx,My,n) interval and number of points with respect to X.
  • yvalues - tuple (y,my,My,n) interval and number of points with respect to Y.
  • draw_points - (defaulf : empty list) a list of points.

If xvalues is given, then yvalues has to be given.

OUTPUT:

object GraphOfAVectorField.

EXAMPLES:

sage: x,y=var('x,y')
sage: F=VectorField(x,y).graph(xvalues=(x,-2,2,3),yvalues=(y,-10,10,3),draw_points=[Point(100,100)])
sage: print F.draw_points[0]
Point(100,100)
sage: print len(F.draw_points)
10
class phystricks.BasicGeometricObjects.GraphOfACircle(center, radius, angleI=0, angleF=360)

This is a circle, or an arc of circle.

INPUT:

  • center - a point, the center of the circle.
  • radius - a number, the radius of the circle.
  • self.angleI - (default=0) the beginning angle of the arc (degree).
  • self.angleF - (default=360) the ending angle of the arc (degree).

OUTPUT:

A circle ready to be drawn.

EXAMPLES:

sage: circle=Circle(Point(-1,1),3)
sage: print unify_point_name(circle.pstricks_code())
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](-4.00000000000000,1.00000000000000){Xaaaa}
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](-1.00000000000000,1.00000000000000){Xaaab}
\pstCircleOA[linestyle=solid,linecolor=black]{Xaaab}{Xaaaa}

If you want the same circle but between the angles 45 and 78:

sage: other_circle=circle.graph(45,78)
sage: print unify_point_name(other_circle.pstricks_code())
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](1.12132034355964,3.12132034355964){Xaaaa}
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](-0.376264927546722,3.93444280220142){Xaaab}
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](-1.00000000000000,1.00000000000000){Xaaac}
\pstArcOAB[linestyle=solid,linecolor=black]{Xaaac}{Xaaaa}{Xaaab}
copy()

Return a copy of the object as geometrical object.

It only copies the center and the radius. In particular the following are not copied:

  • style of drawing.
  • initial and final angle if self is an arc.

EXAMPLES:

Python copies by assignation:

sage: c1=Circle( Point(1,1),2 )
sage: c2=c1
sage: c2.center=Point(3,3)
sage: print c1.center
Point(3,3)

The method copy() pass through:

sage: c1=Circle( Point(1,1),3 )
sage: c2=c1.copy()
sage: c2.center=Point(3,3)
sage: print c1.center
Point(1,1)

NOTE:

Due to use of lazy_attribute, it is not recommended to change the center of a circle after having defined it.

equation

Return the equation of self.

OUTPUT:

an equation.

EXAMPLES:

sage: circle=Circle(Point(0,0),1)
sage: circle.equation()
x^2 + y^2 - 1 == 0
sage: circle=CircleOA(Point(-1,-1),Point(0,0))
sage: circle.equation()
(y + 1)^2 + (x + 1)^2 - 2 == 0
get_normal_vector(theta)

Return a normal vector at the given angle

INPUT:

  • theta - an angle in degree or AngleMeasure.

OUTPUT:

An affine vector

EXAMPLES:

sage: C=Circle(Point(0,0),2)
sage: print C.get_normal_vector(45)
vector I=Point(sqrt(2),sqrt(2)) F=Point(3/2*sqrt(2),3/2*sqrt(2))
get_point(theta, advised=True, numerical=False)

Return a point at angle <theta> (degree) on the circle.

INPUT: - theta - the angle given in degree.

get_regular_points(mx, Mx, l, advised=True)

return regularly spaced points on the circle

INPUT:

  • mx - initial angle (degree).

  • Mx - final angle (degree).

  • l - distance between two points (arc length).

  • advised - (default=True) if True, compute an advised mark angle for each point

    this is CPU-intensive.

OUTPUT: a list of points

EXAMPLES:

sage: C=Circle(Point(0,0),2)
sage: pts=C.get_regular_points(0,90,1)
sage: [str(p) for p in pts]
['Point(2,0)', 'Point(2*cos(1/2),2*sin(1/2))', 'Point(2*cos(1),2*sin(1))', 'Point(2*cos(3/2),2*sin(3/2))']
graph(angleI, angleF)

Return a graph of the circle between the two angles given in degree

parametric_curve(a=None, b=None)

Return the parametric curve associated to the circle.

If optional arguments <a> and <b> are given, return the corresponding graph between the values a and b of the angle.

The parameter of the curve is the angle in radian.

phyFunction()

return the function corresponding to the graph of the upper part of the circle

class phystricks.BasicGeometricObjects.GraphOfACustomSurface(args)

INPUT:

  • args - A list or a tuple of graphs that can compose a pscustom
class phystricks.BasicGeometricObjects.GraphOfAPolygon(args)

INPUT:

  • args - a tuple of points.

NOTE:

This class is not intended to be used by the end-user. The latter has to use Polygon().

class phystricks.BasicGeometricObjects.GraphOfARectangle(NW, SE)

The parameters of the four lines are by default the same, but they can be adapted separately.

graph_N returns the north side as a phystricks.Segment object The parameters of the four sides have to be set independently.

The drawing is done by psframe, so that, in principle, all the options are available.

default_associated_graph_class()

Return the class which is the Graph associated type

class phystricks.BasicGeometricObjects.GraphOfAText(P, text, hide=True)

You can customize the background via the object self.rectangle

class phystricks.BasicGeometricObjects.GraphOfAVectorField(F, draw_points)

the graph object of a vector field

INPUT: - F - a vector field - draw_point - the list of points on which it has to be drawn

Typically, in order to construct such an object we use the function VectorField and then the method GeometricVectorField.graph

See the function VectorField and GeometricVectorField.graph for documentation.

draw_vectors

the list of vectors to be drawn

pos_x

return the list of x positions on which there is a drawn vector

The list is sorted

NOTE:

If self was created using the optional argument draw_points, then the set of points on which there is a vector is not equal to the Cartesian product self.pos_x times self.pos_y

EXAMPLES:

The two lists created in the following example are the same:

sage: x,y=var('x,y')
sage: F=VectorField(x,y).graph(xvalues=(x,1,2,3),yvalues=(y,-2,2,3))
sage: [ P.coordinates() for P in F.draw_points ]
['(1.0,-2.0)', '(1.0,0)', '(1.0,2.0)', '(1.5,-2.0)', '(1.5,0)', '(1.5,2.0)', '(2.0,-2.0)', '(2.0,0)', '(2.0,2.0)']

and

sage: [ (x,y) for x in F.pos_x for y in F.pos_y ]
[(1.0, -2.0), (1.0, 0.0), (1.0, 2.0), (1.5, -2.0), (1.5, 0.0), (1.5, 2.0), (2.0, -2.0), (2.0, 0.0), (2.0, 2.0)]

But in the following, the list is not the list of points:

sage: G=VectorField(x,y).graph(draw_points=[Point(1,2),Point(3,4)])
sage: [ (x,y) for x in G.pos_x for y in G.pos_y ]
[(1, 2), (1, 4), (3, 2), (3, 4)]
pos_y

return the list of y positions on which there is a drawn vector

See pos_x

class phystricks.BasicGeometricObjects.GraphOfAnAngle(A, O, B, r=None)
self.mark_angle is the angle at which self.mark_point will be placed. By default it is at the middle.
If you want to change it, use self.set_mark_angle(x). It will set both the mark_angle and the advised_mark_angle to to x in the same time.
set_mark_angle(theta)

theta is degree or AngleMeasure

class phystricks.BasicGeometricObjects.GraphOfAnImplicitCurve(implicit_curve, xrange, yrange, plot_points=300)

Describe the graph of an implicit curve.

INPUT:

  • implicit_curve - the implicit curve to be considered.
  • xrange,``yrange`` - the range on which we want to plot.

OPTIONAL INPUT:

  • plot_points – integer (default: 100); number of points to plot in each direction of the grid.

ATTRIBUTES:

  • self.path this is a list of lists of points. Each list correspond to a path

    in the sense of matplotlib. Notice that here the points are given as instances of Point; not as list [x,y] as matplotlib does.

EXAMPLES:

sage: var('x,y')
(x, y)
sage: implicit_curve=GeometricImplicitCurve(x**2+x==3)
sage: F=GraphOfAnImplicitCurve(implicit_curve,(x,-1,1),(y,-3,2)).pstricks_code()

NOTES:

The get_minmax_data is contributed by the Sage’s community here : http://ask.sagemath.org/question/359/get_minmax_data-on-implicit_plot (thanks to DSM)

bounding_box(pspict=None)

Return the bounding box of the implicit curve.

This is NOT the bounding box got that one could expect using Sage’s plotting system implicit_plot(f,xrange,yrange).get_minmax_data()

Instead the bounding box returned here only contains the points that are actually plotted. In the following example, we know that the ymax has to be half the sqrt of the radius (and not the 5 given in yrange).

EXAMPLES: sage: var(‘x,y’) (x, y) sage: f=x**2+2*y**2 sage: G=ImplicitCurve(f==sqrt(2),(x,-5,5),(y,-5,5),plot_points=200) sage: print G.bounding_box() (-1.188,-0.841),(1.188,0.841)

get_minmax_data(decimals=3, dict=True)

Return a dictionary whose keys give the xmin, xmax, ymin, and ymax data for this graphic.

Since the results come from the lazy_attribute function _get_minmax_data, changing the number of points between two call will not change the result.

EXAMPLES sage: var(‘x,y’) (x, y) sage: F=ImplicitCurve(x**2+y**2==sqrt(2),(x,-5,5),(y,-4,4),plot_points=300) sage: F.get_minmax_data() {‘xmin’: -1.1890000000000001, ‘ymin’: -1.1879999999999999, ‘ymax’: 1.1879999999999999, ‘xmax’: 1.1890000000000001} sage: F.plot_points=10 sage: F.get_minmax_data() {‘xmin’: -1.1890000000000001, ‘ymin’: -1.1879999999999999, ‘ymax’: 1.1879999999999999, ‘xmax’: 1.1890000000000001}

pstricks_code(pspict=None)

Return the pstrick code of the implicit curve.

class phystricks.BasicGeometricObjects.GraphOfAnObject(obj)

This class is supposed to be used to create other “GraphOfA...” by inheritance. It is a superclass.

merge_options(graph)

takes an other object GraphOfA... and merges the options as explained in the documentation of the class Options. That merge takes into account the attributes “color”, “style”, wavy

class phystricks.BasicGeometricObjects.GraphOfAphyFunction(fun, mx, Mx)

INPUT:

  • fun - sage symbolic expression that is to be interpreted as

    a function of x.

  • mx,Mx - the initial and end values of the variable.

NOTE :

The end-used has to use phyFunction() instead. The latter accepts more types of arguments.

derivative(n=1)

return the derivative of the function.

INPUT:

  • n - an interger (default = 1) the order of derivative. If n=0, return self.

EXAMPLES:

sage: from phystricks import *
sage: f=phyFunction(x**2)
sage: print f.derivative()
x |--> 2*x
sage: print f.derivative()(3)
6
sage: g(x)=cos(x)
sage: print [g.derivative(i) for i in range(0,5)]
[x |--> cos(x), x |--> -sin(x), x |--> -cos(x), x |--> sin(x), x |--> cos(x)]
get_minmax_data(mx, Mx)

return numerical approximations of min and max of the function on the interval

INPUT: - mx,Mx - the interval on which we look at the extrema

OUTPUT:

dictionary conaining xmax, ymax, xmin and ymin

Notice that we are only interested in ymax and ymin.

EXAMPLES:

sage: f=phyFunction(x)
sage: f.get_minmax_data(-3,pi)
{'xmin': -3.0, 'ymin': -3.0, 'ymax': 3.1419999999999999, 'xmax': 3.1419999999999999}

In the case of the sine function, the min and max are almost -1 and 1:

sage: f=phyFunction(sin(x))
sage: f.get_minmax_data(0,2*pi)
{'xmin': 0.0, 'ymin': -1.0, 'ymax': 1.0, 'xmax': 6.2830000000000004}

NOTE:

This function is victim of the Trac 10246 <http://trac.sagemath.org/sage_trac/ticket/10246> The try ... except block is a workaround.

get_normal_point(x, dy)

return a point at distance dy in the normal direction of the point (x,f(x))

get_normal_vector(xx)

return a normalized normal vector to the graph of the function at xx

The direction of the vector is outside

INPUT: - x - a number, the position at which we want the normal vector

OUTPUT: a vector

EXAMPLES: sage: var(‘x’) x sage: f=phyFunction(x**2) sage: print f.get_normal_vector(0) vector I=Point(0,0) F=Point(0,-1)

get_point(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.

get_regular_points(mx, Mx, dx)

return a list of points regularly spaced (with respect to the arc length) on the graph of self.

INPUT:

  • mx,Mx - the minimal and maximal values of x between we will search for points.
  • dx - the arc length between two points

OUTPUT: A list of points

EXAMPLES:

sage: f=phyFunction(x+1)
sage: print [P.coordinates() for P in f.get_regular_points(-2,2,sqrt(2))]
['(0.70434464532253749*sqrt(2) - 2,0.70434464532253749*sqrt(2) - 1)', '(1.408689290645075*sqrt(2) - 2,1.408689290645075*sqrt(2) - 1)', '(2.1130339359676125*sqrt(2) - 2,2.1130339359676125*sqrt(2) - 1)', '(2.81737858129015*sqrt(2) - 2,2.81737858129015*sqrt(2) - 1)']

Even if it is not clear from these expressions, these are almos the points (-1,0),(0,1), and (1,2).

get_tangent_segment(x)

Return a tangent segment at point (x,f(x)).

The difference with self.get_tangent_vector is that self.get_tangent_segment returns a segment that will be symmetric. The point (x,f(x)) is the center of self.get_tangent_segment.

get_tangent_vector(x, advised=False, numerical=False)

return a tangent vector at the point (x,f(x))

inverse(y)

returns a list of values x such that f(x)=y

parametric_curve()

return a parametric curve with the same graph as self.

pstricks_code(pspict=None)

return the pstricks code of the function

EXAMPLES:

sage: f=phyFunction(x*sin(1/x)).graph(-5,5)
sage: f.pstricks_code()      
'\psplot[linestyle=solid,plotpoints=100,linecolor=blue]{-5.00000000000000}{5.00000000000000}{x*sin(1/x)}'
roots()

return roots of the function as a list of Points. Some can miss !

surface_under(mx=None, Mx=None)

Return the graph of a surface under the function.

If mx and Mx are not given, try to use self.mx and self.Mx, assuming that the method is used on an instance of GraphOfAphyFunction that inherits from here.

tangent_phyFunction(x0)

Return the tangent at the given point as a phyFunction.

INPUT:

  • x0 - a number

OUTPUT:

A phyFunction that represents the tangent. This is an affine function.

EXAMPLE:

sage: g=phyFunction(cos(x))
sage: print g.tangent_phyFunction(pi/2)
x |--> 1/2*pi - x
sage: g.tangent_phyFunction(pi/2)(1)
1/2*pi - 1
tangente(x)

This should no more be used.

class phystricks.BasicGeometricObjects.HatchParameters

Same as FillParameters, but when one speaks about hatching

class phystricks.BasicGeometricObjects.Options

Describe the drawing options of pstricks objects.

ATTRIBUTES :
self.DicoOptions : dictionnary which contains the options
METHODS :
self.merge_options(opt) : opt is an other object of the class Options. The method merges the two in the sense that opt is not
changed, but 1. if opt contains a key more, it is added to self 2. if a key of opt is different of the one of self, self is changed
phystricks.BasicGeometricObjects.PointsNameList()

Furnish a list of points name.

This is the generator of the sequence of strings “aaaa”, “aaab”, ..., “aaaz”,”aaaA”, ..., “aaaZ”,”aaba” etc.

EXAMPLES:

sage: x=PointsNameList()
sage: x.next()
'aaaa'
sage: x.next()
'aaab'
class phystricks.BasicGeometricObjects.Waviness(graph, dx, dy)

This class contains the informations about the waviness of a curve. It takes as argument a GraphOfAphyFunction and the parameters dx, dy of the wave. Waviness.get_wavy_points returns a list of points which are disposed around the graph of the curve. These are the points to be linked

by a bezier or something in order to get the wavy graph of the function.
phystricks.BasicGeometricObjects.allocatemem()

File: sage/libs/pari/gen.pyx (starting at line 9391)

Double the PARI stack.

phystricks.BasicGeometricObjects.extract_interval_information(curve)

return the interval of the curve.

That is the initial and final value of the parameter of curve if that is a ParametricCurve and the initial and final values of x if this the the graph of a function.

INPUT:

  • curve - graph of a function or a parametric curve

OUTPUT:

a tuple of numbers. If nothing is found, return (None,None).

EXAMPLES:

sage: f=phyFunction(x**2).graph(1,pi)
sage: extract_interval_information(f)
(1, pi)
 
sage: a=var('a')
sage: curve=ParametricCurve(x,sin(x)).graph(sqrt(2),a)
sage: extract_interval_information(curve)
(sqrt(2), a)

sage: f=phyFunction(x**3)
sage: extract_interval_information(f)
(None, None)
phystricks.BasicGeometricObjects.get_paths_from_implicit_plot(p)

Return a list of list of points from an implicit plot.

Each list correspond to a path.

INPUT:

  • p an implicit plot.

OUTPUT:

A list of lists of points. Each list corresponds to a path (see matplotlib), but the components are converted into points in the sens of phystricks (instead of matplotlib’s vertices).

EXAMPLES:

The length of the list can be quite long:

sage: x,y=var('x,y')
sage: F=implicit_plot(x**2+y**2==2,(x,-5,5),(y,-5,5))
sage: len(get_paths_from_implicit_plot(F)[0])
169

When you have more than one connected component, you see it

sage: F=implicit_plot(x**2-y**2==2,(x,-5,5),(y,-5,5))
sage: paths=get_paths_from_implicit_plot(F)
sage: len(paths)
4
sage: type(paths[0][1])
<class 'phystricks.BasicGeometricObjects.GraphOfAPoint'>
sage: print paths[1][3]
Point(4.87405534614,-4.6644295302)
phystricks.BasicGeometricObjects.get_paths_from_plot(p)

return the paths (in the sense of matplotlib) contained in the plot object p.

The paths here are paths in the sense of matplotlib; the elements are vertices. Not to be confused with get_paths_from_implicit_plot in which the basic elements are points.

INPUT: - p - a plot object

EXAMPLES: sage: var(‘x,y’) (x, y) sage: F=implicit_plot(x**2+y**2==2,(x,-5,5),(y,-5,5)) sage: g=get_paths_from_plot(F) sage: print type(g[0]) <class ‘matplotlib.path.Path’>

NOTE: The first version of the function is due to the DSM here: http://ask.sagemath.org/question/359/get_minmax_data-on-implicit_plot

phystricks.BasicGeometricObjects.inner_product(v, w)

Return the inner product of vectors v and w

INPUT: - v,w - two vectors or points

OUTPUT: a number

If the vectors are not based at (0,0), make first the translation and return the inner product.

If a point is passed, it is considered as the vector from (0,0).

EXAMPLES: sage: from phystricks import * sage: v=Vector(1,3) sage: w=Vector(-5,7) sage: inner_product(v,w) 16

sage: v=AffineVector(Point(1,1),Point(2,2)) sage: w=AffineVector(Point(-2,5),Point(-1,4)) sage: inner_product(v,w) 0

Small mathematical computations

This submodule contains some auxiliary computations that have to be performed by phystricks but that are not geometry.

class phystricks.SmallComputations.AngleMeasure(value_degree=None, value_radian=None)

describe an angle.

This class is an attempt to abstract the degree/radian problem.

EXAMPLES:

sage: x=AngleMeasure(value_radian=pi/2)
sage: x()
90

Conversions are exact:

sage: a=AngleMeasure(value_degree=30)
sage: cos(a.radian)
1/2*sqrt(3)

You can create a new angle from an old one:

sage: a=AngleMeasure(value_degree=180)
sage: b=AngleMeasure(a)
sage: b.degree
180
class phystricks.SmallComputations.ConversionAngles(conversion_factor, max_value, exit_attribute=None, create_function=None)

Simplify and convert angle units.

This class serves to factorise conversion degree -> radian and radian -> degree INPUT: - conversion_factor - the conversion factor from the considered unit to the other (radian->degree or the contrary) - max_value - the maximal value (360 or 2*pi)

conversion(theta, number=False, keep_max=False, converting=True, numerical=False)

Makes the conversion and simplify.

INPUT:

  • theta - the angle to be converted.

  • number - (default =False) If true, return a number. Not to be confused with <numerical>.

  • keep_max - (defaut False) If true, does not convert the max value into the minimal value.

    Typically, leaves 2*pi as 2*pi instead of returning 0.

  • converting - (defaut = True) If False, make no conversion.

  • numerical - (default = False) boolean. If True, return a numerical approximation.

    If <numerical>=True, then <number> is automatically switched to True.

EXAMPLES:

For converting 7 radian into degree, make the following:

sage: degree=ConversionAngles(180/pi,360).conversion
sage: degree(7)     
1260/pi - 360

Notice that the result is an exact value. If you want a numerical approximation:

sage: degree(7,numerical=True)
41.0704565915763
sage: numerical_approx(degree(7))
41.0704565915763
sage: degree(120,converting=False)
120

Using converting=False,number=True is a way to ensure something to be a number instead of a AngleMeasure. For that, we need to precise what unit we want to produce. This is done by self.exit_attribute. A realistic way to define a function that converts to degree is:

sage: DegreeConversions=ConversionAngles(SR(180)/pi,360,exit_attribute="degree",create_function=DegreeAngleMeasure)
sage: degree=DegreeConversions.conversion
sage: a=45 
sage: b=AngleMeasure(value_radian=pi/4)
sage: degree(a,number=True,converting=False)
45
sage: degree(b,number=True,converting=False)
45
simplify(angle, keep_max=False, number=False, numerical=False)

Simplify the angles modulo the maximum.

If what is given is a number, return a number. If what is given is a AngleMeasure, return a new AngleMeasure.

INPUT:

  • angle - an angle that can be an instance of AngleMeasure or a number.

    if it is a number, the simplify modulo self.max_value if it is a AngleMeasure, then first extract the value of the angle

    using self.exit_attribute .

  • keep_max - (defautl=False) If True, does not simplify the angle with max value.

    Typically, keeps 2*pi as 2*pi. This is used in order to keep track of the difference between 0 and 2*pi in the context of drawing an full circle.

  • number - (default=False) If True, return a number even is a AngleMeasure is given.

  • numerical - (default=False) If True, return numerical_approx of the result

NOTE: number=True allows exit like pi/2 while numerical will return 1.57079632679490.

EXAMPLES:

sage: simplify_degree=ConversionAngles(180/pi,360).simplify
sage: simplify_degree(400)
40

If <keep_max> is True, maximal values are kept:

sage: simplify_degree(500,keep_max=True)
140
sage: simplify_degree(360,keep_max=True)
360
phystricks.SmallComputations.MainGridArray(mx, Mx, Dx)

Return the list of number that are 1. integer multiple of Dy 2. between mx and Mx

If mx=-1.4 and Dx=0.5, the first element of the list will be -1 If mx=-1.5 and Dx=0.5, the first element of the list will be -1.5

phystricks.SmallComputations.MultipleBetween(Dx, mx, Mx, mark_origin=True)

Return the list of values that are all the integer multiple of Dx between mx and Mx.

If <mark_origin> is True, the list includes 0 if applicable.

phystricks.SmallComputations.MultipleBigger(x, m)

return the lower multiple of m which is bigger or equal to x

phystricks.SmallComputations.MultipleLower(x, m)

return the biggest multiple of m which is lower or equal to x

phystricks.SmallComputations.MyMinMax(dico_sage, decimals=3)

return the dictionary with numbers cut to decimals digits.

INPUT:

  • dico_sage - a dictionary with number values
  • decimals - (default=3) the number of digits after the unity to keep

OUTPUT:

A dictionary

EXAMPLES:

sage: d={‘xmin’: -0.3456475, ‘ymin’: -1.94565, ‘ymax’: 1.7895, ‘xmax’: 3.0000124} sage: MyMinMax(d,decimals=2) {‘xmin’: -0.34999999999999998, ‘ymin’: -1.95, ‘ymax’: 1.79, ‘xmax’: 3.0}
phystricks.SmallComputations.PointToPolaire(P=None, x=None, y=None)

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: 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
phystricks.SmallComputations.RemoveLastZeros(x, n)

Cut the number x to n decimals and then remove the last zeros.

If there remain no decimals, also remove the dot. We only cut a given number of decimals; if the integer part has more digits, we keep them.

The output is a string, not a number.

INPUT:

  • x - a number.
  • n - the number of decimals we want to keep.

OUTPUT: A string.

EXAMPLES:

sage: RemoveLastZeros(1.000,4)
'1'
sage: RemoveLastZeros(3/4,1)
'0.7'
sage: RemoveLastZeros(3/4,3)
'0.75'
sage: RemoveLastZeros(3/4,4)
'0.75'
sage: RemoveLastZeros(pi,4)
'3.1415'
sage: RemoveLastZeros(130*e,2)
'353.37'

NOTE : Part of the algorithm comes from http://www.java2s.com/Code/Python/Development/StringformatFivedigitsafterdecimalinfloat.htm

phystricks.SmallComputations.SubGridArray(mx, Mx, Dx, num_subX)

Provides the values between mx and Mx such that there are num_subX-1 numbers between two integer separated by Dx

phystricks.SmallComputations.allocatemem()

File: sage/libs/pari/gen.pyx (starting at line 9391)

Double the PARI stack.

phystricks.SmallComputations.around(x, decimals)

return x truncated after a certain number of decimals.

INPUT:

  • x - a number
  • deciamsl - integer

OUTPUT:

A number.

EXAMPLES:

sage: around(100.6867867,3)
100.687
phystricks.SmallComputations.enlarge_a_little_low(x, m, epsilon)

see the description of the function enlarge_a_little of the class BoundingBox. This function makes the job for one number.

phystricks.SmallComputations.enlarge_a_little_up(x, m, epsilon)

see the description of the function enlarge_a_little of the class BoundingBox. This function makes the job for one number.

phystricks.SmallComputations.get_line(s, pos)

return the line containing s[pos]

INPUT:

  • s - a srting.
  • pos - integer.

EXAMPLES:

sage: s="Hello\n how do you do ? \n See you"
sage: print get_line(s,10)
how do you do ?
phystricks.SmallComputations.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: latinize("/home/MyName/.sage/my_script11.py")
'homeMyNameDsagemyscriptOODpy'
sage: latinize("/home/MyName/.sage/my_script13.py")
'homeMyNameDsagemyscriptOThDpy'
phystricks.SmallComputations.number_at_position(s, n)

return the number being at position n in s as well as the first and last positions of that number in s.

Return False is the position n is not part of a number.

INPUT:

  • s - a string.
  • n - a number.

OUTPUT:

a tuple (string,integer,integer)

EXAMPLES:

sage: s=”Point(-1.3427,0.1223)” sage: number_at_position(s,9) (‘-1.3427’, 6, 13) sage: number_at_position(s,6) (‘-1.3427’, 6, 13)

sage: number_at_position(s,3) (False, 0, 0)

sage: s=”begin{pspicture}(-0.375000000000000,-1.94848632812500)(3.00000000000000,1.94860839843750)” sage: number_at_position(s,20) (‘-0.375000000000000’, 18, 36)

sage: number_at_position(s,27) (‘-0.375000000000000’, 18, 36)

sage: number_at_position(s,60) (‘3.00000000000000’, 56, 72)

sage: number_at_position(s,80) (‘1.94860839843750’, 73, 89)

That allows to make cool replacements. In the following, we replace the occurrence of “0.12124” that is on position 4:

sage: s="Ps=0.12124 and Qs=0.12124"
sage: v,first,last=number_at_position(s,4)
sage: print s[:first]+"AAA"+s[last:]
Ps=AAA and Qs=0.12124

NOTE:

We cannot return the number since the aim is to substitute it as string in the function string_number_comparison().

The problem in returning a number is the following:

sage: SR(str('1.94848632812500'))
1.94848632812
phystricks.SmallComputations.polar_with_dilatation(r, theta, xunit=1, yunit=1)

return the polar coordinated that you have to give in such a way the it visually appears (r,theta) when xunit and yunit are given.

The input and output angles are in radian.

INPUT:

  • r - the distance you want to see.
  • theta - the angle you want to see (radian).
  • xunit - the dilatation factor in the x direction.
  • yunit - the dilatation factor in the y direction.

OUTPUT:

a tuple (distance,angle)

EXAMPLES:

sage: polar_with_dilatation(2,pi,2,1)
(1, pi)
sage: polar_with_dilatation(1,pi/4,2,2)
(1/2, 1/4*pi)

Notice the difference between:

sage: polar_with_dilatation(1,pi/2,2,1/2)
(2, 1/2*pi)

and:

sage: polar_with_dilatation(1,pi/2,2,0.5)
(2.00000000000000, 1/2*pi)
phystricks.SmallComputations.string_number_comparison(s1, s2, epsilon=0.01, last_justification='')

Compare two strings.

The comparison is True is the two string differ by numbers that are epsilon-close.

It return a tuple of a boolean and a string. The string is a justification of the result.

INPUT:

  • s1 - first string.
  • s2 - second string.
  • epsilon - tolerance.

OUTPUT:

tuple (boolean,string). The boolean says if the two strings are equal up to epsilon-close numbers.
The string provides a short explanation.

EXAMPLES:

In the following, the comparison fails due to the first number:

sage: s1="Point(-0.2,0.111)"
sage: s2="Point(-0.3,0.111)"
sage: string_number_comparison(s1,s2)
(False, 'Distance between -0.2 and -0.3 is larger than 0.01.')

In the following the comparison fails due to the second number:

sage: s1="Point(-0.02,1)"
sage: s2="Point(-0.03,2)"
sage: string_number_comparison(s1,s2,epsilon=0.1)
(False, 'd(-0.02,-0.03)=0.01\nDistance between 1 and 2 is larger than 0.100000000000000.')

Here the comparison succeed:

sage: s1="Point(1.99,1.001)"
sage: s2="Point(2,1.002)"
sage: string_number_comparison(s1,s2,epsilon=0.1)
(True, 'd(1.99,2)=-0.01\nd(1.001,1.002)=-0.001\n')

Main module

A collection of tools for building LaTeX-pstricks figures with python.

COMMAND LINE ARGUMENTS:

  • --pdf - the picture arrives as an includegraphics of a pdf. It also creates the pdf file.

  • --eps - the picture arrives as an includegraphics of a eps. It also creates the eps file.

  • --png - the picture arrives as an includegraphics of a png. It also creates the png file.

  • --create-png - create the png file, but does not change the .pstricks

    file. Thus the LaTeX output will not be modified.

    See TestPspictLaTeXCode and the function create_png_file() in PspictureToOtherOutputs

NOTES:

  • Here we are really speaking about pspicture. There will be one file of one includegraphics for each pspicture. This is not figure-wise.
  • Using –pdf, –create-png, etc. create the picture from an auxiliary LaTeX file that will we compiled and converted on the fly. As a consequence, customizations (e.g. fonts) will not be taken into account. See pspict.specific_needs
  • --create_tests - create a tmp file in which the pspicture is written.

  • --tests - compares the produced pspicture with the corresponding tmp file and

    raises a ValueError if it does not correspond. If this option is set, nothing is written on the disk.

    See TestPspictLaTeXCode

phystricks.AffineVector(A=None, B=None)

return an affine vector.

An affine vector is a vector whose origin is not specifically (0,0).

EXAMPLES:

An affine vector can be given by two points:

sage: print AffineVector(Point(1,1),Point(pi,sqrt(2)))
vector I=Point(1,1) F=Point(pi,sqrt(2))

It can be simply derived from a segment:

sage: segment=Segment( Point(1,1),Point(2,2)  )
sage: av=AffineVector(segment)
sage: print av
vector I=Point(1,1) F=Point(2,2)

If you pass an object which has a method segment, the AffineVector() will provide the corresponding affine vector:

sage: from phystricks.BasicGeometricObjects import SingleAxe
sage: axe=SingleAxe(  Point(-2,2),Vector(1,1),-3,3  )
sage: print AffineVector(axe)
vector I=Point(-5,-1) F=Point(1,5)

NOTE:

The main difference between a Segment() an AffineVector() is that the latter will be draw with an arrow. There are also some difference in their behaviour under rotation, dilatation and operations like that.

phystricks.Angle(A, O, B, r=None)

Return the angle AOB.

It represent the angle formed at the point O with the lines OA and OB (in that order).

INPUT:

  • A,O,A - points.
  • r - (default, see below) the radius of the arc circle marking the angle.

OUTPUT:

An object ready to be drawn of type GraphOfAnAngle.

If r is not given, a default value of 0.2 times the length OA is taken.

EXAMPLES:

Notice the difference between AOB and BOA:

sage: A=Point(1,1)
sage: O=Point(0,0)
sage: B=Point(1,0)
sage: print Angle(A,O,B).measure()
AngleMeasure, degree=-45.0000000000000,radian=7/4*pi
sage: print Angle(B,O,A).measure()
AngleMeasure, degree=45.0000000000000,radian=1/4*pi
from phystricks import *
def TriangleRectangle():
	pspict,fig = SinglePicture("TriangleRectangle")

	B=Point(0,0)
	C=Point(1,0)
	A=Point(0.5,0.5*sqrt(3))

	A.put_mark(0.3,90,"$A$")
	B.put_mark(0.3,180,"$B$")
	C.put_mark(0.3,0,"$C$")

	AB=Segment(A,B)
	AC=Segment(A,C)
	BC=Segment(C,B)


	H=BC.center()
	hauteur=Segment(A,H)
	hauteur.parameters.style="dotted"
	hauteur.parameters.color="blue"
	H.put_mark(0.3,-90,"$H$")


	angleS=Angle(A,C,H)
	angleT=Angle(H,A,C)
	angleS.parameters.color="red"
	angleT.parameters.color="cyan"
	angleS.put_mark(0.3,angleS.advised_mark_angle,"$60$")
	angleT.put_mark(0.3,angleT.advised_mark_angle,"$30$")


	pspict.DrawGraphs(AB,AC,BC,hauteur,A,B,C,H,angleS,angleT)
	pspict.dilatation(4)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigTriangleRectanglePICTTriangleRectangle-for_eps.png
phystricks.Circle(center, radius, angleI=0, angleF=360)

Return a circle of given radius and center.

INPUT:

  • center - the center of the circle.
  • radius - the radius of the circle.
  • angleI - (default=0) If you want an arc of circle, this is the beginning angle.
  • angleF - (default=0) If you want an arc of circle, this is the ending angle.

OUTPUT:

A circle ready to be drawn

EXAMPLES:

The following describes the usual trigonometric circle:

sage: circle=Circle(Point(0,0),1)
sage: print circle.angleI
AngleMeasure, degree=0.000000000000000,radian=0
sage: print circle.angleF
AngleMeasure, degree=360.000000000000,radian=0
phystricks.CircleOA(O, A)

From the centrer O and a point A, return the circle.

INPUT:

  • O - a point that will be the center of the circle.
  • A - a point on the circle.

OUTPUT:

A circle ready to be drawn of type GraphOfACircle.

EXAMPLES:

sage: A=Point(2,1)
sage: O=Point(0,0)
sage: circle=CircleOA(O,A)
sage: circle.radius
sqrt(5)
phystricks.CustomSurface(*args)

Represent the surface contained between some lines and (parametric) curves.

INPUT: - *args - la tuple of lines like segments, functions, parametric curves.

EXAMPLE:

The following describes the surface between the circle of radius 1 and the square of length 1:

sage: C=Circle(Point(0,0),1)
sage: arc=C.parametric_curve(0,pi/2)
sage: h=Segment(Point(0,1),Point(1,1))
sage: v=Segment(Point(1,1),Point(1,0))
sage: surf=CustomSurface(arc,h,v)
sage: print unify_point_name(surf.pstricks_code())
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](0,1.00000000000000){Xaaaa}
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](1.00000000000000,1.00000000000000){Xaaab}
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](1.00000000000000,1.00000000000000){Xaaac}
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](1.00000000000000,0){Xaaad}
\pscustom[linestyle=none,linecolor=black,fillstyle=vlines]{
\parametricplot[plotstyle=curve,linestyle=solid,plotpoints=1000,linecolor=blue]{0.000000000000000}{1.57079632679490}{cos(t) | sin(t) }
<BLANKLINE>
\pstLineAB[linestyle=solid,linecolor=black]{Xaaaa}{Xaaab}
<BLANKLINE>
\pstLineAB[linestyle=solid,linecolor=black]{Xaaac}{Xaaad}
}

The border is not drawn.

This is somewhat the more general use of the pstricks’s macro pscustom

phystricks.GenericFigure(nom)

This function returns a figure with some default values. It creates coherent label, file name and prints the lines to be appended in the LaTeX file to include the figure.

class phystricks.Grid(bb=None)

A grid. This is main lines to appear at regular interval on the picture.

ATTRIBUTES:

  • self.BB - the bounding box of the grid : its size.
  • self.Dx,self.Dy - the step of main subdivision along X and Y directions (have to be integers).
  • self.num_subX,self.num_subY - number of subdivision within each main subdivision of length Dx or Dy. When it is zero, there are no subdivisions.

It draws lines on the integer multiples of Dx. It begins at the closest integer multiple of Dx from the lower left corner. It finishes before to reach the upper right corner if Dx the size. Subdivisions are drawn following the same rule.

  • self.draw_border - (default=False) If True, the border is drawn even if it does not arrives on an integer multiple of Dx.

    It turns out that for aestetical reasons, this is a bad idea to turn it True.

  • self.main_horizontal : an objet of type GraphOfASegment. This is the archetype of the horizontal lines

    of the main grid will be drawn.

As an example, in order to have red main horizontal lines:

sage: grid=Grid()
sage: grid.main_horizontal.parameters.color = "red"
phystricks.ImplicitCurve(f, xrange, yrange, plot_points=100)

return the implicit curve given by equation f on the range xrange x yrange

This is a constructor for the class GraphOfAnImplicitCurve INPUT: - f – a function of two variables or equation in two variables

  • xrange,yrange - the range on which we want to compute the implicit curve.

OPTIONAL INPUT: - plot_points - (defautl : 100) the number of points that will be calculated in each direction.

The resulting bounding box will not be in general xrange x yrange. EXAMPLES: We know that the curve x^2+y^2=2 is a circle of radius sqrt(2). Thus even if you ask a range of size 5, you will only get the bounding box of size sqrt(2) sage: var(‘x,y’) (x, y) sage: f(x,y)=x**2+y**2 sage: F=ImplicitCurve(f==2,(x,-5,5),(y,-5,5)) sage: print F.bounding_box() (-1.413,-1.413),(1.413,1.413)

But the following will be empty : sage: G=ImplicitCurve(f==2,(x,-1,1),(y,-1,1)) sage: print G.paths []

If you give very low value of plot_points, you get incorrect results : sage: H=ImplicitCurve(f==2,(x,-2,2),(y,-2,2),plot_points=3) sage: print H.bounding_box() (-1.414,-1.414),(1.414,1.414)

Using Sage’s implicit_curve and matplotlib, a list of points “contained” in the curve is created. The bounding_box is calculated from that list. The pstricsk code generated will be an interpolation curve passing trough all these points.

phystricks.InterpolationCurve(points_list, context_object=None)

determine an interpolation curve from a list of points.

INPUT: - points_list - a list of points that have to be joined.

OPTIONAL INPUT:

  • context_object - the object that is going to use the InterpolationCurve’s pstricks_code.

    ImplicitCurve and wavy curves are using InterpolationCurve as “backend” for the pstricks_code. Here we use the context_object in order to take this one into account when determining the parameters (color, ...). See self.pstricks_code().

EXAMPLES:

This example is valid, but will not plot the expected line (this is a feature of pscurve):

sage: F=InterpolationCurve([Point(0,0),Point(1,1)])

If you want to plot the small segment, you have to add a point in the center:

sage: F=InterpolationCurve([Point(0,0),Point(0.5,0.5),Point(1,1)])

The following draws a circle:

sage: C=Circle(Point(0,0),1)
sage: G=InterpolationCurve([C.get_point(2*pi/i,advised=False) for i in range(1,100)])

Notice in the lase example the use of advised=False in order to speed up the computation.

NOTE:

InterpolationCurve is used in order to produce implicit plot and wavy functions.

phystricks.Intersection(f, g)

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

EXAMPLES:

sage: fun=phyFunction(x**2-5*x+6)
sage: droite=phyFunction(2)
sage: pts = Intersection(fun,droite)
sage: for P in pts:print P
Point(4,2)
Point(1,2)
phystricks.MeasureLength(seg, dist=0.10000000000000001)

When a segment exists, one wants sometimes to denote its length drawing a double-arrow parallel to the segment. This is what this class is intended to.

The segment (and then the graph associated with the mark) is the parallel one, not the segment given in argument.

INPUT:

  • seg - the segment to be measured.
  • dist - the distance between the segment and the measure.

The sign of <dist> is an issue. If you give 0.3 you get one result, if you give -0.3, you get the segment on the other side. The algorithm is the following. If v is the vector seg.I –> seg.F and w is the vector from <seg> to the arrow line to be drawn, then (v,w) has the same orientation as (Y,X) where X=(1,0) and Y=(0,1). The rational is that if the segment is vertical, we want the measure to appear on the right.

EXAMPLES:

from phystricks import *
def IntervalleUn():
	pspict,fig = SinglePicture("Intervalle")

	O=Point(0,0)
	A=Point(0.3,0)
	U=Point(1,0)

	I=Point(-0.5,0)
	F=Point(1.5,0)
	
	A.put_mark(0.3,90,"$a$")
	O.put_mark(0.3,90,"$0$")
	U.put_mark(0.3,90,"$1$")
	pspict.DrawGraph(Segment(I,F))
	pspict.DrawGraphs(A,O,U)

	measureOA=MeasureLength(Segment(O,A),0.1)
	measureOA.put_mark(0.3,measureOA.advised_mark_angle,"$a$")
	measureAU=MeasureLength(Segment(A,U),0.1)
	measureAU.put_mark(0.3,measureAU.advised_mark_angle,"$1-a$")

	pspict.DrawGraphs(measureOA,measureAU)

	pspict.dilatation(3)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigIntervallePICTIntervalle-for_eps.png

In order to check the position of the arrow line, we check the position of the mark_point:

sage: O=Point(0,0)
sage: A=Point(1,0)

Horizontal line directed from right to left; the arrow line has to be bellow:

sage: measureOA=MeasureLength(Segment(O,A),0.1)
sage: print measureOA.mark_point()
Point(0.5,-0.100000000000000)

Horizontal line directed from left to right:

sage: measureAO=MeasureLength(Segment(A,O),0.1)
sage: print measureAO.mark_point()
Point(0.5,0.100000000000000)

Vertical line:

sage: B=Point(0,2)
sage: measureOB=MeasureLength(Segment(O,B),0.1)
sage: print measureOB.mark_point()
Point(0.100000000000000,1.0)

USEFUL ATTRIBUTE:

  • self.advised_mark_angle - the angle at which we advise you to put the mark.

    It indicates the direction orthogonal to the segment, with the orientation given in the discussion about the sign of <dist>.

sage: m=MeasureLength(Segment( Point(1,1) ,Point(2,2) ),0.1)
sage: print m.advised_mark_angle
AngleMeasure, degree=315.000000000000,radian=-1/4*pi

You are invited to use advised_mark_angle. If not the position of the mark could be unpredictable.

phystricks.MultiplePictures(name, n)

return a figure with multiple subfigures. This is the other 10% of cases.

INPUT:

  • name - the name of the figure.
  • n - the number of subfigures.

You have to think about naming the subfigures.

EXAMPLE:

sage: pspict,fig = MultiplePictures("MyName",3)
The result is on figure \ref{LabelFigMyName}.
\newcommand{\CaptionFigMyName}{<+Type your caption here+>}
\input{Fig_MyName.pstricks}
See also the subfigure \ref{LabelFigMyNamessLabelSubFigMyName0}
See also the subfigure \ref{LabelFigMyNamessLabelSubFigMyName1}
See also the subfigure \ref{LabelFigMyNamessLabelSubFigMyName2}
sage: pspict[0].mother.caption="My first subfigure"
sage: pspict[1].mother.caption="My second subfigure"
sage: pspict[2].mother.caption="My third subfigure"

Notice that a caption is related to a figure or a subfigure, not to a pspicture.

See also subfigure

phystricks.ParametricCurve(*args, **opt)

This class describes a parametric curve.

INPUT:

  • f1,f2 - functions that are the components of the parametric curve.
  • mx,Mx - (optionals) Initial and final value of the parameter.

Alternatively you can give a parametric curve as only argument.

If mx and Mx are given, a graph object is returned.

OUTPUT: an object ready to be drawn.

EXAMPLES:

sage: x=var('x')
sage: f1=phyFunction(x)
sage: f2=phyFunction(x**2)
sage: F=ParametricCurve(f1,f2).graph(-2,3)
sage: G=ParametricCurve(f1,f2,mx=-2,Mx=3)
sage: print F.pstricks_code()
\parametricplot[plotstyle=curve,linestyle=solid,plotpoints=1000,linecolor=blue]{-2.00000000000000}{3.00000000000000}{t | t^2 }
sage: F.pstricks_code()==G.pstricks_code()
True

Notice that due to several @lazy_attribute, changing the components after creation could produce funny results.

from phystricks import *
def Cycloide():
    pspict,fig = SinglePicture("Cycloide")

    a=1
    var('x')
    f1=a*(x-sin(x))
    f2=a*(1-cos(x))
    curve=ParametricCurve(f1,f2).graph(0,4*pi)

    pspict.DrawGraph(curve)
    pspict.DrawDefaultAxes()

    pspict.dilatation(1)

    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigCycloidePICTCycloide-for_eps.png
phystricks.Point(x, y)

return a point.

INPUT:

  • x,y - the coordinates of the point. These are numbers.

EXAMPLES:

sage: print Point(1,1)
Point(1,1)
sage: print Point(pi,sqrt(2))
Point(pi,sqrt(2))

You can pass variables:

sage: x=var('x')
sage: P=Point(x**2,1)   
sage: print P
Point(x^2,1)

Notice that the coordinates of the point have to be numerical in order to be passed to pstricks at the end:

sage: print P.pstricks_code()
Traceback (most recent call last):
...
TypeError: cannot evaluate symbolic expression numerically
phystricks.PolarCurve(fr, ftheta=None)

return the parametric curve (ParametricCurve) corresponding to the curve of equation r=f(theta) in polar coordinates.

If ftheta is not given, return the curve x(t)=fr(t)cos(t) y(t)=fr(t)sin(t)

If ftheta is given, return the curve x(t)=fr(t)cos( ftheta(t) ) y(t)=fr(t)sin( ftheta(t) )

EXAMPLES:

from phystricks import *
def Cardioid():
	pspict,fig = SinglePicture("Cardioid")
	
	var('x')
	a=1.5
	f=a*(1+cos(x))
	cardioid=PolarCurve(f).graph(-pi,pi)
	cardioid.parameters.color="red"

	pspict.DrawGraph(cardioid)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigCardioidPICTCardioid-for_eps.png
phystricks.PolarPoint(r, theta)

return the point at polar coordinates (r,theta).

INPUT:

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

EXAMPLES:

sage: print PolarPoint(2,45)
Point(sqrt(2),sqrt(2))
phystricks.PolarSegment(P, r, theta)

returns a segment on the base point P (class Point) of length r angle theta (degree)

phystricks.Polygon(*args)

represent a polygon.

from phystricks import *
def ExPolygone():
    pspict,fig = SinglePicture("ExPolygone")

    A=Point(1,1)
    B=Point(2,0)
    C=Point(2,-1)
    D=Point(0,0)
    poly=Polygon( A,B,C,D )
    poly.parameters.hatched()
    poly.parameters.hatch.color="green"
    poly.edge.parameters.color="blue"

    pspict.DrawGraphs(poly)
    pspict.DrawDefaultAxes()
    pspict.dilatation(1)
    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigExPolygonePICTExPolygone-for_eps.png
phystricks.Rectangle(*args)

INPUT:

  • NW,SE - the North-West corner and South-East corner

Alternatively, you can pass a bounding box as unique argument.

phystricks.SingleAxe(C, base, mx, Mx)

Return an axe.

INPUT:

  • C - the center of the axe. This is the point corresponding to the “zero” coordinate

  • base - the unit of the axe. This indicates

    1. the direction
    2. the size of “1”

    A mark will be added at each integer multiple of that vector (but zero) including negative.

  • mx - the multiple of base at which the axe begins. This is typically negative

  • Mx - the multiple of base at which the axe ends. This is typically positive

    The axe goes from C+mx*base to C-Mx*base.

OTHER CONTROLS :

The default behaviour can be modified by the following attributes.

  • self.Dx - (default=1) A mark is written each multiple of self.Dx*base.

  • self.mark_angle - the angle in degree under which the mark are written. By default this is orthogonal

    to the direction given by self.base.

If an user-defined axes_unit is given, the length of base is “forgotten”

EXAMPLES:

sage: axe = SingleAxe(Point(1,1),Vector(0,1),-2,2)
phystricks.SinglePicture(name)

Return the tuple of pspicture and figure that one needs in 90% of the cases.

phystricks.SurfaceBetweenFunctions(f1, f2, mx=None, Mx=None)

Represents a surface between two functions.

INPUT:

  • f1,f2 - functions (sage or phyFunction). f1 is considered to be the upper function while f2 is the lower function.

  • mx,Mx - (optional) initial and end values of x. If these are not given, we suppose that f1 and f2 are graphs.

    If f1 is a graph while mx is given, the value of f1.mx is forgotten and the given mx is taken into account.

EXAMPLES:

If you want the surface to be blue

sage: surf=SurfaceBetweenFunctions(sin(x)+3,cos(x),0,2*pi)
sage: surf.parameters.color="blue"

If you want the function f1 to be red without changing the color of the surface, you have to change the color AND the style:

sage: surf.f1.parameters.color="red"
sage: print "red" in surf.pstricks_code(),"solid" in surf.pstricks_code()
True True

Notice that the output of surf.pstricks_code() is too long to be written here.

You can also try to control the option linestyle (use add_option).

from phystricks import *
def exSurfaceBetweenFunction():
	pspict,fig = SinglePicture("exSurfaceBetweenFunction")

	var('x')
	f1=x**2-3
	f2=log(x)
	mx=0.5
	Mx=3
	surf1=SurfaceBetweenFunctions(f1,f2,mx,Mx)
	surf1.parameters.filled()
	surf1.parameters.fill.color="green"
	surf1.Isegment.parameters.style="dashed"
	surf1.Isegment.parameters.color="red"
	surf1.f1.parameters.style="solid"
	surf1.f1.parameters.color="magenta"

	pspict.DrawGraphs(surf1)

	pspict.DrawDefaultAxes()
	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigexSurfaceBetweenFunctionPICTexSurfaceBetweenFunction-for_eps.png
phystricks.SurfaceBetweenParametricCurves(curve1, curve2, interval=None, reverse1=False, reverse2=True)

Represents a surface between two parametric curves.

INPUT:

  • curve1,curve2 - two parametric curves.

OPTIONAL ARGUMENTS : - (mx1,Mx1) - a tuple. Initial and final values of the parameter for the first curve.

  • reverse1 - (default=False) if True, reverse the sense of curve1.
  • reverse2 - (default=True) if True, reverse the sense of curve1.

Let us suppose that curve1 goes from A1 to B1 and curve2 from A2 to B2 If we do not reverse the sense of anything, the result will be the surface delimited by

curve1: A1 -> B1 Fsegment: B1 -> B2 curve2: A2 -> B2 Isegment: A2 -> A1

This is wrong since the last point of each line is not the first point of the next line.

For that reason, the second curve is, by default, reversed in order to get curve1: A1 -> B1 Fsegment: B1 -> B2 curve2 (reversed): B2 -> A2 Isegment: A2 -> A1

OUTPUT: An object ready to be draw.

EXAMPLES:

sage: curve1=ParametricCurve(x,x**2).graph(2,3)
sage: curve2=ParametricCurve(x,x**3).graph(2,5)
sage: region=SurfaceBetweenParametricCurves(curve1,curve2)

The segment “closing” the domain are available by the attributes Isegment and Fsegment:

sage: print region.Isegment
segment I=Point(2,8) F=Point(2,4)
sage: print region.Fsegment
segment I=Point(3,9) F=Point(5,125)

The initial and final values of the parameters can be given in different ways. The “normal” way is to provide the curves by triples (curve,mx,Mx):

sage: f1=phyFunction(x**2)
sage: f2=phyFunction(x)
sage: curve=SurfaceBetweenParametricCurves((f1,1,2),(f2,3,4))
sage: print curve.mx1,curve.Mx1,curve.mx2,curve.Mx2
1 2 3 4

If one of the curve is provided without interval, the latter will be deduced:

sage: f1=phyFunction(x**2).graph(1,2)
sage: f2=phyFunction(x)
sage: curve=SurfaceBetweenParametricCurves(f1,(f2,3,4))
sage: print curve.mx1,curve.Mx1,curve.mx2,curve.Mx2
1 2 3 4

If the optional argument interval is provided, it erases the other intervals:

sage: f1=phyFunction(x**2).graph(1,2)
sage: f2=phyFunction(x)
sage: curve=SurfaceBetweenParametricCurves(f1,(f2,3,4),interval=(7,8))
sage: print curve.mx1,curve.Mx1,curve.mx2,curve.Mx2
7 8 7 8

NOTE: If the two curves make intersections, the result could be messy.

from phystricks import *
def BetweenParametric():
    pspict,fig = SinglePicture("BetweenParametric")
    
    x=var('x')
    curve1=ParametricCurve(sin(x)-1,x).graph(-3,3)
    curve2=ParametricCurve(3+x+cos(x),sin(x/2)).graph(-2,2)

    curve1.parameters.style="solid"
    curve1.parameters.color="red"
    curve2.parameters.style="solid"
    curve2.parameters.color="green"

    region=SurfaceBetweenParametricCurves(curve1,curve2)

    region.parameters.color="cyan"
    region.Fsegment.parameters.style="solid"
    region.Fsegment.parameters.color="blue"
    region.Isegment.parameters.style="solid"
    region.Isegment.parameters.color="brown"

    pspict.DrawGraphs(region)
    pspict.DrawDefaultAxes()
    pspict.dilatation(1)
    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigBetweenParametricPICTBetweenParametric-for_eps.png
phystricks.SurfaceUnderFunction(f, mx, Mx)

Represent a surface under a function.

This is a particular case of SurfaceBetweenFunctions when the second function is the y=0 axis.

The function f becomes self.f1 while self.f2 will be the function 0 (this is a consequence of inheritance). The function f will also be recorded as self.f.

INPUT:

  • f - a function
  • mx,Mx - initial and final values

EXAMPLES:

from phystricks import *
def SurfaceFunction():
	pspict,fig = SinglePicture("SurfaceFunction")

	var('x')
	f=2*sin(x)
	a=0.5
	b=pi/2
	surf1=SurfaceUnderFunction(f,a,b)
	surf1.parameters.color="blue"

	fun = phyFunction(f).graph(3*pi/4,2*pi+0.5)
	surf2=fun.surface_under()

	pspict.DrawGraphs(surf1,surf2)

	pspict.DrawDefaultAxes()
	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigSurfaceFunctionPICTSurfaceFunction-for_eps.png
phystricks.Text(P, text, hide=True)

A text.

INPUT:

  • P - the point at which the center of the bounding box will lie.

  • text - the text.

  • hide - (default=True) When True, the background of the text is hidden by

    a rectangle. The color and style of that rectangle can be customized, see BasicGeometricObjects.GraphOfAText

phystricks.Vector(*args)

From the coordinates x,y, return the corresponding vector, i.e. the affine vector from (0,0) to (x,y).

You can also only give a Point

phystricks.VectorField(fx, fy, xvalues=None, yvalues=None, draw_points=None)

return a vector field that is drawn on the points given in the list.

INPUT:

  • fx,fy - two functions

OPTIONAL :

  • xvalues - a tuple (x,mx,Mx,n) where mx and Mx are the min and max values of x and

    n is the number of values to be used on that interval.

  • draw_points - a list of points on which the vector field has to be drawn.

    If draw_point is given, xvalues and yvalues are not taken into account.

OUTPUT: the graphe vector field.

EXAMPLES:

sage: x,y=var('x,y')
sage: F=VectorField(x*y,cos(x)+y)
sage: F.divergence()
(x, y) |--> y + 1

If you want an automatic Cartesian grid of points, use xvalues and yvalues:

sage: F=VectorField(exp(x+y),x**2+y**2,xvalues=(x,-1,1,3),yvalues=(y,-5,5,6))
sage: len(F.draw_points)
18
sage: print F.draw_points[5]
Point(-1.0,5.0)

The same can be obtained using the following syntax (see the function GeometricVectorField.graph):

sage: F=VectorField(exp(x+y),x**2+y**2).graph(xvalues=(x,-1,1,3),yvalues=(y,-5,5,6))
sage: len(F.draw_points)
18
sage: print F.draw_points[5]
Point(-1.0,5.0)

If you want a personal list of points, use draw_points

sage: F=VectorField(exp(x+y),x**2+y**2, draw_points=[Point(1,1),Point(5,-23)] )
sage: print F.draw_points[0]
Point(1,1)    
sage: print F.draw_points[1]
Point(5,-23)

A vector field with automatic management of the points to be drawn:

from phystricks import *
def ChampVecteursDeux():
    pspict,fig = SinglePicture("ChampVecteursDeux")

    x,y=var('x,y')

    Field=VectorField( sin(x)/2,sin(y)/2 )
    F=Field.graph(xvalues=(x,-6,6,20),yvalues=(y,-6,6,20))

    pspict.DrawGraphs(F)
    pspict.dilatation(1)
    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigChampVecteursDeuxPICTChampVecteursDeux-for_eps.png

A vector field with given points to be drawn:

from phystricks import *
def ChampVecteurs():
    pspict,fig = SinglePicture("ChampVecteurs")

    x,y=var('x,y')

    draw_points=[]
    for i in range(1,10):
        C=Circle(Point(0,0),float(i)/2)
        pts=C.get_regular_points(0,360,0.5)
        draw_points.extend(pts)

    l=(1.0/3)
    Field=VectorField(l*y/sqrt(x**2+y**2),l*-x/sqrt(x**2+y**2))
    F=Field.graph(draw_points=draw_points)

    pspict.DrawGraphs(F)
    pspict.dilatation(1)
    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigChampVecteursPICTChampVecteurs-for_eps.png
phystricks.allocatemem()

File: sage/libs/pari/gen.pyx (starting at line 9391)

Double the PARI stack.

class phystricks.global_variables

Some global variables

  • create_formats - dictionary which says the exit files we want to produce. These can be

    • eps,pdf,pfd : I think that these names are self-explaining.
    • test : outputs a tmp file
  • exit_format - the format one wants to use in the LaTeX file. By default it is pstricks.

  • perform_tests - (default=False) If True, perform the tests.

The difference between create_formats and exit_format is that create_format says what files are going to be _produced_ while exit_format is the format that LaTeX will see.

Notice that create_formats is a plural while exit_format is a singlular. This is not a joke ;)

phystricks.phyFunction(fun, mx=None, Mx=None)

Represent a function.

INPUT:

  • fun - a function.
  • mx,Mx - initial and final value of the argument.

EXAMPLES:

sage: f=phyFunction(cos(x))
sage: f(pi/2)
0

sage: g=phyFunction(2*f,0,pi)
sage: g(pi)
-2
phystricks.unify_point_name(s)

Internet s as the pstricks code of something and return a chain with all the points names changed to “Xaaaa”, “Xaaab” etc.

Practically, it changes the strings like “{abcd}” to “{Xaaaa}”.

When “{abcd}” is found, it also replace the occurences of “(abcd)”. This is because the marks of points are given by example as ‘\rput(abcd){\rput(0;0){$-2$}}’

This serves to build more robust doctests by providing strings in which we are sure that the names of the points are the first in the list.

INPUT:

  • s - a string

OUTPUT: string

EXAMPLES:

In the following example, the points name in the segment do not begin by “aaaa” because of the definition of P, or even because of other doctests executed before. (due to complex implementation, the names of the points are more or less unpredictable and can change)

sage: P=Point(3,4)
sage: S = Segment(Point(1,1),Point(2,2))
sage: print S.pstricks_code()       # random
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](1.00000000000000,1.00000000000000){aaad}
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](2.00000000000000,2.00000000000000){aaae}
<BLANKLINE>
\pstLineAB[linestyle=solid,linecolor=black]{aaad}{aaae}

However, using the function unify_point_name, the returned string begins with “Xaaaa”

sage: print unify_point_name(S.pstricks_code())
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](1.00000000000000,1.00000000000000){Xaaaa}
\pstGeonode[PointSymbol=none,linestyle=solid,linecolor=black](2.00000000000000,2.00000000000000){Xaaab}
<BLANKLINE>
\pstLineAB[linestyle=solid,linecolor=black]{Xaaaa}{Xaaab}

Notice that the presence of “X” is necessary in order to avoid conflicts when one of the points original name is one of the new points name as in the following example

sage: s="{xxxx}{aaaa}{yyyy}"
sage: print unify_point_name(s)
{Xaaaa}{Xaaab}{Xaaac}

Without the additional X,

  1. The first “xxxx” would be changed to “aaaa”.

  2. When changing “aaaa” into “aaab”, the first one

    would be changed too.

sage: P=Point(-1,1)
sage: P.put_mark(0.3,90,"$A$")
sage: unify_point_name(P.mark.pstricks_code())
'\\pstGeonode[](-1.00000000000000,1.30000000000000){Xaaaa}\n\\rput(Xaaaa){\\rput(0;0){$A$}}'

Others

This module uses phystricks in order to produces some mathematical situations/

class phystricks.MathConstructions.CalculPolynome

This class should disappear when I learn how to perform euclidian divisions with Sage.

class phystricks.MathConstructions.NewtonMethodStep(newton, xn)

Return the informations about one step of the Newton method.

self.A : the starting x value self.P : the starting point on the graph self.B : the next point self.vertical_segment : the Segment from the point (xn,0) and the point P self.diagonal_segment : the Segment which joins the point P and x_{n+1}

phystricks.MathConstructions.allocatemem()

File: sage/libs/pari/gen.pyx (starting at line 9391)

Double the PARI stack.

Examples

from phystricks import *
def Dilatation():
    pspict,fig = SinglePicture("Dilatation")

    A = Point(1,0)
    B = Point(1,2)
    v=AffineVector(A,B)
    w1=v.dilatation(0.5)
    w2=v.dilatation(1.5)
    v.parameters.color="blue"
    w1.parameters.color="green"
    w2.parameters.color="red"
    pspict.DrawGraphs(w2,v,w1)

    C = Point(2,0)
    D = Point(2,2)
    s=Segment(C,D)
    t1=s.dilatation(0.5)
    t2=s.dilatation(1.5)
    s.parameters.color="blue"
    t1.parameters.color="green"
    t2.parameters.color="red"
    pspict.DrawGraphs(t2,s,t1)

    pspict.axes.single_axeX.no_numbering()
    pspict.DrawDefaultAxes()

    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigDilatationPICTDilatation-for_eps.png
from phystricks import *
def DevoirUnA():
    pspict,fig = SinglePicture("DevoirUnA")

    x=var('x')

    my=-1.5
    med=0
    My=1

    # Two vertical curves
    curve1=ParametricCurve(2*x**2+4*x+2,x).graph(my,My)
    curve2=ParametricCurve(sqrt(4-x**2),x).graph(my,My)

    curve1.parameters.style="solid"
    curve1.parameters.color="red"
    curve2.parameters.style="solid"
    curve2.parameters.color="brown"

    region=SurfaceBetweenParametricCurves(curve1,curve2,(med,My))
    region.parameters.filled()
    region.parameters.fill.color="green"

    region.Fsegment.parameters.style="dashed"
    region.Fsegment.parameters.color="blue"

    pspict.DrawGraphs(region)
    pspict.DrawDefaultAxes()
    pspict.dilatation(1)
    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigDevoirUnAPICTDevoirUnA-for_eps.png
from phystricks import *
import numpy
def NormalExterior():
    fig=GenericFigure("NormalExterior")
    ssfig1=fig.new_subfigure("Normal exterior vectors to the graph of a function.")
    ssfig2=fig.new_subfigure("Normal outward vector to a parametric curve. Notice that the second derivative vector (green) is not the normal exterior vector.")
    pspict1=ssfig1.new_pspicture()
    pspict2=ssfig2.new_pspicture()

    var('x')
    mx=-2*pi
    Mx=2*pi
    f=phyFunction(sin(x)).graph(mx,Mx)

    n=20
    for xx in numpy.linspace(mx,Mx,n):
        n=f.get_normal_vector(xx)
        pspict1.DrawGraphs(n)

    pspict1.DrawGraphs(f)
    pspict1.DrawDefaultAxes()

    f1=phyFunction(2*cos(x)+sin(x/2))
    f2=phyFunction(x**(1.5))
    mx=1
    Mx=5
    F=ParametricCurve(f1,f2).graph(mx,Mx)
    n=10
    for xx in numpy.linspace(mx,Mx,n):
        v=F.get_second_derivative_vector(xx)
        v.parameters.color="green"
        n=F.get_normal_vector(xx)
        pspict2.DrawGraphs(v,n)

    pspict2.DrawGraphs(F)
    #pspict2.DrawDefaultAxes()

    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigNormalExteriorsssubOPICTsubZ-for_eps.png _images/Picture_FIGLabelFigNormalExteriorsssubZPICTsubZ-for_eps.png
from phystricks import *
def ExInterpolation():
    pspictTwo,figTwo = SinglePicture("ExInterpolationTwo")
    pspictThree,figThree = SinglePicture("ExInterpolationThree")

    n=50
    C=Circle(Point(0,0),1)
    step=SR(360)/n
    G=InterpolationCurve([C.get_point(i*step,advised=False) for i in range(n)])
    H=InterpolationCurve([Point(-1,1),Point(1,1),Point(1,-1),Point(-1,-1)])

    pspictTwo.DrawGraphs(G)
    pspictTwo.DrawDefaultAxes()
    pspictTwo.dilatation(1)
    figTwo.conclude()
    figTwo.write_the_file()

    pspictThree.DrawGraphs(H,H.bounding_box())
    pspictThree.DrawDefaultAxes()
    pspictThree.dilatation(1)
    figThree.conclude()
    figThree.write_the_file()
_images/Picture_FIGLabelFigExInterpolationThreePICTExInterpolationThree-for_eps.png _images/Picture_FIGLabelFigExInterpolationTwoPICTExInterpolationTwo-for_eps.png
from phystricks import *
def ImplicitTwo():
    pspict,fig = SinglePicture("ImplicitTwo")

    var('x,y')
    f=x**2+2*y**2
    G=ImplicitCurve(f==sqrt(2),(x,-5,5),(y,-5,5),plot_points=200)

    pspict.DrawGraphs(G,G.bounding_box())
    pspict.DrawDefaultAxes()
    pspict.dilatation(1)
    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigImplicitTwoPICTImplicitTwo-for_eps.png
from phystricks import *
def Implicit():
    pspict,fig = SinglePicture("Implicit")

    var('x,y')
    f=x**2-y**2
    for i in range(-5,5):
        G=ImplicitCurve(f==i,(x,-3,3),(y,-3,3),plot_points=200)
        if i<0:
            G.parameters.color="red"
        if i==0:
            G.parameters.color="brown"
        pspict.DrawGraph(G)

    pspict.DrawDefaultAxes()
    pspict.dilatation(1)
    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigImplicitPICTImplicit-for_eps.png
from phystricks import *
def ImplicitOther():
    pspictOne,figOne = SinglePicture("ImplicitOtherOne")
    pspictTwo,figTwo = SinglePicture("ImplicitOtherTwo")
    pspictThree,figThree = SinglePicture("ImplicitOtherThree")
    pspictFour,figFour = SinglePicture("ImplicitOtherFour")

    var('x,y')
    F=ImplicitCurve(x**2+y**2-4==0,(x,-5,5),(y,-5,5))
    G=ImplicitCurve( (x**2+y**2)**2-8*(x**2-y**2)==0 ,(x,-5,5),(y,-5,5))
    H=ImplicitCurve( (x**3+y**3)-4*x*y==0 ,(x,-5,5),(y,-5,5))
    K=ImplicitCurve( y*cos(x*y)-0.2==0 ,(x,-5,5),(y,-5,5))
    L=ImplicitCurve( y*cos(x*y)-1.2==0 ,(x,-5,5),(y,-5,5))
    K.parameters.color='red'

    pspictOne.DrawGraphs(F,F.bounding_box())
    pspictOne.DrawDefaultAxes()
    pspictOne.dilatation(1)
    figOne.conclude()
    figOne.write_the_file()

    pspictTwo.DrawGraphs(G,G.bounding_box())
    pspictTwo.DrawDefaultAxes()
    pspictTwo.dilatation(1)
    figTwo.conclude()
    figTwo.write_the_file()

    pspictThree.DrawGraphs(H,H.bounding_box())
    pspictThree.DrawDefaultAxes()
    pspictThree.dilatation(1)
    figThree.conclude()
    figThree.write_the_file()

    pspictFour.DrawGraphs(K,L)
    pspictFour.DrawDefaultAxes()
    pspictFour.dilatation(1)
    figFour.conclude()
    figFour.write_the_file()
_images/Picture_FIGLabelFigImplicitOtherFourPICTImplicitOtherFour-for_eps.png _images/Picture_FIGLabelFigImplicitOtherOnePICTImplicitOtherOne-for_eps.png _images/Picture_FIGLabelFigImplicitOtherThreePICTImplicitOtherThree-for_eps.png _images/Picture_FIGLabelFigImplicitOtherTwoPICTImplicitOtherTwo-for_eps.png
from phystricks import *
def SpecificNeeds():
	pspict,fig = SinglePicture("SpecificNeeds")

	P=Point(1,1)
	pspict.specific_needs=r"""\usepackage{bbm}
	\usepackage{latexsym}
	\usepackage{amsfonts}
	\usepackage[reqno]{amsmath}
	\usepackage{amsthm}
	\usepackage{amssymb}
	\usepackage{amssymb}
	\newcommand{\mtu}{\mathbbm{1}}
	\DeclareMathOperator{\SO}{SO}"""
	P.put_mark(0.1,0,"$\mtu\in\SO(2)$",automatic_place=(pspict,"W"))

	pspict.DrawGraphs(P)
	#pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigSpecificNeedsPICTSpecificNeeds-for_eps.png
from phystricks import *
def ExSingleAxe():
	pspict,fig = SinglePicture("ExSingleAxe")

	base=Vector(1,2).normalize()
	C=Point(0,0)
	axe=SingleAxe(C,base,-1,1.5)

	pspict.DrawGraphs(axe,axe.bounding_box(pspict))
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigExSingleAxePICTExSingleAxe-for_eps.png
from phystricks import *
def TgCercleTrigono():
	pspict,fig = SinglePicture("TgCercleTrigono")

	O=Point(0,0)
	X=Point(1,0)
	Cercle=Circle(O,2)
	Q=Cercle.get_point(150)
	vQ=Vector(Q)


	phi=Angle(X,O,Q,0.5)
	phi.set_mark_angle(0.5*(90+phi.angleF.degree))
	phi.put_mark(0.3,phi.advised_mark_angle,r"$\varphi$")

	M=phi.mark_point()

	vQ.parameters.color="blue"
	M.parameters.color="brown"
	phi.parameters.color=vQ.parameters.color

	pspict.DrawGraphs(phi,vQ)
	pspict.DrawGraphs(M)
	pspict.axes.no_graduation()
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigTgCercleTrigonoPICTTgCercleTrigono-for_eps.png
from phystricks import *
def EdgePosition():
	pspict,fig = SinglePicture("EdgePosition")

	P=Point(0,1)
	Q=Point(1,0)
	R=Point(0,-1)
	S=Point(-1,0)
	text=r"$\alpha_yu\alpha_zv$"
	P.put_mark(0.1,90,text,automatic_place=(pspict,"S"))
	Q.put_mark(0.1,0,text,automatic_place=(pspict,"W"))
	R.put_mark(0.1,-90,text,automatic_place=(pspict,"N"))
	S.put_mark(0.1,180,text,automatic_place=(pspict,"E"))

	pspict.DrawGraphs(P,Q,R,S)
	bbP=P.mark.bounding_box(pspict)
	bbQ=Q.mark.bounding_box(pspict)
	bbR=R.mark.bounding_box(pspict)
	bbS=S.mark.bounding_box(pspict)
	pspict.DrawGraphs(bbP,bbQ,bbR,bbS)
	#pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigEdgePositionPICTEdgePosition-for_eps.png
from phystricks import *
def DefinitionCartesiennes():
	pspict,fig = SinglePicture("DefinitionCartesiennes")

	def PlacePoint(x,y,nom,color):
		M=Point(x,y)
		#print M,numerical_approx(M.angle())
		M.put_mark(0.1,M.angle(),"$(%s,%s)$"%(str(x),str(y)),automatic_place=pspict)
		Px=M.projection(pspict.single_axeX)
		Py=M.projection(pspict.single_axeY)
		seg1=Segment(M,Px)
		seg2=Segment(M,Py)
		seg1.parameters.color=color
		seg1.parameters.style="dashed"
		seg2.parameters=seg1.parameters
		pspict.DrawGraphs(seg1,seg2,M,M.mark.bounding_box(pspict))

	PlacePoint(3,1,"A","blue")
	PlacePoint(-1.5,-2.5,"B","green")
	PlacePoint(-1,2.5,"C","brown")
	PlacePoint(1.5,-1,"D","cyan")
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigDefinitionCartesiennesPICTDefinitionCartesiennes-for_eps.png
from phystricks import *
def BoxSize():
    pspict,fig = SinglePicture("BoxSize")

    text = "$A_i=\int_a^bf_i$"
    dimx,dimy=pspict.get_box_size(text)
    print "The dimensions of the LaTeX text %s is (%s,%s)"%(text,str(dimx),str(dimy))
    A = Point(1,1)
    A.put_mark(2,30,text)   # The text is far and large
    O=Point(0,0)
    C=Point(0,-2)
    C.put_mark(0.2,-45,"$D_{\ell}$")
    pspict.draw_bounding_box=True
    pspict.DrawGraphs(A,C,O)
    pspict.DrawGraphs(A.bounding_box(pspict),C.bounding_box(pspict),O.bounding_box(pspict))
    pspict.DrawGraphs(A.mark.bounding_box(pspict),C.mark.bounding_box(pspict))
    pspict.DrawGraphs(pspict.bounding_box())

    pspict.dilatation(1)
    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigBoxSizePICTBoxSize-for_eps.png
from phystricks import *
def InteractWithLaTeX():
	pspict,fig = SinglePicture("InteractWithLaTeX")

	A = Point(0,0)
	page = pspict.get_counter_value("page")
	A.put_mark(0.3,45,str(page))
	pspict.DrawGraph(A)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigInteractWithLaTeXPICTInteractWithLaTeX-for_eps.png

The result of that picture is only impressive when one sees it in the pdf document compiled by (pdf)LaTeX.

from phystricks import *
def exCustomSurface():
	pspict,fig = SinglePicture("exCustomSurface")

	var('x')
	f1=sin(x)
	f2=x
	mt=0
	Mt=3*pi/2
	mx=0
	Mx=3
	v1=ParametricCurve(f1,f2).graph(mt,Mt)
	v2=phyFunction((x/2)**2).graph(mx,Mx)
	A=v1.get_point(mt)
	B=v1.get_point(Mt)
	C=v2.get_point(Mx)
	sh=Segment(B,C)

	surf=CustomSurface(v1,sh,v2)
	surf.parameters.filled()
	surf.parameters.fill.color="red"

	pspict.DrawGraphs(surf)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigexCustomSurfacePICTexCustomSurface-for_eps.png
from phystricks import *
def GridOne():
	pspict,fig = SinglePicture("GridOne")

	var('x')
	f = phyFunction( x**2-x-1 )
	F=f.graph(-1.5,1.7)

	pspict.DrawGraph(F)

	pspict.DrawDefaultAxes()
	pspict.DrawDefaultGrid()

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigGridOnePICTGridOne-for_eps.png
from phystricks import *
def GridTwo():
	pspict,fig = SinglePicture("GridTwo")

	var('x')
	f = phyFunction( x**2-x-1 )
	F =f.graph(-3,3)

	pspict.DrawGraph(F)

	pspict.grid.Dx = 2
	pspict.grid.Dy = 3
	pspict.grid.num_subX = 0
	pspict.grid.num_subY = 5

	pspict.DrawDefaultAxes()
	pspict.DrawDefaultGrid()

	# The following vertically contracts the figure with a factor 2.
	pspict.dilatation_Y(0.5)	

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigGridTwoPICTGridTwo-for_eps.png
from phystricks import *
def GridThree():
	pspict,fig = SinglePicture("GridThree")

	var('x')
	f = phyFunction(2*x*sin(x))
	F =f.graph(-pi-0.5,pi+0.5)
	pspict.DrawGraph(F)

	pspict.grid.num_subX = 2
	pspict.grid.num_subY = 3
	pspict.grid.sub_vertical.parameters.color = "green"
	pspict.grid.sub_horizontal.parameters.color = "magenta"
	pspict.grid.main_horizontal.parameters.style = "dashed"

	pspict.DrawDefaultAxes()
	pspict.DrawDefaultGrid()

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigGridThreePICTGridThree-for_eps.png
from phystricks import *

def AxesSix():
	pspict,fig = SinglePicture("AxesSix")

	x=var('x')
	f=phyFunction( x/2+2*sin(3*x) ).graph(-5,5)
	pspict.axes.single_axeY.axes_unit=AxesUnit(2.34,"\\sigma")
	pspict.axes.single_axeY.Dx=0.5

	pspict.DrawGraphs(f)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigAxesSixPICTAxesSix-for_eps.png
from phystricks import *

def AxesFive():
	pspict,fig = SinglePicture("AxesFive")

	x=var('x')
	epsilon=0.1
	f=phyFunction( ln(x) ).graph(epsilon,2*e)
	pspict.axes.single_axeX.axes_unit=AxesUnit(e,"e")
	pspict.axes.single_axeX.Dx=1

	pspict.DrawGraphs(f)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigAxesFivePICTAxesFive-for_eps.png
from phystricks import *

def AxesFourth():
	pspict,fig = SinglePicture("AxesFourth")

	x=var('x')
	f=phyFunction( cos(x) ).graph(-2*pi,2*pi)
	pspict.axes.single_axeX.axes_unit=AxesUnit(pi,"\\pi")
	pspict.axes.single_axeX.Dx=0.5

	pspict.DrawGraphs(f)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigAxesFourthPICTAxesFourth-for_eps.png
from phystricks import *
def MarkOnPoint():
	pspict,fig = SinglePicture("MarkOnPoint")

	P = Point(0,0)
	P.parameters.color = "blue"
	P.put_mark(0.3,180,r"$f_i$")

	Q = Point(1,1)
	Q.put_mark(0.3,0,"$q$")
	Q.parameters.symbol = "diamond"

	pspict.DrawGraphs(P,Q)
	pspict.DrawGraph(P.mark.bounding_box(pspict))

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigMarkOnPointPICTMarkOnPoint-for_eps.png
from phystricks import *
def Sequence():
	pspict,fig = SinglePicture("Sequence")

	nmax = 10
	P = []
	for i in range(1,nmax):
		x = i
		y = ((-1)**i)/float(i)
		P = Point(x,y)
		P.put_mark(0.3,90*(-1)**i,"$P_{%s}$"%(str(i)))
		pspict.DrawGraph(P)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigSequencePICTSequence-for_eps.png
from phystricks import *
def Lines():
	pspict,fig = SinglePicture("Lines")

	A = Point(1,1)
	B = Point(5,2)
	C = Point(2,5)
	A.put_mark(0.3,180,"$A$")
	B.put_mark(0.3,0,"$B$")
	C.put_mark(0.3,180,"$C$")
	pspict.DrawGraph(A)
	pspict.DrawGraph(B)
	pspict.DrawGraph(C)
	segment1 = Segment(A,B)
	segment2 = Segment(C,Point(3,-1))

	pspict.DrawGraph(segment1)

	segment2.parameters.color = "red"
	segment2.parameters.style = "dotted"
	pspict.DrawGraph(segment2)

	P = Intersection(segment1,segment2)[0]
	P.put_mark(0.3,-45,"$P$")

	segment3 = Segment(A,C)
	S3 = segment3.graph()
	S4 = segment3.graph()
	S3.wave(0.2,0.1)
	S3.parameters.color = "cyan"
	S4.parameters.color = "blue"
	pspict.DrawGraph(S3)
	pspict.DrawGraph(S4)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigLinesPICTLines-for_eps.png
# -*- coding: utf8 -*-
from phystricks import *
def cube():
	pspict,fig = SinglePicture("cube")

	P=Point(-1,1)
	Q=Point(0,0)
	rect=Rectangle(P,Q)
	pspict.DrawGraph(rect)

	b1=Segment(rect.center(),rect.SW).proportion(1.5)
	b2=Segment(rect.center(),rect.SE).proportion(1.5)
	S1=Segment(rect.center(),b1)
	S2=Segment(rect.center(),b2)
	B=Segment(b1,b2)
	B.parameters.color="red"
	S1.parameters.color="red"
	S2.parameters.color="red"
	pspict.DrawGraph(B)
	pspict.DrawGraph(S1)
	pspict.DrawGraph(S2)

	C=rect.center()
	C.put_mark(0.3,135,"C")
	pspict.DrawGraph(C)

	cne=Segment(rect.center(),rect.NE)
	x1=rect.NE
	x2=b2.translate(AffineVector(cne.I,cne.F))
	X=Segment(x1,x2)
	pspict.DrawGraph(X)

	l1=Segment(rect.center(),x1)
	l2=Segment(b2,x2)
	l1.parameters.style="dotted"
	l2.parameters.style="dotted"
	l1.parameters.color="blue"
	l2.parameters.color="blue"
	pspict.DrawGraph(l1)
	pspict.DrawGraph(l2)

	measureX = MeasureLength(X,-0.1)
	measureX.parameters.color="green"
	measureX.put_mark(0.3,measureX.advised_mark_angle,"$X$")
	pspict.DrawGraph(measureX)
	measureB = MeasureLength(B,0.1)
	measureB.parameters.color="green"
	measureB.put_mark(0.3,measureB.advised_mark_angle,"$B$")
	pspict.DrawGraph(measureB)

	pspict.dilatation(3)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigcubePICTcube-for_eps.png
from phystricks import *
def GestionRepere():
	pspict,fig = SinglePicture("GestionRepere")

	P = Point(-2,-2)
	Q = Point(5,5)
	P.parameters.symbol = "none"
	Q.parameters.symbol = "none"

	pspict.DrawGraph(P)
	pspict.DrawGraph(Q)

	pspict.grid.num_subX = 0
	pspict.grid.num_subY = 0
	pspict.grid.main_vertical.parameters.style = "dotted"
	pspict.grid.main_horizontal.parameters.style = "dotted"

	pspict.axes.no_graduation()

	pspict.DrawDefaultAxes()
	pspict.DrawDefaultGrid()

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigGestionReperePICTGestionRepere-for_eps.png
from phystricks import *
def ParametricOne():
	pspict,fig = SinglePicture("ParametricOne")

	var('x')
	f1 = phyFunction( 3*cos(x) )
	f2 = phyFunction( 2.3*cos(4.7*x))
	curve = ParametricCurve(f1,f2)
	G = curve.graph(0,5)
	G.parameters.style = "dashed"
	pspict.DrawGraph(G)

	pspict.DrawDefaultAxes()

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigParametricOnePICTParametricOne-for_eps.png
from phystricks import *
def ParametricTwo():
	pspict,fig = SinglePicture("ParametricTwo")

	var('x')
	f1 = phyFunction( x*sin(x) )
	f2 = phyFunction( x )
	f3 = phyFunction( x*cos(x) )

	llI = 0
	llF = 5
	wl = 0.1
	amplitude = 0.1
	curve1 = ParametricCurve(f1,f2)
	F1=curve1.graph(llI,llF)
	G1=curve1.graph(llI,llF)
	curve2 = ParametricCurve(f1,f3)
	F2=curve2.graph(llI,llF)

	F1.parameters.color = "brown"
	G1.parameters.color = "magenta"
	G1.wave(wl,amplitude)

	for ll in curve2.get_regular_parameter(llI,llF,2):
		v1 = curve2.get_tangent_vector(ll)
		v2 = curve2.get_normal_vector(ll)
		pspict.DrawGraphs(v1,v2)

	pspict.DrawGraphs(F1,G1,F2)
	pspict.DrawDefaultAxes()
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigParametricTwoPICTParametricTwo-for_eps.png
from phystricks import *
def FunctionFirst():
	pspict,fig = SinglePicture("FunctionFirst")

	var('x')
	f = phyFunction( sin(x) )
	mx = -2*pi
	Mx = 2*pi
	F =f.graph(mx,Mx)
	pspict.DrawGraph(F)

	pspict.DrawDefaultAxes()

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigFunctionFirstPICTFunctionFirst-for_eps.png
from phystricks import *
def FunctionSecond():
	pspict,fig = SinglePicture("FunctionSecond")

	var('x')
	f = phyFunction( log(x) )
	mx = 0.1
	Mx = 10
	F = f.graph(mx,Mx)
	G = f.graph(mx,Mx)
	F.parameters.color = "red"
	F.wave(0.3,0.1)
	F.parameters.style = "dashed"
	pspict.DrawGraph(F)
	pspict.DrawGraph(G)

	pspict.DrawDefaultAxes()

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigFunctionSecondPICTFunctionSecond-for_eps.png
from phystricks import *
def FunctionThird():
	pspict,fig = SinglePicture("FunctionThird")

	var('x')
	f = phyFunction( x*cos(x) )
	mx = -5
	Mx = 5
	F = f.graph(mx,Mx)
	G = f.derivative().graph(mx,Mx)
	G.parameters.color = "red"
	pspict.DrawGraph(F)
	pspict.DrawGraph(G)

	pspict.DrawDefaultAxes()
	pspict.dilatation(0.7)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigFunctionThirdPICTFunctionThird-for_eps.png
from phystricks import *
def FunctionFour():
	pspict,fig = SinglePicture("FunctionFour")

	var('x')
	f = phyFunction( x*sin(x) )
	mx = -5
	Mx = 5
	F = f.graph(mx,Mx)
	points = []
	for i in range(mx,Mx) :
		points.append(f.get_point(i))

	pspict.DrawGraph(F)
	for i in range(0,len(points)):
		points[i].put_mark(0.3,points[i].advised_mark_angle,"$P_{%s}$"%str(i))
		pspict.DrawGraph(points[i])

	pspict.DrawDefaultAxes()

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigFunctionFourPICTFunctionFour-for_eps.png
from phystricks import *
def FunctionFive():
	pspict,fig = SinglePicture("FunctionFive")

	var('x')
	f = phyFunction( x*sin(x) )
	mx = -5
	Mx = 5
	F = f.graph(mx,Mx)

	points = f.get_regular_points(mx,Mx,1.5)

	pspict.DrawGraph(F)
	for i in range(0,len(points)):
		P = points[i]
		P.put_mark(0.3,P.advised_mark_angle,"$P_{%s}$"%str(i))
		pspict.DrawGraph(P)

	pspict.DrawDefaultAxes()
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigFunctionFivePICTFunctionFive-for_eps.png
from phystricks import *
def Axes():
	pspict,fig = SinglePicture("Axes")

	P = Point(-4,-2)
	L = Segment( Point(0,0),Point(1.6,3) )

	P.put_mark(0.3,135,"$P$")
	pspict.DrawGraph(P)
	L.parameters.color = "brown"
	pspict.DrawGraph(L)

	pspict.DrawDefaultAxes()

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigAxesPICTAxes-for_eps.png
from phystricks import *
def AxesSecond():
	pspict,fig = SinglePicture("AxesSecond")

	for i in range(-10,10):
		x = float(i)/5
		P=Point(2*x,sinh(x))
		P.parameters.symbol="*"
		pspict.DrawGraph(P)

	pspict.axes.no_graduation()
	pspict.axes.single_axeX.put_mark(0.3,-45,"$x$")
	pspict.axes.single_axeY.put_mark(1.3,0,"$y=\sinh(x)$")

	pspict.DrawDefaultAxes()

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigAxesSecondPICTAxesSecond-for_eps.png
from phystricks import *
def VectorOne():
	pspict,fig = SinglePicture("VectorOne")

	O = Point(0,0)
	A = Point(1,1)
	B = Point(-4,-1)
	C = Point(-2,3)

	V = []
	V.append(AffineVector(O,A).fix_size(3))
	V.append(AffineVector(A,C))
	V.append(AffineVector(B,C))
	V.append( V[1].rotation(30).dilatation(0.5) )
	V.append( V[1].rotation(-30) )
	V.append( V[1].orthogonal() )


	V[1].put_mark(0.3,45,"$v$")
	V[1].parameters.color="brown"
	V[2].parameters.color="red"
	V[2].parameters.style = "dotted"
	V[3].parameters.color="blue"
	V[4].parameters.style = "dashed"
	V[4].parameters.color=V[1].parameters.color
	V[5].parameters.color=V[1].parameters.color

	for i in range(0,len(V)):
		pspict.DrawGraph(V[i])

	pspict.DrawDefaultAxes()

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigVectorOnePICTVectorOne-for_eps.png
from phystricks import *
def exCircleThree():
	pspict,fig = SinglePicture("exCircleThree")

	circle = Circle(Point(0,0),1.5)
	C = circle.graph(45,360)
	C.wave(0.1,0.1)
	C.color = "green"
	D = circle.graph(C.angleF.degree-360,C.angleI)
	D.wave(C.waviness.dx,C.waviness.dy)
	D.color = "red"

	pspict.DrawGraph(C)
	pspict.DrawGraph(D)
	pspict.DrawDefaultAxes()

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigexCircleThreePICTexCircleThree-for_eps.png
from phystricks import *
def exCircleTwo():
	pspict,fig = SinglePicture("exCircleTwo")

	C = Circle(Point(0,0),1.5)
	C.style = "dotted"
	C.angleI = 20
	C.angleF = 100

	for angle in [10,30,75,130,300,350] :
		P = C.get_point(angle)
		P.put_mark(0.5,angle,"$P_{%s}$"%str(angle))
		pspict.DrawGraph(P)

	pspict.DrawGraph(C)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigexCircleTwoPICTexCircleTwo-for_eps.png
from phystricks import *
def exCircle():
	pspict,fig = SinglePicture("exCircle")

	C = Circle(Point(1,1),2)
	C.parameters.color = "magenta"

	pspict.DrawGraph(C)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigexCirclePICTexCircle-for_eps.png
from phystricks import *
def Graphn():
    def n(u,v):
        var('x')
        fi = u*sin(2*x)-v*cos(2*x)+v
        return fi

    pspict,fig = SinglePicture("Graphn")

    var('u,v,x')

    f1 = phyFunction( n(1,1) )
    f2 = phyFunction( n(0,1) )

    mx = 0
    Mx = mx+2*math.pi

    F1 = f1.graph(mx,Mx)
    F2 = f2.graph(mx,Mx)
    F1.parameters.color="red"
    F2.parameters.color="blue"
    pspict.DrawGraph(F1)
    pspict.DrawGraph(F2)

    pspict.axes.single_axeX.axes_unit=AxesUnit(pi,"\\pi")
    pspict.axes.single_axeX.Dx=0.5
    pspict.DrawDefaultAxes()

    pspict.dilatation(1)

    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigGraphnPICTGraphn-for_eps.png
from phystricks import *
def CercleK():
	pspict,fig = SinglePicture("CercleK")

	var('x')
	f = phyFunction(sqrt(1-x**2))
	g = phyFunction(-sqrt(1-x**2))

	dx = 0.1
	dy = 0.05
	eps = 0.001

	F1 = f.graph(0+eps,1-eps)
	F2 = f.graph(-1+eps,0-eps)
	G1 = g.graph(0+eps,1-eps)
	G2 = g.graph(-1+eps,0-eps)

	F1.parameters.color = "black"
	F2.parameters.color = "green"
	G1.parameters.color = F2.parameters.color
	G2.parameters.color = F1.parameters.color
	F1.wave(dx,dy)
	F2.wave(dx,dy)
	G1.wave(dx,dy)
	G2.wave(dx,dy)

	pspict.DrawGraph(F1)
	pspict.DrawGraph(F2)
	pspict.DrawGraph(G1)
	pspict.DrawGraph(G2)

	A = Point(1,0)
	B = Point(-1,0)
	C = Point(0,1)
	D = Point(0,-1)

	A.parameters.color = "red"
	B.parameters.color = A.parameters.color
	C.parameters.color = "brown"
	D.parameters.color = C.parameters.color
	A.add_option("dotscale=1.3")
	B.add_option("dotscale=1.3")
	C.add_option("dotscale=1.3")
	D.add_option("dotscale=1.3")

	pspict.DrawGraph(A)
	pspict.DrawGraph(B)
	pspict.DrawGraph(C)
	pspict.DrawGraph(D)

	pspict.axes.no_graduation()
	pspict.axes.single_axeX.put_mark(0.3,-45,"$K_H$")
	pspict.DrawDefaultAxes()

	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigCercleKPICTCercleK-for_eps.png
from phystricks import *
def GeodExistence():
	pspict,fig = SinglePicture("GeodExistence")

	var('x')
	f = phyFunction( -(x+2)**2/3+3 )
	mx = -5
	Mx = -2
	F = f.graph(mx,Mx)

	ptO = f.get_point(mx+1)
	ptB = f.get_point(Mx)
	ptP = f.get_point(-4.5)
	V = AffineVector(ptP,Point(ptP.x+2,ptP.y+0.25))

	ptO.parameters.color = "blue"
	ptO.put_mark(0.8,0,"$o=[\mtu]$")
	ptB.parameters.symbol = "none"
	ptB.put_mark(0.7,0,"$[\SO(2)]$")
	#pspict.DrawBoundingBox(B)
	ptP.parameters.color = "blue"
	ptP.parameters.symbol = "none"
	ptP.put_mark(0.7,135,"$[ e^{xq_0}]$")
	
	pspict.DrawGraph(F)
	# See phystricks.PspictureToOtherOutputs.specific_needs
	pspict.specific_needs="\usepackage{bbm}\n  \usepackage{latexsym}\n\usepackage{amsfonts}\n\usepackage[reqno]{amsmath}\n\usepackage{amsthm}\n\usepackage{amssymb}\n\usepackage{amssymb}\n  \\newcommand{\mtu}{\mathbbm{1}}\n \DeclareMathOperator{\SO}{SO}"

	pspict.DrawGraph(ptO)
	pspict.DrawGraph(ptB)

	V.parameters.color = "cyan"
	V.parameters.symbol="none"
	V.put_mark(0.5,-45,"$[ e^{sE(w)} e^{xq_0}]$")

	pspict.DrawGraph(V)
	pspict.DrawGraph(ptP)		# Drawn after by purpose.
	#pspict.TraceBB()

	pspict.dilatation_Y(2)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigGeodExistencePICTGeodExistence-for_eps.png
from phystricks import *
def FilledCircle():
	pspict,fig = SinglePicture("FilledCircle")
	
	C=Circle(Point(0,0),1)
	C.parameters.filled()
	C.parameters.fill.color="yellow"
	C.parameters.color="blue"

	D=Circle(Point(2,0),1)
	D.parameters.hatched()
	D.parameters.hatch.angle=0
	D.parameters.hatch.color="green"

	E=Circle(Point(4,0),1)
	E.add_option("fillstyle=solid")
	E.add_option("fillcolor=green")
	E.parameters.color="red"

	pspict.DrawGraph(C)
	pspict.DrawGraph(D)
	pspict.DrawGraph(E)

	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigFilledCirclePICTFilledCircle-for_eps.png
from phystricks import *
def SurfaceFunction():
	pspict,fig = SinglePicture("SurfaceFunction")

	var('x')
	f=2*sin(x)
	a=0.5
	b=pi/2
	surf1=SurfaceUnderFunction(f,a,b)
	surf1.parameters.color="blue"

	fun = phyFunction(f).graph(3*pi/4,2*pi+0.5)
	surf2=fun.surface_under()

	pspict.DrawGraphs(surf1,surf2)

	pspict.DrawDefaultAxes()
	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigSurfaceFunctionPICTSurfaceFunction-for_eps.png
from phystricks import *
def RectangleOne():
	pspict,fig = SinglePicture("RectangleOne")

	rect=Rectangle( Point(1,1),Point(2,3) )
	rect.parameters.hatched()
	rect.parameters.hatch.color="red"
	rect.parameters.style="dotted"
	rect.parameters.color="blue"

	pspict.DrawGraphs(rect)

	pspict.DrawDefaultAxes()
	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigRectangleOnePICTRectangleOne-for_eps.png
from phystricks import *
def exCustomSurface():
	pspict,fig = SinglePicture("exCustomSurface")

	var('x')
	f1=sin(x)
	f2=x
	mt=0
	Mt=3*pi/2
	mx=0
	Mx=3
	v1=ParametricCurve(f1,f2).graph(mt,Mt)
	v2=phyFunction((x/2)**2).graph(mx,Mx)
	A=v1.get_point(mt)
	B=v1.get_point(Mt)
	C=v2.get_point(Mx)
	sh=Segment(B,C)

	surf=CustomSurface(v1,sh,v2)
	surf.parameters.filled()
	surf.parameters.fill.color="red"

	pspict.DrawGraphs(surf)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigexCustomSurfacePICTexCustomSurface-for_eps.png
from phystricks import *
def TangentSegment():
	pspict,fig = SinglePicture("TangentSegment")

	var('x')
	f=phyFunction(2*sin(x/2)).graph(-pi,2*pi+1)
	pspict.DrawGraphs(f)
	for x0 in [-pi/2,pi] :
		P=f.get_point(x0)
		seg=f.get_tangent_segment(x0)
		seg=seg.dilatation(2)
		pspict.DrawGraphs(seg,P)

	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigTangentSegmentPICTTangentSegment-for_eps.png
from phystricks import *
def AxesThird():
	pspict,fig = SinglePicture("AxesThird")

	var('x')
	f=phyFunction(x*sin(1/x)).graph(-1,1)
	f.plotpoints=1000

	pspict.DrawGraphs(f)

	pspict.axes.Dx=0.5
	pspict.axes.Dy=0.3
	pspict.DrawDefaultAxes()
	pspict.dilatation(3)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigAxesThirdPICTAxesThird-for_eps.png
from phystricks import *
def MorePoints():
	fig = GenericFigure("MorePoints")

	var('x')
	a=0.2
	f=phyFunction(x*sin(1/x)).graph(-a,a)

	dil=8
	Dx=0.2
	Dy=0.1
	ssfig1 = fig.new_subfigure("Not enough points.","LabelMorePointsA")
	pspict1 = ssfig1.new_pspicture("NotEnough")
	pspict1.DrawGraph(f)
	pspict1.axes.Dx=Dx
	pspict1.axes.Dy=Dy
	pspict1.DrawDefaultAxes()
	pspict1.dilatation(dil)

	ssfig2 = fig.new_subfigure("Enough","LabelMorePointsB")
	pspict2 = ssfig2.new_pspicture("Enough")
	f.plotpoints=3000
	pspict2.DrawGraph(f)
	pspict2.axes.Dx=Dx
	pspict2.axes.Dy=Dy
	pspict2.DrawDefaultAxes()
	pspict2.dilatation(dil)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigMorePointsssLabelMorePointsAPICTNotEnough-for_eps.png _images/Picture_FIGLabelFigMorePointsssLabelMorePointsBPICTEnough-for_eps.png
# -*- coding: utf8 -*-
from phystricks import *
def SuiteUnSurn():
	pspict,fig = SinglePicture("SuiteUnSurn")

	def suite(i):
		return SR(1)/i

	n=10
	for i in range(1,n+1):
		y=suite(i)
		P=Point(i,float(y))
		P.put_mark(0.3,90,"$%s$"%(repr(y)))
		pspict.DrawGraph(P)

	pspict.axes.no_graduation()
	pspict.DrawDefaultAxes()

	pspict.dilatation_Y(3)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigSuiteUnSurnPICTSuiteUnSurn-for_eps.png
# -*- coding: utf8 -*-
from phystricks import *
def SpiraleLimite():
	pspict,fig = SinglePicture("SpiraleLimite")

	x=var('x')
	curve=PolarCurve(x,arccos(x**3)/2).graph(0,1)

	pspict.axes.Dx=0.1
	pspict.axes.Dy=0.1
	pspict.axes.no_numbering()
	pspict.DrawGraphs(curve)
	pspict.DrawDefaultAxes()
	pspict.dilatation(3)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigSpiraleLimitePICTSpiraleLimite-for_eps.png
# -*- coding: utf8 -*-
from phystricks import *
def IntTrois():
	fig = GenericFigure("IntTrois")

	O=Point(0,0)
	C=Circle(O,1)
	arc=C.parametric_curve(0,pi/2)
	arc.parameters.color="red"
	h=Segment(Point(0,1),Point(1,1))
	v=Segment(Point(1,1),Point(1,0))
	h.parameters.color=arc.parameters.color
	v.parameters=h.parameters

	P=C.get_point(30)
	Q=Point(P.x,1)
	seg=Segment(P,Q)
	surf=CustomSurface(arc,h,v)
	surf.parameters.filled()
	surf.parameters.fill.color="lightgray"

	ss_fig1=fig.new_subfigure(u"Intégrer en cartésiennes.","LabelMauvais")
	pspict1=ss_fig1.new_pspicture("mauvais")
	pspict1.DrawGraphs(surf,arc,seg,h,v,P,Q)

	pspict1.DrawDefaultAxes()
	pspict1.dilatation(2)

	ss_fig2=fig.new_subfigure("Notice the automatic computation of the intersection between the lines and the circle.","LabelBon")
	pspict2=ss_fig2.new_pspicture("Bon")
	A=C.get_point(35)
	pC=C.get_point(55)
	B =Intersection(Segment(O,A),v)[0]
	D =Intersection(Segment(O,pC),h)[0]
	s1=Segment(A,B)
	s2=Segment(pC,D)
	t1=Segment(O,A)
	t2=Segment(O,pC)
	t1.parameters.style="dotted"
	t2.parameters=t1.parameters
	pspict2.DrawGraphs(t1,t2,surf,h,v,arc,s1,A,B,pC,D,s2)
	pspict2.DrawDefaultAxes()
	pspict2.dilatation(2)
	
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigIntTroisssLabelBonPICTBon-for_eps.png _images/Picture_FIGLabelFigIntTroisssLabelMauvaisPICTmauvais-for_eps.png
from phystricks import *
def CornetGlace():
	pspict,fig = SinglePicture("CornetGlace")

	l=1.2
	x=var('x')
	f1=phyFunction(sqrt(1-x**2)).graph(-1,1)
	f2a=phyFunction(-x).graph(-l,0)
	f2b=phyFunction(x).graph(0,l)
	P = Intersection(f1,f2a)[0]
	Q = Intersection(f1,f2b)[0]
	c1=f1.graph(P.x,Q.x)
	c2a=f2a.graph(0,P.x)
	c2b=f2b.graph(0,Q.x)
	surf=CustomSurface(c2a,c1,c2b)
	surf.parameters.hatched()
	surf.parameters.hatch.color="lightgray"

	pspict.DrawGraphs(surf,f1,f2a,f2b)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigCornetGlacePICTCornetGlace-for_eps.png
from phystricks import *
def Differentielle():
	pspict,fig = SinglePicture("Differentielle")

	var('x')
	a=2
	x0=4
	mx=1
	Mx=x0+0.2
	f=phyFunction(2*log(x/2)+2).graph(mx,Mx)
	tangente=f.tangent_phyFunction(a).graph(mx,Mx)
	A=f.get_point(a)
	C=f.get_point(x0)
	B=Point(x0,A.y)
	D=tangente.get_point(x0)
	Ab=Point(A.x,0)
	Bb=Point(B.x,0)
	AB=Segment(A,B)
	BD=Segment(B,D)
	measureEps=MeasureLength(Segment(C,D),0.3)
	measureEps.put_mark(0.5,measureEps.advised_mark_angle,"$\epsilon(h)$")
	measureT=MeasureLength(Segment(B,D),1.5)
	measureT.put_mark(0.5,measureT.advised_mark_angle,"$T(h)$")

	AAb=Segment(A,Ab)
	ABb=Segment(B,Bb)
	measureAX=MeasureLength( Segment(A,B),0.5 )
	measureAX.put_mark(0.3,measureAX.advised_mark_angle,"$h$")

	Ab.put_mark(0.3,-90,"$a$")
	Bb.put_mark(0.3,-90,"$x$")
	A.put_mark(0.5,A.advised_mark_angle,"$f(a)$")
	C.put_mark(0.7,-45,"$f(x)$")
	tangente.parameters.color="red"
	AB.parameters.style="dotted"
	BD.parameters.style=AB.parameters.style
	AAb.parameters.style=AB.parameters.style
	ABb.parameters.style=AB.parameters.style

	pspict.DrawGraphs(AB,BD,tangente,f,measureEps,measureT)
	pspict.DrawGraphs(measureAX,A,B,C,D,Ab,Bb,AAb,ABb)
	pspict.axes.no_graduation()
	pspict.DrawDefaultAxes()

	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigDifferentiellePICTDifferentielle-for_eps.png
from phystricks import *
def CSCiv():
	pspict,fig = SinglePicture("CSCiv")

	var('x')
	f=(x-1)/(x+1)
	epsilon=0.5
	Mtheta=-50
	curve1=PolarCurve(f).graph(1,50)
	curve2=PolarCurve(f).graph(Mtheta,-1-epsilon)
	curve2.parameters.color="brown"

	pspict.DrawGraphs(curve1,curve2)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigCSCivPICTCSCiv-for_eps.png
from phystricks import *

def CSCvi():
	fig = GenericFigure("SubfiguresCSCvi")

	ssfig1 = fig.new_subfigure(r"Le graphique de $r(\theta)$","CSCviGr")
	pspict1 = ssfig1.new_pspicture("CSCviGraphe")

	var('x')
	epsilon=0.4
	limite=-pi/2
	llam=limite+epsilon
	Llam=pi/2
	r=phyFunction(cos(x)/(1+sin(x)))

	graphe=r.graph(llam,Llam)

	P=Point(limite,0)
	Q=Point(limite,graphe.bounding_box().N().y)
	assymp=Segment(P,Q)
	assymp.parameters.color="lightgray"
	assymp.parameters.style="dashed"
	pspict1.DrawGraphs(graphe,assymp)

	pspict1.DrawDefaultAxes()
	pspict1.dilatation(1)

	ssfig2 = fig.new_subfigure("La courbe polaire correspondante","CSCviCourbe")
	pspict2 = ssfig2.new_pspicture("CSCviCourbe")

	curve=PolarCurve(r).graph(llam,Llam)
	pspict2.DrawGraphs(curve)

	pspict2.DrawDefaultAxes()
	pspict2.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigSubfiguresCSCvissCSCviCourbePICTCSCviCourbe-for_eps.png _images/Picture_FIGLabelFigSubfiguresCSCvissCSCviGrPICTCSCviGraphe-for_eps.png
from phystricks import *
def CSCii():
	pspict,fig = SinglePicture("CSCii")

	var('x')
	f=sin(2*x)
	curve=PolarCurve(f).graph(0,pi/2)
	P=Point(1,1)
	Q=Point(1,0)
	R=Point(0,1)
	l1=Segment(P,Q)
	l2=Segment(P,R)
	l1.parameters.color="lightgray"
	l2.parameters=l1.parameters

	pspict.DrawGraphs(curve,l1,l2,P)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigCSCiiPICTCSCii-for_eps.png
from phystricks import *
def CSCiii():
	pspict,fig = SinglePicture("CSCiii")

	var('x')
	f=sin(x)/x
	curve=PolarCurve(f).graph(-pi,pi)
	O=Point(0,0)
	C1=Circle(O,1)
	C2=Circle(O,f(x=pi/2))
	C1.parameters.color="lightgray"
	C2.parameters=C1.parameters

	pspict.DrawGraphs(C1,C2,curve)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigCSCiiiPICTCSCiii-for_eps.png
from phystricks import *
def CSCv():
	fig = GenericFigure("SubfiguresCSCv")

	ssfig1 = fig.new_subfigure(r"Le graphique de $r(\theta)$","CSCvGr")
	pspict1 = ssfig1.new_pspicture("CSCvGraphe")

	var('x')
	r=phyFunction(cos(x)-cos(2*x)).graph(0,2*pi)
	pspict1.DrawGraph(r)

	pspict1.DrawDefaultAxes()
	pspict1.dilatation(1)

	ssfig2 = fig.new_subfigure("La courbe polaire correspondante","CSCvCourbe")
	pspict2 = ssfig2.new_pspicture("CSCvCourbe")

	curve1=PolarCurve(r).graph(0,2*pi/3)
	curve2=PolarCurve(r).graph(4*pi/3,2*pi)
	pspict2.DrawGraphs(curve1,curve2)

	pspict2.DrawDefaultAxes()
	pspict2.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigSubfiguresCSCvssCSCvCourbePICTCSCvCourbe-for_eps.png _images/Picture_FIGLabelFigSubfiguresCSCvssCSCvGrPICTCSCvGraphe-for_eps.png
from phystricks import *
def Cardioideexo():
	pspict,fig = SinglePicture("Cardioideexo")

	x=var('x')
	f=phyFunction(1+cos(x))
	curve=PolarCurve(f).graph(0,2*pi)

	P=Point(1,1)
	O=Point(0,0)
	Q=curve.get_point(pi/4)
	rect=Rectangle(O,P)
	rect.parameters.color="lightgray"

	C1=Circle(O,1)
	C2=Circle(O,2)
	C1.parameters.color="lightgray"
	C2.parameters=C1.parameters

	seg=Segment(O,Q)
	seg.parameters.style="dashed"
	seg.parameters.color=rect.parameters.color

	pspict.DrawGraphs(C1,C2,curve,rect,seg,P,Q)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigCardioideexoPICTCardioideexo-for_eps.png
from phystricks import *
def DistanceEuclide():
	pspict,fig=SinglePicture("DistanceEuclide")

	A=Point(1,4)
	B=Point(3,1)
	C=Point(B.x,A.y)
	A.put_mark(0.4,90,"$(A_x,A_y)$")
	B.put_mark(1,0,"$(B_x,B_y)$")
	C.put_mark(0.4,45,"$C$")
	pspict.DrawGraph(A)
	pspict.DrawGraph(B)
	pspict.DrawGraph(C)

	Lab=Segment(A,B)
	Lac=Segment(A,C)
	Lbc=Segment(B,C)
	pspict.DrawGraph(Lab)
	pspict.DrawGraph(Lac)
	pspict.DrawGraph(Lbc)

	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigDistanceEuclidePICTDistanceEuclide-for_eps.png
# -*- coding: utf8 -*-
from phystricks import *
def LesSpheres():
	fig = GenericFigure("LesSpheres")

	ssfigN1 = fig.new_subfigure(u"La sphère unité pour la norme $\| . \|_1$","LabelssFigN1")
	ssfigN2 = fig.new_subfigure(u"La sphère unité pour la norme $\| . \|_2$","LabelssFigN2")
	ssfigNinfini = fig.new_subfigure(u"La sphère unité pour la norme $\| . \|_{\infty}$","LabelssFigNinfini")
	pspict1 = ssfigN1.new_pspicture("Sphere1")
	pspict2 = ssfigN2.new_pspicture("Sphere2")
	pspictinfini = ssfigNinfini.new_pspicture("Sphereinfini")

	r=1
	# La norme |  |_1
	A=Point(0,r)
	B=Point(-r,0)
	C=Point(0,-r)
	D=Point(r,0)
	AB=Segment(A,B)
	BC=Segment(B,C)
	CD=Segment(C,D)
	DA=Segment(D,A)
	pspict1.DrawGraphs(AB,BC,CD,DA)
	pspict1.BB.AddX(-r-1)
	pspict1.BB.AddX(r+1)
	pspict1.DrawDefaultAxes()
	pspict1.dilatation(1)

	# La norme |  |_2
	O=Point(0,0)
	Cercle = Circle(O,r)
	pspict2.DrawGraph(Cercle)
	pspict2.BB.AddX(-r-1)
	pspict2.BB.AddX(r+1)
	pspict2.DrawDefaultAxes()
	pspict2.dilatation(1)

	# La norme |  |_infini
	A=Point(r,r)
	B=Point(-r,r)
	C=Point(-r,-r)
	D=Point(r,-r)
	AB=Segment(A,B)
	BC=Segment(B,C)
	CD=Segment(C,D)
	DA=Segment(D,A)
	pspictinfini.DrawGraph(AB)
	pspictinfini.DrawGraph(BC)
	pspictinfini.DrawGraph(CD)
	pspictinfini.DrawGraph(DA)
	pspictinfini.BB.AddX(-r-1)
	pspictinfini.BB.AddX(r+1)
	pspictinfini.DrawDefaultAxes()
	pspictinfini.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigLesSpheresssLabelssFigN1PICTSphere1-for_eps.png _images/Picture_FIGLabelFigLesSpheresssLabelssFigN2PICTSphere2-for_eps.png _images/Picture_FIGLabelFigLesSpheresssLabelssFigNinfiniPICTSphereinfini-for_eps.png
from phystricks import *
def DistanceEnsemble():
	pspict,fig = SinglePicture("DistanceEnsemble")

	C=Point(0,0)
	Cercle=Circle(C,1)
	A=Cercle.get_point(45)
	A.put_mark(0.3,45,"$A$")
	A.parameters.symbol="none"
	pspict.DrawGraph(A)
	P=Cercle.get_point(210)
	Q=Cercle.get_point(100)
	P.put_mark(0.5,-90,"$p$")
	R=Circle(C,0.7).get_point(-90)
	v=AffineVector(C,P)
	X=(v*2.3).F
	X.put_mark(0.3,180,"$x$")

	xP=Segment(X,P)
	xQ=Segment(X,Q)
	xR=Segment(X,R)
	xQ.parameters.style="dotted"
	xR.parameters.style="dotted"
	pspict.DrawGraph(xP)
	pspict.DrawGraph(xQ)
	pspict.DrawGraph(xR)

	pspict.DrawGraph(Cercle)
	pspict.DrawGraph(P)
	pspict.DrawGraph(R)
	pspict.DrawGraph(Q)
	pspict.DrawGraph(X)

	pspict.dilatation(2)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigDistanceEnsemblePICTDistanceEnsemble-for_eps.png
from phystricks import *
def AccumulationIsole():
	pspict,fig = SinglePicture("AccumulationIsole")

	O=Point(0,0)
	Boule=Circle(O,1)
	Boule.parameters.color="red"
	Boule.parameters.hatched()

	P=Point(1,1)
	P.put_mark(0.4,0,"$P$")
	Q=Point(-1,0)
	Q.parameters.color="red"
	Q.put_mark(0.4,180,"$Q$")

	CercleP=Circle(P,0.2)
	CercleP.parameters.color="green"
	CercleQ=Circle(Q,0.2)
	CercleQ.parameters.color="green"
	
	pspict.DrawGraphs(Boule,P,Q,CercleP,CercleQ)
	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigAccumulationIsolePICTAccumulationIsole-for_eps.png
from phystricks import *
def MethodeChemin():
	pspict,fig = SinglePicture("MethodeChemin")

	A=Point(-1,1)
	B=Point(1,-1)
	C=Point(-1,-0.5)
	D=Point(1,0.5)
	A.put_mark(0.3,90,"$y=-x$")
	D.put_mark(0.3,45,"$y=x/2$")
	A.parameters.symbol="none"
	D.parameters.symbol="none"
	S1=Segment(A,B)
	S2=Segment(C,D)
	S1.parameters.color="red"
	S2.parameters.color="blue"
	S1.parameters.style="dashed"
	S2.parameters.style=S1.parameters.style

	pspict.DrawGraphs(S1,S2,A,D)

	pspict.axes.no_graduation()
	pspict.DrawDefaultAxes()

	pspict.dilatation(1.5)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigMethodeCheminPICTMethodeChemin-for_eps.png
from phystricks import *
def ExempleArcParam():
	fig = GenericFigure("ExempleArcParam")

	ssfigN1 = fig.new_subfigure("$\gamma(t)=(2\sin(t),t)$, avec $0\leq t\leq 2\pi$","LabelArcUn")
	ssfigN2 = fig.new_subfigure("$\gamma(t)=(sin(2t),sin(t))$ avec $-\pi\leq t\leq \pi$","LabelArcDeux")
	pspict1 = ssfigN1.new_pspicture("gammasintti")
	pspict2 = ssfigN2.new_pspicture("gammasindyttii")

	var('x')
	f1=2*sin(x)
	f2=x
	Mcurve1 = ParametricCurve(f1,f2)
	curve1 = Mcurve1.graph(0,2*pi)
	pspict1.DrawGraphs(curve1)
	pspict1.DrawDefaultAxes()

	pspict1.dilatation(0.7)

	g1=sin(2*x)
	g2=sin(x)
	curve2=ParametricCurve(g1,g2).graph(-pi,pi)
	pspict2.DrawGraphs(curve2)
	pspict2.DrawDefaultAxes()
	pspict2.dilatation(1.5)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigExempleArcParamssLabelArcDeuxPICTgammasindyttii-for_eps.png _images/Picture_FIGLabelFigExempleArcParamssLabelArcUnPICTgammasintti-for_eps.png
from phystricks import *
def CourbeRectifiable():
	pspict,fig = SinglePicture("CourbeRectifiable")
	
	var('x')
	f1=-20*cos(x)
	f2=2*sin(2*pi*x)
	n=4		# It makes n+1 points because the first is zero.
	sigma=[float(i)/n  for i in range(n+1)  ]
	points=[]
	curve=ParametricCurve(f1,f2).graph(0,1)
	for i in range(len(sigma)) :
		P = curve.get_point(sigma[i])
		P.put_mark(0.5,P.advised_mark_angle,"$\gamma(t_{%s})$"%str(i))
		points.append(P)

	for i in range(len(points)-1):
		A=points[i]
		B=points[i+1]
		seg=Segment(A,B)
		seg.parameters.color="red"
		pspict.DrawGraph(seg)

	for P in points :
		pspict.DrawGraph(P)

	pspict.DrawGraphs(curve)

	pspict.dilatation(0.7)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigCourbeRectifiablePICTCourbeRectifiable-for_eps.png
from phystricks import *
def SuiteInverseAlterne():

	def suite(i):
		return SR((-1)**i)/i

	pspict,fig = SinglePicture("SuiteInverseAlterne")
	n=10
	for i in range(1,n+1):
		P=Point(i,suite(i))
		P.put_mark(0.3,(-1)**i*90,"$%s$"%(repr(suite(i))))
		pspict.DrawGraph(P)

	pspict.axes.no_graduation()
	pspict.DrawDefaultAxes()

	pspict.dilatation_Y(3)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigSuiteInverseAlternePICTSuiteInverseAlterne-for_eps.png
from phystricks import *
def Cycloide():
    pspict,fig = SinglePicture("Cycloide")

    a=1
    var('x')
    f1=a*(x-sin(x))
    f2=a*(1-cos(x))
    curve=ParametricCurve(f1,f2).graph(0,4*pi)

    pspict.DrawGraph(curve)
    pspict.DrawDefaultAxes()

    pspict.dilatation(1)

    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigCycloidePICTCycloide-for_eps.png
from phystricks import *
def DesCordes():
	pspict,fig = SinglePicture("DesCordes")

	var('x')
	f1=4*x
	f2=x**2-cos(x)
	mx=-1
	Mx=2
	curve=ParametricCurve(f1,f2).graph(mx,Mx)
	pspict.DrawGraph(curve)

	x0=-0.5
	x1=Mx-0.5
	n=5
	P0=curve.get_point(x0)
	sigma=[ x0+(x1-x0)/i for i in range(1,n) ]
	for xi in sigma:
		Q=curve.get_point(xi)
		corde=Segment(P0,Q)
		corde.parameters.color="red"
		pspict.DrawGraph(corde)

	pspict.DrawDefaultAxes()
	pspict.dilatation(0.8)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigDesCordesPICTDesCordes-for_eps.png
from phystricks import *
def ParamTangente():
	pspict,fig = SinglePicture("ParamTangente")
	var('x')
	f1=x**2
	f2=x**3
	mx=-1.5
	Mx=-mx
	curve=ParametricCurve(f1,f2).graph(mx,Mx)
	pspict.DrawGraph(curve)
	lls=curve.get_regular_parameter(mx,Mx,1.5)
	eps=0.7
	#lls=[-eps,eps]
	for i in range(len(lls)) :
		ll=lls[i]
		Q=curve.get_point(ll)
		v=curve.get_tangent_vector(ll)
		v.parameters.color="red"
		pspict.DrawGraphs(v)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigParamTangentePICTParamTangente-for_eps.png
from phystricks import *
def Polirettangolo():
	pspict,fig = SinglePicture("Polirettangolo")

	P=Point(0,2)
	P1=Point(3,4)
	P2=Point(1,4)
	P3=Point(4,5)
	P4=Point(4,0)
	P5=Point(6,2)
	P6=Point(4,3)
	P7=Point(7,7)
	
	R=Rectangle(P,P1)
	R1=Rectangle(P2,P3)
	R2=Rectangle(P4,P5)
	R3=Rectangle(P6,P7)
	R.parameters.hatched()
	R.parameters.hatch.color="red"
	R.parameters.style="dotted"
	R1.parameters=R.parameters
	R2.parameters=R.parameters
	R3.parameters=R.parameters

	pspict.DrawGraphs(R,R1,R2,R3)
	
	pspict.DrawDefaultAxes()
	pspict.dilatation(0.5)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigPolirettangoloPICTPolirettangolo-for_eps.png
from phystricks import *
def RegioniPrimoeSecondoTipo():
	fig = GenericFigure("RegioniPrimoeSecondoTipo")

	ssfig1=fig.new_subfigure(r'''Une region du premier type''', 'primotipo')
	ssfig2=fig.new_subfigure(r'''Une region du deuxi\`eme type''', 'secondotipo')
	pspict1=ssfig1.new_pspicture('regun')
	pspict2=ssfig2.new_pspicture('regdeux')

	a=1
	b=4
	m=float(b+a)/2
	var('x')
	f=phyFunction(sin(x+1)+2)
	g=phyFunction(-(x-2)**(2)+6)
	F=f.graph(a,b)
	G=g.graph(a,b)
	reg=SurfaceBetweenFunctions(f,g,a,b)
	reg.parameters.hatched()
	reg.parameters.hatch.color="red"
	reg.Isegment.parameters.style="dashed"
	reg.Fsegment.parameters.style="dashed"
	reg.f1.parameters.style="solid"
	reg.f1.parameters.color="blue"
	reg.f2.parameters.style="solid"
	reg.f2.parameters.color="blue"

	Xa=Point(a,0)
	Xb=Point(b,0)
	Xa.put_mark(0.3,-90,"$a$")
	Xb.put_mark(0.3,-90,"$b$")
	Mf=f.get_point(m)
	Mf.put_mark(0.3,Mf.advised_mark_angle,"$g_1$")
	Mg=g.get_point(m)
	Mg.put_mark(0.3,Mg.advised_mark_angle,"$g_2$")
	Mf.parameters.symbol="none"
	Mg.parameters.symbol="none"
	Sa=Segment(f.get_point(a),Xa)
	Sa.parameters.style="dotted"
	Sb=Segment(f.get_point(b),Xb)
	Sb.parameters.style="dotted"

	pspict1.axes.no_graduation()
	pspict1.DrawGraphs(reg,Xa,Xb,Mf,Mg,Sa,Sb)
	pspict1.DrawDefaultAxes()
	pspict1.dilatation(1)
	
	c=0
	d=4
	m=float(d+c)/2
	var('x')
	S=ParametricCurve(sin(x)+2,x+1).graph(c,d)
	P1=S.get_point(d)
	P4=S.get_point(c)
	R=ParametricCurve(((x-1)/3)**2+5,x+1).graph(c,d)
	P2=R.get_point(c)
	P3=R.get_point(d)
	Q=Segment(P1,P3)
	T=Segment(P4,P2)
	reg2=CustomSurface(S,Q,T,R)
	reg2.parameters.hatched()
	reg2.parameters.hatch.color="blue"
	Q.parameters.style="dashed"
	T.parameters.style="dashed"

	Xc=Point(0,S.get_point(c).y)
	Xd=Point(0,S.get_point(d).y)
	Xc.put_mark(0.3,180,"$c$")
	Xd.put_mark(0.3,180,"$d$")
	MS=S.get_point(m)
	MS.put_mark(0.3,MS.advised_mark_angle.degree+180,"$h_1$")
	MR=R.get_point(m)
	MR.put_mark(0.3,MR.advised_mark_angle,"$h_2$")
	MS.parameters.symbol="none"
	MR.parameters.symbol="none"
	Sc=Segment(S.get_point(c),Xc)
	Sc.parameters.style="dotted"
	Sd=Segment(S.get_point(d),Xd)
	Sd.parameters.style="dotted"

	pspict2.axes.no_graduation()
	pspict2.DrawGraphs(reg2, S,Q,T,R,Xc,Xd,MS,MR,Sc,Sd)
	pspict2.DrawDefaultAxes()
	pspict2.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigRegioniPrimoeSecondoTipossprimotipoPICTregun-for_eps.png _images/Picture_FIGLabelFigRegioniPrimoeSecondoTiposssecondotipoPICTregdeux-for_eps.png
from phystricks import *
def ExampleIntegration():
	pspict,fig = SinglePicture("ExampleIntegration")
	
	a=0
	b=(sqrt(5)+1)/2
	c=2
	var('x')
	f=phyFunction(x)
	g=phyFunction(x**2-1)
	F=f.graph(a,c)
	G=g.graph(a,c)
	reg=SurfaceBetweenFunctions(f,g,a,b)
	reg.parameters.hatched()
	reg.parameters.hatch.color="red"
	F.parameters.style="solid"
	F.parameters.color="blue"
	G.parameters.style="solid"
	G.parameters.color="blue"

	pspict.DrawGraphs(reg, F, G)
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigExampleIntegrationPICTExampleIntegration-for_eps.png
from phystricks import *
def ExampleIntegrationdeux():
    pspict,fig = SinglePicture("ExampleIntegrationdeux")
    
    a=-3
    b=-1
    e=0
    c=5
    d=6
    var('x')
    f=phyFunction(x-1)
    g=phyFunction(sqrt(2*x+6))
    h=phyFunction(-sqrt(2*x+6))
    F=f.graph(a,d)
    G=g.graph(a,d)
    H=h.graph(a,e)

    reg=SurfaceBetweenFunctions(f,g,b,c)
    reg.parameters.hatched()
    reg.parameters.hatch.color="red"
    reg.Isegment.parameters.style="none"

    reg1=SurfaceBetweenFunctions(g,h,a,b)
    reg1.parameters.hatched()
    reg1.parameters.hatch.color="green"
    reg1.Fsegment.parameters=reg.Isegment.parameters

    F.parameters.style="solid"
    F.parameters.color="blue"
    G.parameters.style="solid"
    G.parameters.color="blue"
    H.parameters.style="solid"
    H.parameters.color="blue"

    pspict.DrawGraphs(reg, reg1, F, G, H)
    pspict.DrawDefaultAxes()
    pspict.dilatation(1)
    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigExampleIntegrationdeuxPICTExampleIntegrationdeux-for_eps.png
from phystricks import *
def ExampleChangementVariables():
	fig = GenericFigure("ExampleChangementVariables")

	ssfig1=fig.new_subfigure(r'''La r\'egion $V$''', 'vecchiaregione')
	ssfig2=fig.new_subfigure(r'''La r\'egion $U=\phi^{-1}(V)$''', 'nuovaregione')
	pspict=ssfig1.new_pspicture('vreg')
	pspict2=ssfig2.new_pspicture('nreg')
	P=Point(0,-1)
	P1=Point(1,0)
	P2=Point(2,0)
	P3=Point(0,-2)
	l1=Segment(P1,P2)
	l2=Segment(P2,P3)
	l3=Segment(P3,P)
	l4=Segment(P,P1)
	reg=CustomSurface(l1,l2,l3,l4)
	reg.parameters.hatched()
	reg.parameters.hatch.color="red"
	
	pspict.DrawGraphs(reg,l1,l2,l3,l4 )
	pspict.DrawDefaultAxes()
	pspict.dilatation(1)
	
       	R=Point(-1,1)
	R1=Point(1,1)
	R2=Point(2,2)
	R3=Point(-2,2)
	s1=Segment(R1,R2)
	s2=Segment(R2,R3)
	s3=Segment(R3,R)
	s4=Segment(R,R1)
	reg1=CustomSurface(s1,s2,s3,s4)
	reg1.parameters.hatched()
	reg1.parameters.hatch.color="blue"

	pspict2.DrawGraphs(reg1, s1,s2,s3,s4)
	pspict2.DrawDefaultAxes()
	pspict2.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigExampleChangementVariablesssnuovaregionePICTnreg-for_eps.png _images/Picture_FIGLabelFigExampleChangementVariablesssvecchiaregionePICTvreg-for_eps.png
from phystricks import *

def ArcLongueurFinesse():
	pspict,fig = SinglePicture("ArcLongueurFinesse")

	def TraceDivision(n,curve,pspict,color):
		sigma=[float(i)/n  for i in range(n+1)  ]
		points = [ curve.get_point(t) for t in sigma ]
		for i in range(len(points)-1):
			A=points[i]
			B=points[i+1]
			seg=Segment(A,B)
			seg.parameters.color=color
			pspict.DrawGraph(seg)

	var('x')
	f1=-20*cos(x)
	f2=2*sin(2*pi*x)
	curve=ParametricCurve(f1,f2).graph(0,1)
	curve.parameters.style="dashed"
	pspict.DrawGraphs(curve)
	TraceDivision(3,curve,pspict,"red")
	TraceDivision(9,curve,pspict,"green")

	pspict.dilatation(0.7)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigArcLongueurFinessePICTArcLongueurFinesse-for_eps.png
from phystricks import *
def BoulePtLoin():
	pspict,fig = SinglePicture("BoulePtLoin")

	r=float(2)
	a=Point(0,0)
	a.put_mark(0.3,135,"$a$")
	cercle=Circle(a,r)
	x=cercle.get_point(45)
	x.put_mark(0.3,150,"$x$")
	v=AffineVector(a,x)
	delta=r/2
	N=4*(v.length()/delta)/3
	P=x+v/N
	P.put_mark(0.3,-90,"$P$")
	B=Circle(x,delta)
	B.parameters.style="dotted"
	seg=Segment(x,P)
	seg.parameters.style="dashed"
	
	pspict.DrawGraphs(seg,a,x,v,B,P)

	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigBoulePtLoinPICTBoulePtLoin-for_eps.png
from phystricks import *
def UneCellule():

	def Sigma(dep,leng):
		sigma=[dep]
		d=dep
		for l in leng :
			d=d+l
			sigma.append(d)
		return sigma

	pspict,fig = SinglePicture("UneCellule")

	a1=1
	l1=[1.2,1.5,0.5,1,1]
	sigma1=Sigma(a1,l1)
	b1=a1+sum(l1)
	a2=2
	l2=[0.5,1.5,1]
	sigma2=Sigma(a2,l2)
	b2=a2+sum(l2)
	for i in range(len(sigma1)):
		dist=0.3+(1-(-1)**i)*0.15	# <-- semi-automatic intelligent positioning
		x=sigma1[i]
		P=Point(x,0)
		if i == 0 :
			P.put_mark(dist,-90,"$a_1=y_{10}$")
		elif i == len(sigma1)-1:
			P.put_mark(dist,-90,"$b_1=y_{1%s}$"%str(i))
		else:
			P.put_mark(dist,-90,"$y_{1%s}$"%str(i))
		seg1=Segment(P,Point(x,a2))
		seg1.parameters.style="dotted"
		seg2=Segment(Point(x,a2),Point(x,b2))
		pspict.DrawGraphs(P,seg1,seg2)

	for i in range(len(sigma2)):
		y=sigma2[i]
		P=Point(0,y)
		if i == 0 :
			P.put_mark(0.9,180,"$a_2=y_{20}$")
		elif i == len(sigma2)-1:
			P.put_mark(0.9,180,"$b_2=y_{2%s}$"%str(i))
		else:
			P.put_mark(0.4,180,"$y_{2%s}$"%str(i))
		seg1=Segment(P,Point(a1,y))
		seg1.parameters.style="dotted"
		seg2=Segment(Point(a1,y),Point(b1,y))
		pspict.DrawGraphs(P,seg1,seg2)

	cellule=Rectangle(  Point(sigma1[3],sigma2[1]),Point(sigma1[4],sigma2[2])  )
	cellule.parameters.filled()
	cellule.parameters.fill.color="lightgray"
	pspict.DrawGraphs(cellule)

	pspict.axes.no_graduation()
	pspict.DrawDefaultAxes()

	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigUneCellulePICTUneCellule-for_eps.png
from phystricks import *
def SenoTopologo():
	pspict,fig = SinglePicture("SenoTopologo")

	a=-0.5
	b=0.5
	var('x')
	f=phyFunction(x*sin(1/x))
	G=f.graph(a,b)
	G.plotpoints=2000
	pspict.DrawGraph(G)
	pspict.axes.Dx=0.3
	pspict.axes.Dy=0.3
	pspict.DrawDefaultAxes()

	pspict.dilatation(5)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigSenoTopologoPICTSenoTopologo-for_eps.png
from phystricks import *
def AdhIntFr():
	pspict,fig = SinglePicture("exAdhIntFr")

	var('x')
	mx=0.7
	Mx=4.5
	fun=phyFunction(x**2-5*x+6)
	horiz=phyFunction(2)
	pts = Intersection(fun,horiz)
	x0=pts[0].x
	x1=pts[1].x
	droite=horiz.graph(mx,Mx)
	f=fun.graph(mx,Mx)
	droite.parameters.color="gray"
	f.parameters.color="gray"
	droite.parameters.style="dashed"
	f.parameters.style="dashed"

	P=f.get_point(3.5)
	Cer=Circle(P,0.3)

	A=SurfaceBetweenFunctions(fun,horiz,x0,x1)
	A.parameters.hatched()
	A.parameters.hatch.color="red"
	A.f1.parameters.color="blue"
	A.f1.parameters.style="solid"
	A.f2.parameters.style="solid"
	A.f2.parameters.color="blue"

	pspict.DrawGraphs(droite,f,A,P,Cer)

	pspict.DrawDefaultAxes()
	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigexAdhIntFrPICTexAdhIntFr-for_eps.png
from phystricks import *
def AdhIntFrDeux():
	pspict,fig = SinglePicture("exAdhIntFrDeux")

	var('x')
	mx=-0.5
	Mx=3
	f1=phyFunction(x+1)
	f2=phyFunction(2*x)
	pts = Intersection(f1,f2)
	x0=pts[0].x
	F1=f1.graph(mx,Mx)
	F2=f2.graph(mx,Mx)
	F1.parameters.color="gray"
	F1.parameters.style="dashed"
	F2.parameters=F1.parameters

	P=f1.get_point(x0)
	Cer=Circle(P,0.7)

	A=SurfaceBetweenFunctions(f1,f2,x0,Mx)
	A.parameters.hatched()
	A.parameters.hatch.color="red"
	A.f1.parameters.color="blue"
	A.f1.parameters.style="solid"
	A.f2.parameters = A.f1.parameters

	pspict.DrawGraphs(F1,F2,A,P,Cer)

	pspict.DrawDefaultAxes()
	pspict.dilatation(1)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigexAdhIntFrDeuxPICTexAdhIntFrDeux-for_eps.png
from phystricks import *
def AdhIntFrTrois():
	pspict,fig = SinglePicture("exAdhIntFrTrois")

	var('x')
	epsilon=0.005
	mx=epsilon
	Mx=2
	f1=phyFunction(3)
	f2=phyFunction(sin(1/x))
	#pts = Intersection(f1,f2)
	#x0=pts[0].x
	x0=epsilon
	x1=1
	F1=f1.graph(x1,Mx)
	F2=f2.graph(x1,Mx)
	F2.plotpoints=5000
	F1.parameters.color="gray"
	F1.parameters.style="dashed"
	F2.parameters=F1.parameters
	F1p=f1.graph(-Mx/2,-mx)
	F2p=f2.graph(-Mx/2,-mx)
	F2p.plotpoints=F2.plotpoints
	F1p.parameters=F1.parameters
	F2p.parameters=F1.parameters

	P=Point(0,0.7)
	Cer=Circle(P,0.1)

	A=SurfaceBetweenFunctions(f1,f2,x0,x1)
	A.f2.plotpoints=F2.plotpoints
	A.Isegment.parameters.style="solid"
	A.Isegment.parameters.color="blue"
	A.Fsegment.parameters = A.Isegment.parameters
	A.parameters.hatched()
	A.parameters.hatch.color="red"
	A.f1.parameters.color="blue"
	A.f1.parameters.style="solid"
	A.f2.parameters = A.f1.parameters

	pspict.DrawGraphs(F1p,F2p,F1,F2,A,P,Cer)
	#pspict.DrawGraphs(F1p,F2p,F1,F2,P)

	pspict.axes.Dx=0.5
	pspict.DrawDefaultAxes()
	pspict.dilatation_X(4)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigexAdhIntFrTroisPICTexAdhIntFrTrois-for_eps.png
from phystricks import *
def AdhIntFrSix():
	pspict,fig = SinglePicture("exAdhIntFrSix")

	N=100
	for n in range(1,N):
		x=float(1)/n
		seg=Segment(Point(x,0),Point(x,1))
		seg.parameters.color="blue"
		pspict.DrawGraphs(seg)
	seg=Segment(Point(0,0),Point(0,1))
	pspict.DrawGraphs(seg)

	P=Point(0,0.8)
	Cer=Circle(P,0.15)
	pspict.DrawGraphs(P,Cer)

	pspict.axes.Dx=0.5
	pspict.axes.Dy=0.5
	pspict.DrawDefaultAxes()
	pspict.dilatation_X(4)
	pspict.dilatation_Y(4)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigexAdhIntFrSixPICTexAdhIntFrSix-for_eps.png
from phystricks import *
def DeuxCercles():
	pspict,fig = SinglePicture("DeuxCercles")

	A=Point(0,0.5)
	B=Point(0.5,0)
	C1=Circle(A,0.5)
	C2=Circle(B,0.5)
	print type(C1)

	l1=C1.parametric_curve(-pi/2,0)
	l2=C2.parametric_curve(pi/2,-pi)
	l1.parameters.color="red"
	l2.parameters.color="red"

	surf=CustomSurface(l1,l2)
	surf.parameters.hatched()
	surf.parameters.hatch.color="lightgray"

	pspict.DrawGraphs(surf,C1,C2,l1,l2)

	pspict.axes.Dx=0.5
	pspict.axes.Dy=0.5
	pspict.DrawDefaultAxes()
	pspict.dilatation(2)

	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigDeuxCerclesPICTDeuxCercles-for_eps.png
from phystricks import *
import phystricksCommuns as Communs
def TraceCDun():
	x=var('x')
	f1=phyFunction(x+1/x)
	f2=phyFunction(x+1/(2*x**2))
	llamI=-3
	llamF=-0.4
	curve=ParametricCurve(f1,f2).graph(llamI,llamF)
	
	LLms=[-2,-1,-0.6]
	Communs.CorrectionParametrique(curve,LLms,"TraceCDun")


	f1=phyFunction(cos(x)**2)
	f2=phyFunction(cos(x)**3*sin(x))
	llamI=0
	llamF=2*pi
	curve=ParametricCurve(f1,f2).graph(llamI,llamF)
	
	LLms=[0,pi/3,pi/5]
	Communs.CorrectionParametrique(curve,LLms,"TraceCDdeux",dilatation=2)
_images/Picture_FIGLabelFigSubfiguresCDUTraceCDdeuxssSS1TraceCDdeuxPICTTraceCDdeuxpsp1-for_eps.png _images/Picture_FIGLabelFigSubfiguresCDUTraceCDdeuxssSS2TraceCDdeuxPICTTraceCDdeuxpsp2-for_eps.png _images/Picture_FIGLabelFigSubfiguresCDUTraceCDunssSS1TraceCDunPICTTraceCDunpsp1-for_eps.png _images/Picture_FIGLabelFigSubfiguresCDUTraceCDunssSS2TraceCDunPICTTraceCDunpsp2-for_eps.png
from phystricks import *
def QuelCote():
	pspict,fig = SinglePicture("QuelCote")

	x=var('x')
	f1=phyFunction(x+1/x+1)
	f2=phyFunction(x+1/(2*x**2)+1)
	llamI=-2
	llamF=-0.7
	llam = -1.2
	curve=ParametricCurve(f1,f2).graph(llamI,llamF)

	P=curve.get_point(llam)
	normal=curve.get_normal_vector(llam)
	Mnormal=-normal
	normal.parameters.color="green"
	Mnormal.parameters.color="green"
	Mnormal.parameters.style="dashed"
	second=curve.get_second_derivative_vector(llam)
	tangente=curve.get_tangent_segment(llam)
	tangente.parameters.color="brown"
	tangente.put_mark(0.3,0,"$\gamma'(t)$")
	normal.put_mark(0.3,90,"$n(t)$")
	Mnormal.put_mark(0.3,90,"$-n(t)$")
	second.put_mark(0.3,45,"$\gamma''(t)$")
	P.put_mark(0.3,-45,"$P$")

	pspict.DrawGraphs(curve,tangente,second,normal,Mnormal,P)
	pspict.dilatation(2)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigQuelCotePICTQuelCote-for_eps.png
from phystricks import *
def Osculateur():
	pspict,fig = SinglePicture("Osculateur")

	x=var('x')
	f1=phyFunction(-20*cos(x))
	f2=phyFunction(2*sin(2*pi*x))
	llamI=0
	llamF=1
	curve=ParametricCurve(f1,f2).graph(llamI,llamF)
	
	LLms=[0.25,0.3,0.7]
	for llam in LLms :
		P=curve.get_point(llam)
		osculateur=curve.get_osculating_circle(llam)
		if abs(osculateur.radius)<3:
			pspict.DrawGraphs(P,osculateur)
		pspict.DrawGraphs(P)
	
	pspict.DrawGraphs(curve)
	pspict.dilatation(1)
	fig.conclude()
	fig.write_the_file()
_images/Picture_FIGLabelFigOsculateurPICTOsculateur-for_eps.png
from phystricks import *
def FnCosApprox():
    pspict,fig = SinglePicture("FnCosApprox")

    var('x')
    f=phyFunction(cos(x)).graph(0,pi)
    P=f.get_point(pi/4)
    P.put_mark(0.3,P.advised_mark_angle,"$P$",automatic_place=pspict)
    pspict.axes.single_axeX.axes_unit=AxesUnit(pi,"\\pi")
    pspict.axes.single_axeX.Dx=0.25

    pspict.DrawGraphs(f,P,P.mark.bounding_box(pspict))
    pspict.DrawDefaultAxes()
    pspict.dilatation(2)
    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigFnCosApproxPICTFnCosApprox-for_eps.png
from phystricks import *
import numpy

def PluieSceau():
    pspicts,fig = MultiplePictures("PluieSceau",2)
    pspicts[0].mother.caption="Some rain water enters a recipient."
    pspicts[1].mother.caption="Other rain water in the recipient."

    a=2
    l=3
    h=1

    A=Point(0,a)
    B=Point(0,0)
    C=Point(l,0)
    D=Point(l,a)

    eau=Rectangle(Point(0,h),C)
    eau.parameters.filled()
    eau.parameters.fill.color="blue"
    eau.parameters.style="none"

    seg1=Segment(A,B)
    seg2=Segment(B,C)
    seg3=Segment(C,D)

    for pspict in pspicts :
        pspict.DrawGraphs(eau,seg1,seg2,seg3)

    D=1
    n=20
    draw_points=[  Point(x,a+0.2) for x in numpy.linspace(-D,l+D,n)  ]

    vv=[(0,-1),(1,-1)]
    pluie=[]
    for v in vv:
        v = Vector(v[0],v[1]).fix_size(0.7)
        pl = VectorField(v.F.x,v.F.y).graph(draw_points=draw_points)
        pl.parameters.color="blue"
        pluie.append(pl)

    for i in range(len(pspicts)):
        pspicts[i].DrawGraphs(pluie[i])   

    fig.conclude()
    fig.write_the_file()
_images/Picture_FIGLabelFigPluieSceaussLabelSubFigPluieSceau0PICTPluieSceaupspict0-for_eps.png _images/Picture_FIGLabelFigPluieSceaussLabelSubFigPluieSceau1PICTPluieSceaupspict1-for_eps.png

Tests

The following pictures were buggy in past time.

  • The marks on the axis are well positioned
_images/Picture_FIGLabelFigAxesSixPICTAxesSix-for_eps.png
  • The bounding box encloses the whole axe including the marks.
_images/Picture_FIGLabelFigExSingleAxePICTExSingleAxe-for_eps.png
  • The image is dilated in the X dimension;
  • the mark is at visual length 1 from the point;
  • the graduation on the axes is correctly placed
_images/Picture_FIGLabelFigTestDilatationPICTTestDilatation-for_eps.png

Indices and tables