1

How could I create these aligned images intelligently and with millimeter dimensions?

enter image description here

I used GeoGebra to generate the code shown below.

\documentclass[border=5mm]{standalone}
\usepackage{pgf,tikz}

\begin{document}
    \begin{tikzpicture}
    \draw (0mm,0mm) ellipse (50mm and 20mm);

    \draw (150mm,0mm) circle (20mm);

    \draw (-50mm,-72.5mm)-- (50mm,-72.5mm);
    \draw (-50mm,-107.50mm)-- (50mm,-107.50mm);
    \draw (-50mm,-72.5mm)-- (-50mm,-107.50mm);
    \draw (50mm,-107.50mm)-- (50mm,-72.5mm);

    \draw (110mm,-72.5mm)-- (190mm,-72.5mm);
    \draw (110mm,-107.50mm)-- (190mm,-107.50mm);
    \draw (110mm,-72.5mm)-- (110mm,-107.50mm);
    \draw (190mm,-107.50mm)-- (190mm,-72.5mm);
    \end{tikzpicture}
\end{document}

I would like to improve the code by defining the positions of the geometries using the centers as reference. Having the center of the ellipse in position (0,0).

Dimensions do not have to be displayed. They are just for setting profile sizes.

The link in this video demonstrates what I'm trying to learn. I'm Brazilian and so it's in Portuguese.

1

You can use positioning to set the ceneter points, and then calc to draw the shapes. I have scaled it to half size to get a better fit on a normal page size, but you can get the true size by setting x=1mm,y=1mm.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}
    \begin{tikzpicture}[x=0.5mm,y=0.5mm]% Set the scale (default x and y is 1cm)
    \coordinate (a11);
    \coordinate[right=150 of a11](a12);
    \coordinate[below=90 of a11](a21);
    \coordinate[right=150 of a21](a22);
    %% 
    \draw[ultra thick] (a11) circle (50 and 20);
    \draw[dash dot] ($(a11)-(50+10,0)$) -- +($2*(50+10,0)$);
    \draw[dash dot] ($(a11)-(0,20+10)$) -- +($2*(0,20+10)$);
    %% 
    \draw[ultra thick] (a12) circle (20);
    \draw[dash dot] ($(a12)-(20+10,0)$) -- +($2*(20+10,0)$);
    \draw[dash dot] ($(a12)-(0,20+10)$) -- +($2*(0,20+10)$);
    %% 
    \draw[ultra thick] ($(a21)-(50,17.5)$) rectangle +(50*2,17.5*2);
    \draw[dash dot] ($(a21)-(50+10,0)$) -- +($2*(50+10,0)$);
    \draw[dash dot] ($(a21)-(0,17.5+10)$) -- +($2*(0,17.5+10)$);
    %%
    \draw[ultra thick,rounded corners=8] ($(a22)-(50,17.5)$) rectangle +(50*2,17.5*2);
    \draw[dash dot] ($(a22)-(50+10,0)$) -- +($2*(50+10,0)$);
    \draw[dash dot] ($(a22)-(0,17.5+10)$) -- +($2*(0,17.5+10)$);
    \end{tikzpicture}
\end{document}

j

| improve this answer | |
4

Here's a start.

  • There is a lot of unnecessary stuff (for a MWE) in your example (\pagestyle{empty} and the strange color definitions and -5.428299960530308 for example).
  • Did you generate the code with another software?
  • I removed everything and use article as the "better" MWE document class for most cases.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}

\begin{document}

\begin{tikzpicture}[node distance=30mm]
\node[circle,draw,minimum width = 20mm,anchor=center] (n1) {Circle};
\node[ellipse,draw,minimum width = 20mm,minimum height = 10mm,anchor=center,below=20mm of n1] (n2) {Ellipse};
\node[rectangle,draw,minimum width = 20mm,minimum height = 10mm,anchor=center,right=20mm of n2] (n3) {Rectangle};
\end{tikzpicture}

\end{document}

enter image description here

| improve this answer | |
  • Maybe add this information to your question. You claim to have generated a minimal example which I strongly disagree. – Dr. Manuel Kuehner Jul 17 '17 at 22:22
  • I'm a beginner and I did not even know how to start. To have at least one minimal example, I had to do against it. – LCarvalho Jul 17 '17 at 22:25
  • Still, just tell that the people here in your question: "I used GeoGebra to generate the code shown below." This is independent of if you are a beginner or not. I tried to understand the code first which was a waste of time. – Dr. Manuel Kuehner Jul 17 '17 at 22:28
  • I only ask to mention that you used GeoGebra to generate the code. Nothing else. – Dr. Manuel Kuehner Jul 18 '17 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.