6

Want to make the following shapes function in TikZenter image description here

\begin{tikzpicture}
\tikzstyle{every node}=[draw,shape=circle];
\draw (0,0)  --   (0,1)  node {1};
\draw (0,1)  --   (1,1)  node {2};
\draw (1,1)  --   (1,0)  node {3};
\draw (1,0) --    (0,0)  node {4};
\end{tikzpicture}
\begin{tikzpicture}
\tikzstyle{every node}=[draw,shape=circle];
\draw (0,0)  -- ++  (1,1)  node {1};
\draw (1,1)  -- ++  (1,-1) node {2};
\draw (0,0)  --  ++ (2,0)  node {3};
\end{tikzpicture}
Paul Gessler
  • 29,607
Micky K
  • 1,457
  • 1
    Can you show us what you've tried so far? Have you consulted the numerous TikZ resources recommended to you in your other questions to give you a starting point? – Paul Gessler May 07 '14 at 14:13
  • I need these figure for my Thesis. I start working on TikZ but complex figure I couldn't make it like last 5 figure – Micky K May 07 '14 at 14:16
  • 3
    Then please, show us your code for the first nine. Or better yet, just ask about a specific issue in one of the final five. When asking graphics questions that are essentially "do this for me" formats, you are at the mercy of the procrastination of our users here. :-) Asking questions about specific problems you're having on one figure often leads to faster and more learning-conducive answers. The question is then much more useful to future visitors to the site as well. – Paul Gessler May 07 '14 at 14:25
  • Please edit these into the question (using the "edit" button to the left side of the bottom of the post) rather than leaving multiple comments. A tip when editing your post: If you indent lines by 4 spaces or [enclose words in backticks ```](http://meta.tex.stackexchange.com/q/863), they'll be marked as code. You can also highlight the code and click the "code" button (with "{}" on it). – Paul Gessler May 07 '14 at 14:30
  • The above two i make for 4 and 7 figure. I am still trying to make it. – Micky K May 07 '14 at 14:45
  • Possibly related: http://tex.stackexchange.com/questions/99133/creating-bezier-surfaces-using-procedural-graphics/102585#102585 – Christian Feuersänger May 07 '14 at 17:34

1 Answers1

11

Try to understand this code and you'll know how to draw all of them.

Start with definition of coordinates.

\coordinate (1) at (0,0,2);

creates a coordinate node (node without dimensions) named 1 at point (x,y,z)=(0,0,2). 2 means 2cm. If you need some particular unit change cm to mm, in, ... Later reference to point (0,0,2) will be done with (1). There is no need to remember its particular coordinates.

Second place circles in every coordinate and add labels to it.

    \fill (1) circle (1pt) node [below] {1};

will draw and fill a circle with radious 1pt (1 point) with center in coordinate 1. Below it a node with text 1 is placed. Because points 1 to 4 has label below and 5 to 8 has it above, it's possible to use a foreach loop.

Last, draw lines between coordinates:

\draw[dashed] (1)--(4)--(3) (4)--(8);

draws a dashed line from coordinate 1 to 4 and 3. Next places the pen on coordinate 4 and draws another line to coordinate 8.

You can use nodes (coordinates are nodes) to position other nodes. JLDiaz explained in his comments how to use calc syntax (needs \usetikzlibrary{calc} in preamble) to do it:

\coordinate (17) at ($(1)!.5!(5)$);

defines a new coordinate 17 on "the point in the line (1)-(5) which is at 50% of the distance from (1)" (the !.5! means that 50%). One you have coordinate 17 defined you can apply again \fill (17) circle (1pt) node [left] {17}; to draw the circle and label.

An alternative syntax could be

\path (1) -- (5) coordinate[pos=0.5] (17);

which means move from 1 to 5 and in pos=0.5 from this path place a coordinate node named 17. This syntax doesn't use calc library.

As an exercice: What do you think \coordinate (27) at ($(1)!.5!(7)$); does?

Before the complete code a little suggestion. If you fill intimidated by TiKZ huge documentation, take a look at some of documents recommended in

Now the complete code

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}

\coordinate (1) at (0,0,2);
\coordinate (2) at (2,0,2);
\coordinate (3) at (2,0,0);
\coordinate (4) at (0,0,0);
\coordinate (5) at (0,2,2);
\coordinate (6) at (2,2,2);
\coordinate (7) at (2,2,0);
\coordinate (8) at (0,2,0);

\coordinate (17) at ($(1)!.5!(5)$);
\coordinate (27) at ($(1)!.5!(7)$);

\foreach \i in {1,...,4}
    \fill (\i) circle (1pt) node [below] {\i};

\foreach \i in {5,...,8}
    \fill (\i) circle (1pt) node [above] {\i};

\fill (17) circle (1pt) node [left] {17};
\fill (27) circle (1pt) node [above] {27};

\draw (1) --(2) --(3) --(7) --(6)--(5)--(8)--(7);
\draw (1)--(5) (2)--(6);
\draw[dashed] (1)--(4) --(3) (4)--(8);

\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588
  • by using the your code I just make the first and now I am try to make the 2nd figure – Micky K May 07 '14 at 15:02
  • second done :-) – Micky K May 07 '14 at 15:07
  • How i make the mid node between 1 and 2, in 4th figure? – Micky K May 07 '14 at 15:35
  • @SKKhan Interpolated coordinates. You need \usetikzlibrary{calc}, and then you can write \coordinate (5) at ($(1)!.5!(2)$);, which means "the point in the line (1)-(2) which is at 50% of the distance from (1)" (the !.5! means that 50%). – JLDiaz May 07 '14 at 15:46
  • @JLDiaz I used it but there is a problem it show me 5 between line(1)-(2) – Micky K May 07 '14 at 15:52
  • @SKKhan In my comment, \coordinate (5) ...; only defines the position of the coordinate named (5). You have to draw a dot on it, and put a node with the text {5} next to it (above, below, left, or right, as desired), as in the other coordinates in Ignasi's answer, i.e. \fill (5) circle (1pt) node[left] {5}; – JLDiaz May 07 '14 at 16:01
  • @JLDiaz 5th done :-) and now working on 6th – Micky K May 07 '14 at 16:48
  • @Tarass 6th figure, I made 9 nodes. Give me any idea about node 10. – Micky K May 08 '14 at 03:47
  • @Ignasi 6th figure, I made 9 nodes. Give me any idea about node 10. – Micky K May 08 '14 at 03:47
  • @SKKhan I've updated the answer with some explanation. Hope it helps to understand how it works. – Ignasi May 08 '14 at 06:37
  • 1
    @SKKhan: I've updated my answer here because from your comment I've didn't understood that you had opened a new question. You can include links to other questions or answers in your questions, answers or comments. Please take a look at this guide to learn how to do it. It will be easier for you to improve your questions and easier for us to help you. – Ignasi May 08 '14 at 07:53
  • I am trying to make the figure 10, 11, and 14. Still working but I can't get success – Micky K May 13 '14 at 15:25
  • @SKKhan My updated code shows you how to add points 17 and 27 to start converting figure 12 in figure 13. Just use the same code and will get all other points. – Ignasi May 13 '14 at 15:42
  • @SKKhan What's supposed to represent figures 10 and 11? A triangle? Then start from figure 5 and add its central point. If it's half cube start from figure 12 but forget some vertices. It's perspective is different but represent the same volume. – Ignasi May 13 '14 at 15:46