first steps with 3-D drawings

View: New views
3 Messages — Rating Filter:   Alert me  

first steps with 3-D drawings

by Goebel, Juergen, OPES27 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

first steps with 3-D drawings

Hi,

I'm trying to do first steps with creating three-dimensional drawings
with pgf/TikZ. My first attempt was Sketch, but I really need curves,
circles and so on (while the graphs are quite simple at all).

My next step are currently the examples shown on Kjell's great
TikZ-page. Here arouses the following question. When analyzing
the example 3d-graph-model.tex by Andreas Menge I tried to
integrate a circle. But it seems that the pgftransformcm and my
definition of the circle (in line 62) don't harmonize. I'd really appreciate
it if someone can give me a hint where my mistake is.

Regards,

Juergen





% Author: Andreas Menge
\documentclass[10pt]{article}
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{comment}
:Title: A simple graph-model in 3D
:slug: 3d-graph-model

A simple graph-model in 3D with a helping grid but not with a rotation of 45 degrees to avoid overlapping edges. The graph lines are drawn with a white background to visualize the ones closer to the viewer and hence improve the 3D-view. Code duplication is reduced.

\end{comment}

%transforms all coordinates the same way when used (use it within a scope!)
%(rotation is not 45 degress to avoid overlapping edges)
% Input: point of origins x and y coordinate
\newcommand{\myGlobalTransformation}[2]
{
    \pgftransformcm{1}{0}{0.4}{0.5}{\pgfpoint{#1cm}{#2cm}}
}

% draw a 4x4 helper grid in 3D
% Input: point of origins x and y coordinate and additional drawing-parameters
\newcommand{\gridThreeD}[3]
{
    \begin{scope}
        \myGlobalTransformation{#1}{#2};
        \draw [#3,step=2cm] grid (8,8);
    \end{scope}
}

\tikzstyle myBG=[line width=3pt,opacity=1.0]

% draws lines with white background to show which lines are closer to the
% viewer (Hint: draw from bottom up and from back to front)
%Input: start and end point
\newcommand{\drawLinewithBG}[2]
{
    \draw[white,myBG]  (#1) -- (#2);
    \draw[black,very thick] (#1) -- (#2);
}

% draws all horizontal graph lines within grid
\newcommand{\graphLinesHorizontal}
{
    \drawLinewithBG{1,1}{7,1};
    \drawLinewithBG{1,3}{7,3};
    \drawLinewithBG{1,5}{7,5};
    \drawLinewithBG{1,7}{7,7};
%    \fill[red,opacity=0.5] (4,4) circle (1.5cm);
}

% draws all vertical graph lines within grid
\newcommand{\graphLinesVertical}
{
    %swaps x and y coordinate (hence vertical lines):
    \pgftransformcm{0}{1}{1}{0}{\pgfpoint{0cm}{0cm}}
    \fill[red,opacity=0.5] (2,2) circle (1.5cm); <--- this circle isn't transformed <--- <--- <---
    \graphLinesHorizontal;
}

%draws nodes of the grid
%Input: point of origins x and y coordinate
\newcommand{\graphThreeDnodes}[2]
{
    \begin{scope}
        \myGlobalTransformation{#1}{#2};
        \foreach \x in {1,3,5,7} {
            \foreach \y in {1,3,5,7} {
                \node at (\x,\y) [circle,fill=black] {};
                %this way circle of nodes will not be transformed
            }
        }
    \end{scope}
}


\begin{document}
\pagestyle{empty}


\begin{tikzpicture}

    %draws helper-grid:
    \gridThreeD{0}{0}{black!50};
    \gridThreeD{0}{4.25}{black!50};

    %draws lower graph lines and those in z-direction:
    \begin{scope}
        \myGlobalTransformation{0}{0};
        \graphLinesHorizontal;

        %draws all graph lines in z-direction (reset transformation first!):
        \foreach \x in {1,3,5,7} {
            \foreach \y in {1,3,5,7} {
                \node (thisNode) at (\x,\y) {};
                {
                    \pgftransformreset
                    \draw[white,myBG]  (thisNode) -- ++(0,4.25);
                    \draw[black,very thick] (thisNode) -- ++(0,4.25);
                }
            }
        }
    \end{scope}

    %draws upper graph-lines:
    \begin{scope}
        \myGlobalTransformation{0}{4.25};
        \graphLinesVertical;
    \end{scope}

    % draws all graph nodes:
    \graphThreeDnodes{0}{0};
    \graphThreeDnodes{0}{4.25};

\end{tikzpicture}

\end{document}


------------------------------------------------------------------------------

_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Re: first steps with 3-D drawings

by Rafaelmx :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Goebel, Juergen" <juergen.goebel@...> writes:

> My next step are currently the examples shown on Kjell's great
> TikZ-page. Here arouses the following question. When analyzing the
> example 3d-graph-model.tex by Andreas Menge I tried to integrate a
> circle. But it seems that the pgftransformcm and my definition of the
> circle (in line 62) don't harmonize. I'd really appreciate it if
> someone can give me a hint where my mistake is.

I typeset the file, and I don't see what you mean by "don't
harmonize". Maybe it would help if you try to explain it. Also it would
help if you reduce the example to some really minimal elements.
Best regards.



------------------------------------------------------------------------------
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Re: first steps with 3-D drawings

by Goebel, Juergen, OPES27 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Rafael wrote:

> I typeset the file, and I don't see what you mean by "don't
> harmonize". Maybe it would help if you try to explain it.
> Also it would
> help if you reduce the example to some really minimal elements.
> Best regards.

Ok, let me try it again. During the weekend I played a bit with
TikZ. So my question changes to ...

When pdfLaTeXing the following example the text isn't transformed.
Of course I can achieve this manually with xslant and yslant, but
this is far from being elegant. I'm quite sure that there is a
better way. What do I have to do?

Greetings,

Juergen




\documentclass[10pt]{article}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%

\newcommand{\cubeface}[2]{%
  \fill[#1,opacity=0.25] (1,1) circle (1cm);
  \draw[miter limit=1] (0,0) rectangle (2,2);
  \draw[#1!50,thin,shorten >= 3pt,shorten <= 3pt] (0,0) -- (2,2);
  \draw[#1!50,thin,shorten >= 3pt,shorten <= 3pt] (0,2) -- (2,0);
  \path (1,1) node[font=\small\bfseries,text=#1!50!black] {#2};
}

\begin{document}
 \begin{tikzpicture}
  \pgftransformcm{1}{0}{0.4}{0.5}{\pgfpoint{0cm}{0cm}}
  \cubeface{blue}{unten}
  \pgftransformreset
  \pgftransformcm{1}{0}{0}{1}{\pgfpoint{0.8cm}{1cm}}
  \cubeface{red}{hinten}
  \pgftransformreset
  \pgftransformcm{0.4}{0.5}{0}{1}{\pgfpoint{0cm}{0cm}}
  \cubeface{red}{links}
  \pgftransformreset
  \pgftransformcm{0.4}{0.5}{0}{1}{\pgfpoint{2cm}{0cm}}
  \cubeface{red}{rechts}
  \pgftransformreset
  \cubeface{red}{vorn}
  \pgftransformcm{1}{0}{0.4}{0.5}{\pgfpoint{0cm}{2cm}}
  \cubeface{green}{oben}
 \end{tikzpicture}
\end{document}

------------------------------------------------------------------------------
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users