Most PGF commands expect you to provide the coordinates of a point (also called coordinate) inside your picture. Points are always “local” to your picture, that is, they never refer to an absolute position on the page, but to a position inside the current {pgfpicture} environment. To specify a coordinate you can use commands that start with \pgfpoint.
The following commands are the most basic for specifying a coordinate.
Yields a point location. The coordinates are given as TEX dimensions.
|
Yields the origin. Same as \pgfpoint{0pt}{0pt}.
Yields a point location given in polar coordinates. You can specify the angle only in degrees, radians are not supported, currently.
|
Coordinates can also be specified as multiples of an x-vector and a y-vector. Normally, the x-vector points one centimeter in the x-direction and the y-vector points one centimeter in the y-direction, but using the commands \pgfsetxvec and \pgfsetyvec they can be changed. Note that the x- and y-vector do not necessarily point “horizontally” and “vertically.”
It is also possible to specify a point as a multiple of three vectors, the x-, y-, and z-vector. This is useful for creating simple three dimensional graphics.
Yields a point that is situated at sx times the x-vector plus sy times the y-vector.
|
Yields a point that is situated at sx times the x-vector plus sy times the y-vector plus sz times the z-vector.
|
Sets that current x-vector for usage in the xyz-coordinate system.
Example:
|
Works like \pgfsetyvec.
Works like \pgfsetzvec.
Many commands allow you to construct a coordinate in terms of other coordinates.
Returns the sum vector <v1> + <v2>.
|
Returns the vector <factor><coordinate>.
|
Returns the difference vector <end>-<start>.
|
This command returns a normalized version of <point>, that is, a vector of length 1pt pointing in the direction of <point>. If <point> is the 0-vector or extremely short, a vector of length 1pt pointing upwards is returned.
This command is not implemented by calculating the length of the vector, but rather by calculating the angle of the vector and then using (something equivalent to) the \pgfpointpolar command. This ensures that the point will really have length 1pt, but it is not guaranteed that the vector will precisely point in the direction of <point> due to the fact that the polar tables are accurate only up to one degree. Normally, this is not a problem.
|
The commands in this section allow you to specify points on a line or a curve. Imaging a point “traveling” along a curve from some point p to another point q. At time t = 0 the point is at p and at time t = 1 it is at q and at time, say, t = 1/2 it is “somewhere in the middle.” The exact location at time t = 1/2 will not necessarily be the “halfway point,” that is, the point whose distance on the curve from p and q is equal. Rather, the exact location will depend on the “speed” at which the point is traveling, which in turn depends on the lengths of the support vectors in a complicated manner. If you are interested in the details, please see a good book on Bézier curves.
Yields a point that is the tth fraction between p and q, that is, p + t(q - p). For t = 1/2 this is the middle of p and q.
|
Yields a point that is located <distance> many units removed from the start point in the direction of the end point. In other words, this is the point that results if we travel <distance> steps from <start point> towards <end point>.
Example:
|
Yields a point that is on the Bézier curve from p to q with the support points s1 and s2. The time t is used to determine the location, where t = 0 yields p and t = 1 yields q.
|
The following commands are useful for specifying a point that lies on the border of special shapes. They are used, for example, by the shape mechanism to determine border points of shapes.
This command returns a point that lies on the intersection of a line starting at the origin and going towards the point <direction point> and a rectangle whose center is in the origin and whose upper right corner is at <corner>.
The <direction point> should have length “about 1pt,” but it will be normalized automatically. Nevertheless, the “nearer” the length is to 1pt, the less rounding errors.
|
This command works like the corresponding command for rectangles, only this time the <corner> is the corner of the bounding rectangle of an ellipse.
|
This command returns the intersection of a line going through p and q and a line going through s and t. If the lines do not intersection, an arithmetic overflow will occur.
|
There are two commands that can be used to “extract” the x- or y-coordinate of a coordinate.
Sets the TEX-<dimension> to the x-coordinate of the point.
|
Like \pgfextractx, except for the y-coordinate.
As a normal user of PGF you do not need to read this section. It is relevant only if you need to understand how the point commands work internally.
When a command like \pgfpoint{1cm}{2pt} is called, all that happens is that the two TEX-dimension variables \pgf@x and \pgf@y are set to 1cm and 2pt, respectively. A command like \pgfpathmoveto that takes a coordinate as parameter will just execute this parameter and then use the values of \pgf@x and \pgf@y as the coordinates to which it will move the pen on the current path.
since commands like \pgfpointnormalised modify other variables besides \pgf@x and \pgf@y during the computation of the final values of \pgf@x and \pgf@y, it is a good idea to enclose a call of a command like \pgfpoint in a TEX-scope and then make the changes of \pgf@x and \pgf@y global as in the following example:
|
Since this situation arises very often, the macro \pgf@process can be used to perform the above code:
Executes the <code> in a scope and then makes \pgf@x and \pgf@y global.
Note that this macro is used often internally. For this reason, it is not a good idea to keep anything important in the variables \pgf@x and \pgf@y since they will be overwritten and changed frequently. Instead, intermediate values can ge stored in the TEX-dimensions \pgf@xa, \pgf@xb, \pgf@xc and their y-counterparts \pgf@ya, \pgf@yb, pgf@yc. For example, here is the code of the command \pgfpointadd:
|