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?

Dan
  • 3,699
asimath
  • 145

1 Answers1

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

Zarko
  • 296,517
  • 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
  • I'm glad that you figured out. I also add similar case to my answer. – Zarko Nov 12 '16 at 19:57
  • 1
    @asimath Don't use node to define coordinate! – Paul Gaborit Nov 12 '16 at 23:51
  • @PaulGaborit : Thanks for pointing out. I understand the difference now. This post helped http://tex.stackexchange.com/questions/91310/tikz-difference-between-node-and-coordinate – asimath Nov 13 '16 at 04:34
  • @PaulGaborit : can the code of Zarko above be modified so that there is no faded line showing the vertex name. i.e. [pin=330:a] to be modified such that name of vertex is in same position but no faded line showing it? – asimath Nov 13 '16 at 09:08
  • 1
    Instead of pin use label. – Zarko Nov 13 '16 at 10:18