How to make pictures using postscript programs (part 10) ----------------------------------------------------------------------------- If you want to draw curves that are given by a parametrization, you just put points along the curve and connect each one to the previous by lineto. The first point most be set with moveto, since the first point is not connected to any previous point. Here is an example of the parabola y = x^2 on the interval [-1,1] -------------------------Example 21------------------------------------------ %!PS-Adobe-2.0 %%BoundingBox: -110.0 -10.0 110.0 110.0 100 100 scale %scale so that we have the interval -1 1 blown up to -100 100 0.01 setlinewidth newpath -1 1 moveto %upper left end of parabola -1 0.01 1 {/x exch def x x x mul lineto } for stroke showpage ---------------------------------------------------------------------------- This was just an example of a (x,y)-curve where y = f(x), in this case y=x*x. More complicated are parametrized curves, where x=f(t) and y = g(t). The simplest example of that is a circle: x=cos(t), y=sin(t) for t=0...360 degree gives a circle of radius 1. If we elongate it in a coordinate, we get an ellipse; below is the ellipse x = 250* cost(t), y = 100* sin(t) -------------------------Example 22------------------------------------------ %!PS-Adobe-2.0 %%BoundingBox: -260 -110 260 110 newpath 250 0 moveto %rightmost point of the ellipse 0 1 360 {/t exch def t cos 250 mul %x coordinate t sin 100 mul %y coordinate lineto } for stroke showpage ---------------------------------------------------------------------------- of course, taking a circle of radius 100 and scaling it with 2.5 1 has the same effect; the only difference is that we did not change the coordinate system. Another classic curve is the hyperbola, with the parametrization y=1/x. Here it is convenient to cut the parametrization in two parts, from 0 to 1, and from 1 to wherever we want to stop. Below is a hyperbola on [0,10], only the upper arc. -------------------------Example 23------------------------------------------ %!PS-Adobe-2.0 %%BoundingBox: 0 0 300 300 30 30 scale % to expand the 10 by 10 box to 300 by 300 0.05 setlinewidth newpath 1 1 moveto %middle point of the hyperbola, now arc going right 1 0.1 10 {/x exch def x %x coordinate 1 x div %y coordinate lineto } for stroke newpath 1 1 moveto %middle point of the hyperbola, now arc going up 1 0.1 10 {/y exch def 1 y div %x coordinate y %y coordinate lineto } for stroke ---------------------------------------------------------------------------- Ellipses, parabolas and hyperbolas are known as `quadrics', because they are solutions to quadratic equations, or as `conics', because they are the interection curves of a cone with a plane. Try with flashlight cone and wall.