#Join points in a (irregular) lattice using tikz?

1 messages · Page 1 of 1 (latest)

sleek meteor
#

I am trying to make the attached figure, which is meant to represent a cystal with and edge dislocation. The dots are the atoms and, of course, i would like to draw lines between them to represent the bonds. However i am struggling to do this.
What i did is (probably not the most optimal thing) since the lattice is irregular only on one half of the diagram, i split it in two parts and my code looks like this:

\documentclass[tikz]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}


\begin{document}
    \begin{tikzpicture}
    \draw [->,thick] (-3.5,0)--(3.5,0) node [above] {$x$};
    \draw [->,thick] (0,-3.5) -- (0,3.5) node [right] {$y$};
    
    
    \foreach \x in {-3,...,3.}{
    \foreach \y in {0,...,3}{
    \draw [fill=white] (\x,\y) circle [radius=0.05];
    }
    }
    
    \foreach \d in {0.1,0.2,0.3} {
    \foreach \x in {{-3+\d},{-2+\d+0.1},{-1+\d+0.2},{1-\d-0.2},{2-\d-0.1},{3-\d}} {
    \draw [fill=white] (\x,{-10*\d}) circle [radius=0.05];}
    }
    
    \draw [dashed] (-0.15,-0.15) -- (0.15,-0.15) -- (0.15,3.15) -- (-0.15,3.15) -- cycle;
    

    \end{tikzpicture}
\end{document}

But i simply don't know and can't find how to make the bonds in a loop. Is there a way i can do that, or a package that may help? Or do i just suffer and do the lines one by one and that's it?

A less important question, but now that i'm at it ill make it too, notice in the \foreach \d loop, i want to loop on \d and \y at the same time, one value of \d per value of \y, but i don't know how to do that, in this case i could just work with y=-10d but is there a way i can iterate in 2 variables from 2 different lists?

final sableBOT
#

Cheese gaming
Compile Error! Click the errors reaction for more information.
(You may edit your message to recompile.)

prime sparrow
#

On looping two variables at once:

\begin{tikzpicture}
\foreach \x/\y in {0.1/0.1, 0.2/0.5, 0.3/0.85, 0.4/0.96, 0.5/0.975, 0.6/0.98}{\node[draw, circle, radius = 1pt] at (\x, \y) {};}
\end{tikzpicture}

It's possible

final sableBOT
prime sparrow
#

Show us how you want the final thing to look like, if you can

prime sparrow
# sleek meteor I am trying to make the attached figure, which is meant to represent a cystal wi...

I came up with something like this:

\begin{tikzpicture}
        \draw [->,thick] (-3.5,0)--(3.5,0) node [above] {$x$};
        \draw [->,thick] (0,-3.5) -- (0,3.5) node [right] {$y$};
        
        
        \foreach \x in {-3,...,3}{
        \foreach \y in {0,...,3}{
            \draw [fill=white] (\x, \y) circle [radius=0.05];
            % \d calculation
            \ifnum\y>0
            \ifnum\x>0 
                \draw[fill=white] ({\x - \y/10 - (3 - \x)/10}, -\y) circle [radius=0.05];
            \else\ifnum\x<0
                \draw[fill=white] ({\x + \y/10 + (3 + \x)/10}, -\y) circle [radius=0.05];
                \fi
            \fi\fi
        }
    }
        
        \draw [dashed] (-0.15,-0.15) -- (0.15,-0.15) -- (0.15,3.15) -- (-0.15,3.15) -- cycle;
\end{tikzpicture}
final sableBOT
sleek meteor
#

Thanks for the help on the loop also, I'm not too familiar with tikz yet so i didn't know that

sleek meteor
quiet tide
#

Pretty sure it's the end of the if statement, like in some other programming languages. And I think you could achieve the connecting lines with foreach to loop through all of those atoms in a quick manner. Something like this probably, but I'm no expert in TikZ and it might not work as easily for an asymmetrical grid like yours.

prime sparrow
#

one for checking if Y > 0, one for X > 0 and the other for X < 0

#

hence three \fi's

sleek meteor
#

Ok I see thanks