Previous Up Next

7.2.3  Polygonal paths: polygonplot ligne_polygonale linear_interpolate listplot plotlist

You can draw a polygonal path with either polygonplot or listplot.

Given a list of points (a two-column matrix) or two lists (the x coordinates and the y-coordinates), the polygonplot (or polygonscatterplot) command will draw the polygonal path through the points, from left to right (so the points are automatically ordered by increasing x-coordinates). If you enter

polygonplot([0,1,2,3,4],[0,1,4,9,16])

or

polygonplot([[0,0],[1,1],[2,4],[3,9],[4,16]])

or even

polygonplot([[2,4],[0,0],[3,9],[1,1],[4,16]])

you will get

If you give polygonplot a single list of numbers, then they will be taken to be the y-coordinates and the x-coordinates will be assumed to be integers starting at 0. If you enter

polygonplot([0,1,4,9,16])

If you want to get coordinates on the polygonal path, you can use the linear_interpolate command. This command takes four arguments; a two-row matrix consisting of the x-coordinates and the y-coordinates, xmin, the minimum value of x that you are interested in, xmax, the maximum value of x, and xstep, the step size you want. (The values of xmin and xmax must be between the smallest and largest x-coordinates of the points.) You will get a matrix with two rows, the first row will be [xmin, xmin+xstep, xmin+2xstep,...,xmax] and the second row will be the corresponding y-coordinates of the points on the polygonal path. For example, if you enter

linear_interpolate([[1,2,6,9],[3,4,6,12]],2,7,1)

you will get

[[2.0,3.0,4.0,5.0,6.0,7.0],[4.0,4.5,5.0,5.5,6.0,8.0]]

If you want to draw a polygonal path through points in an order determined by you, you can use the listplot (or plotlist) command. If you give listplot a list of points, then you will get a polygonal path through the points in the order given by the list. If you enter

listplot([[2,4],[0,0],[3,9],[1,1],[4,16]])

you will get

As with polygonplot, if you give listplot a single list of numbers, then they will be taken to be the y-coordinates and the x-coordinates will be assumed to be integers starting at 0. If you enter

listplot([0,1,4,9,16])

you will get the same graph that you got with polygonplot. However, unlike polygonplot, the listplot command can’t be given two lists of numbers as arguments.


Previous Up Next