0% found this document useful (0 votes)
59 views1 page

Tikz 004

This document discusses different ways to specify coordinates in TikZ pictures. It explains that coordinates can be specified using absolute values with units like (10pt,2cm) or relative values without units like (1,2). Polar coordinates can be written as (30:1cm). Additional notation like ++(x,y) allows specifying coordinates relative to the previous point. The (hpi |- hqi) syntax finds the intersection of a vertical line through hpi and a horizontal line through hqi. The document provides examples using these coordinate specifications to draw sine and cosine curves on a unit circle.

Uploaded by

9251066
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views1 page

Tikz 004

This document discusses different ways to specify coordinates in TikZ pictures. It explains that coordinates can be specified using absolute values with units like (10pt,2cm) or relative values without units like (1,2). Polar coordinates can be written as (30:1cm). Additional notation like ++(x,y) allows specifying coordinates relative to the previous point. The (hpi |- hqi) syntax finds the intersection of a vertical line through hpi and a horizontal line through hqi. The document provides examples using these coordinate specifications to draw sine and cosine curves on a unit circle.

Uploaded by

9251066
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

\begin{tikzpicture}[rounded corners,ultra thick]

\shade[top color=yellow,bottom color=black] (0,0) rectangle +(2,1);


\shade[left color=yellow,right color=black] (3,0) rectangle +(2,1);
\shadedraw[inner color=yellow,outer color=black,draw=yellow] (6,0) rectangle +(2,1);
\shade[ball color=green] (9,.5) circle (.5cm);
\end{tikzpicture}

For Karl, the following might be appropriate:


\begin{tikzpicture}[scale=3]
\clip (-0.1,-0.2) rectangle (1.1,0.75);
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\draw (0,0) circle [radius=1cm];
\shadedraw[left color=gray,right color=green, draw=green!50!black]
(0,0) -- (3mm,0mm)
arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\end{tikzpicture}

However, he wisely decides that shadings usually only distract without adding anything to the picture.

2.15 Specifying Coordinates


Karl now wants to add the sine and cosine lines. He knows already that he can use the color= option to set
the lines’ colors. So, what is the best way to specify the coordinates?
There are different ways of specifying coordinates. The easiest way is to say something like (10pt,2cm).
This means 10pt in x-direction and 2cm in y-directions. Alternatively, you can also leave out the units as in
(1,2), which means “one times the current x-vector plus twice the current y-vector”. These vectors default
to 1cm in the x-direction and 1cm in the y-direction, respectively.
In order to specify points in polar coordinates, use the notation (30:1cm), which means 1cm in direction
30 degree. This is obviously quite useful to “get to the point (cos 30◦ , sin 30◦ ) on the circle”.
You can add a single + sign in front of a coordinate or two of them as in +(0cm,1cm) or ++(2cm,0cm).
Such coordinates are interpreted differently: The first form means “1cm upwards from the previous specified
position” and the second means “2cm to the right of the previous specified position, making this the new
specified position”. For example, we can draw the sine line as follows:
\begin{tikzpicture}[scale=3]
\clip (-0.1,-0.2) rectangle (1.1,0.75);
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\draw (0,0) circle [radius=1cm];
\filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\draw[red,very thick] (30:1cm) -- +(0,-0.5);
\end{tikzpicture}

Karl used the fact sin 30◦ = 1/2. However, he very much doubts that his students know this, so it would
be nice to have a way of specifying “the point straight down from (30:1cm) that lies on the x-axis”. This
is, indeed, possible using a special syntax: Karl can write (30:1cm |- 0,0). In general, the meaning of
(hpi |- hqi) is “the intersection of a vertical line through p and a horizontal line through q”.
Next, let us draw the cosine line. One way would be to say (30:1cm |- 0,0) -- (0,0). Another way
is the following: we “continue” from where the sine ends:
\begin{tikzpicture}[scale=3]
\clip (-0.1,-0.2) rectangle (1.1,0.75);
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\draw (0,0) circle [radius=1cm];
\filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\draw[red,very thick] (30:1cm) -- +(0,-0.5);
\draw[blue,very thick] (30:1cm) ++(0,-0.5) -- (0,0);
\end{tikzpicture}

Note that there is no -- between (30:1cm) and ++(0,-0.5). In detail, this path is interpreted as follows:
“First, the (30:1cm) tells me to move my pen to (cos 30◦ , 1/2). Next, there comes another coordinate

40

You might also like