3

enter image description here

I can draw this picture in tikz with codes like
\draw (a,b) node {} -- (c,d);
but for that I have to calculate values of coordinates so that the picture looks good. What I want to do is use this type of code
\draw (0:0) node {} -- (45:1.2) node {} -- (45:2.4) node {} -- (90:3); which gives me this picture
enter image description here
Is it possible to code in this way such that (90:3) is plotted by considering (45:2.4) as origin not by considering (0:0) as origin?

  • 1
    \draw (0:0) node {} --++ (45:1.2) node {} --++ (45:2.4) node {} -- ++(90:3); ? – Zarko Nov 12 '16 at 18:51
  • I convert my comment to answer. – Zarko Nov 12 '16 at 19:08
4

From TikZ manual (chapter 13.4, page 140, recent version 3.0.1a):

You can prefix coordinates by ++ to make them “relative.” A coordinate such as ++(1cm,0pt) means “1cm to the right of the previous position, making this the new current position.” Relative coordinates are often useful in “local” contexts:

\documentclass[tikz, border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[every node/.style={circle,fill=black}]
\draw (0:0)    node (a) [pin=330:a] {} -- ++ (45:1.2) node (b) [pin=330:b] {} -- ++
      (45:2.4) node (c) [pin=330:c] {} -- ++ (90:3)   node (d) [pin=330:a] {};
\draw   (b) -- ++ (-15:2) node (e) [pin=330:e] {};
\end{tikzpicture}

gives:

enter image description here

  • now if I want to draw line from say, top most vertex (any angle) ,how can I do it in different line of code. From your code I can do it in same line. That will help me drawing my complete figure. – asimath Nov 12 '16 at 19:20
  • It is difficult to say .. for selecting and using coordinates not exist general rule. It depends on many factors and on your skills. Show your image, than I can see, if it is possible to improve your code. Concerning graph with vertices people first define positions of vertices (relatively to star one) and than draw the lines. Se example for sketch of automaton in TikZ manual, (41 Automata Drawing Library, page 513). Maybe you will find some useful for you. – Zarko Nov 12 '16 at 19:32
  • oh! I figured it out. while drawing the paths, the vertex which I need for later drawing will name it and later use it like``\draw (0:0) node {} --++ (45:1.2) node {} --++ (45:1.2) node {} --++ (90:1.2) node (a) {}; \draw (a) -- ++ (90:1.2) node {};'' – asimath Nov 12 '16 at 19:41
  • 1
    @asimath Don't use node to define coordinate! – Paul Gaborit Nov 12 '16 at 23:51
  • 1
    Instead of pin use label. – Zarko Nov 13 '16 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.