4

I'd like to draw crystal structures using TikZ-3Dplot'''. I saw that solutions exist with Asymptote, but for some reason, I can't install it (and I admit I had trouble understanding how the package works).

I started with TikZ 3D Plot, which seems to work.

I just have one question: I can't keep some lines horizontal, which I find unsightly (I've tried several angle values ​​in the command \tdplotsetmaincoords, but without success).

crystal

\documentclass{standalone}
\usepackage{tikz,tikz-3dplot}
\usepackage{xcolor}

\begin{document}    
        
        \tdplotsetmaincoords{75}{10}
        \begin{tikzpicture}[tdplot_main_coords, scale = 5]
                
            
            % ---- Tracé des traits du réseau ----
            \draw[thin] (0,0,0) -- (1,0,0) -- (1,1,0) -- (0,1,0) -- (0,0,0);
            \draw[thin] (0,0,1) -- (1,0,1) -- (1,1,1) -- (0,1,1) -- (0,0,1);
            \draw[thin] (0,0,0) -- (0,0,1);
            \draw[thin] (1,0,0) -- (1,0,1);
            \draw[thin] (1,1,0) -- (1,1,1);
            \draw[thin] (0,1,0) -- (0,1,1);


            \tdplottransformmainscreen{0}{0}{0}
            \shadedraw[tdplot_screen_coords, ball color = blue] (\tdplotresx,\tdplotresy) circle (0.10);
        \end{tikzpicture}
    

\end{document}
1
  • 1
    It’s an orthographic projection of an orthogonal basis. You will be unable to get them horizontal in most cases. Commented 22 hours ago

1 Answer 1

8

Replace \begin{tikzpicture}[tdplot_main_coords, scale = 5]

by \begin{tikzpicture}[x={(0:1cm)},y={(30:0.5cm)},z={(90:1cm)},scale = 5].

Code:

\documentclass{standalone}
\usepackage{tikz,tikz-3dplot}
\usepackage{xcolor}

\begin{document}    
        
        \tdplotsetmaincoords{75}{10}
        \begin{tikzpicture}[x={(0:1cm)},y={(30:0.5cm)},z={(90:1cm)},scale = 5]
                
            
            % ---- Tracé des traits du réseau ----
            \draw[thin] (0,0,0) -- (1,0,0) -- (1,1,0) -- (0,1,0) -- (0,0,0);
            \draw[thin] (0,0,1) -- (1,0,1) -- (1,1,1) -- (0,1,1) -- (0,0,1);
            \draw[thin] (0,0,0) -- (0,0,1);
            \draw[thin] (1,0,0) -- (1,0,1);
            \draw[thin] (1,1,0) -- (1,1,1);
            \draw[thin] (0,1,0) -- (0,1,1);


            \tdplottransformmainscreen{0}{0}{0}
            \shadedraw[tdplot_screen_coords, ball color = blue] (\tdplotresx,\tdplotresy) circle (0.10);
        \end{tikzpicture}
    

\end{document}

For comparison, at left, your original code, at right, the corrected code:

output comparison

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.