TikZ learning note cycle

Write in front Upper section( TikZ learning notes (I) basic graphics _zorchpcsdn blog )We said Ti k Z \textk\text TikZ's...
Bisection of line segments
Marking of drawings
Write in front

Upper section( TikZ learning notes (I) basic graphics _zorchpcsdn blog )We said Ti k Z \textk\text TikZ's simple graphic drawing method. This time, let's learn about the use of circular statements (foreach...in...) in graphics. With this powerful tool, we can pass Ti k Z \textk\text TikZ can easily and quickly generate many exquisite vector graphs

P.S. for different types of graphics, many bosses have encapsulated some useful macro packages, such as plane geometry drawing package tikz Euclide. Using this package to draw common graphics of plane geometry is better than using it directly Ti k Z \textk\text TikZ is much simpler, but it is recommended to study it first Ti k Z \textk\text TikZ, because these other packages are based on Ti k Z \textk\text TikZ} secondary development, which is also a simple understanding of "so ran"

Preparatory knowledge

Before introducing loops, let's introduce some basic drawing knowledge points, which are also very important, especially when used in the following examples

Bisection of line segments

Let's introduce it first Ti k Z \textk\text calc, a sub package of TikZ , needs to add \ usetikzlibrary in the preamble to use the command of line segment bisection

The defau lt calling format is ($(starting point of line segment)! < proportion > (ending point of line segment) $), which is easy to understand. For example, the following statement divides line segment AB equally, and the dividing point takes D

\documentclass[tikz,border=3pt] \usetikzlibrary \begin \begin[] % Mark point A, B, C \coordinate[label=left:{$A$}] (A) at (0,2); \coordinate[label=right:{$B$}] (B) at (5,2); % Draw line segments AB \draw (A) -- (B); % line bisection , The parameter in the middle can be 0~1 Number between, Take it here`.5` \coordinate[label=below:{$D$}] (D) at ($(A)!.5!(B)$); % Fill with red circles D spot \filldraw[red] (D) circle (1pt); \end \end

Similarly, if you need to take the split point of AD, you can add the following two commands:

\coordinate[label=below:{$E$}] (E) at ($(A)!.25!(B)$); \filldraw[green] (E) circle (1pt);

Marking of drawings

In the previous section, we drew basic graphics, but for each graphics, it exists independently. In order to understand the graphics intersection after this section, we need to know the graphics marking

For a straight line (line segment), the marking is still very simple. Just add \ abel to the parameter when drawing the straight line

Cycle (pgfmanual-chap88)

Adobe illustrator(AI), a very popular vector graph drawing software, can create vector graphs directly with the mouse, but when a lot of repetitive work is encountered, Ti k Z \textk\text The foreach statement in TikZ can give full play to its power. The following is a small example. This example is what I learned before Ti k Z \textk\text The first drawing of the ruler and gauge drawing series drawn by TikZ, TikZ drawing example - ruler and gauge drawing: arbitrary bisection of line segments_ Zorchp CSDN blog.

For the loop, we first introduce its main format, namely

\foreach \i in {...} { ... }

The first ellipsis can be defined in the following way, that is, the start value, the second value,..., and the end value, (the second value can not be written, and the default is 1) is equivalent to the definition of the for loop statement in C + +, which requires three parameters to generate the loop variable

The following are some values generated by \ foreach, which are available in pgfmanual to deepen your understanding of \ foreach

\foreach \x in {\x, } yields 1, 2, 3, 4, 5, 6, \foreach \x in {\x, } yields 1, 2, 3, 4, 5, 6, \foreach \x in {\x, } yields 1, 3, 5, 7, 9, 11, \foreach \x in {\x, } yields 1, 3, 5, 7, 9, \foreach \x in {\x, } yields 0, 0.1, 0.20001, 0.30002, 0.40002, \foreach \x in {\x, } yields a, b, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 2.125, 2.25, 2.375, 2.5, \foreach \x in {\x, } yields 1, 2, 3, 4, 5, 6, \foreach \x in {\x, } yields 9, 8, 7, 6, 5, 4, \foreach \x in {\x, } yields a, b, c, d, e, f, g, h, i, j, k, l, m, \foreach \x in {\x, } yields Z, X, V, T, R, P, N, \foreach \x in {$\x$, } yields 21, 22, 23, 24, 25, 26, 27, \foreach \x in {$\x$, } yields 0π, 0.5π, 1π, 1.5π, 2π, 2.5π, 3π, \foreach \x in {$\x$, } yields A1, B1, C1, D1, E1, F1, G1, H1,

The following is a small example for drawing a coordinate axis

\documentclass[tikz,border=3pt] \begin \begin % Draw mesh \draw[gray!50, thin] (-2,-2) grid (10,10); % Draw arrow \draw[-latex] (-3,0) -- (11,0); \draw[-latex] (0,-3) -- (0,11); % Mark points and label \coordinate [label=below:$x$] (x) at (11,0); \coordinate [label=right:$y$] (y) at (0,11); \coordinate [label=below left:$O$] (O) at (0,0); % Start drawing scale \foreach \i in { % Mark scale: label To customize the font color \coordinate [label={[red] below right:$\i$}] (x\i) at (\i-.1,0); \coordinate [label={[green] below left:$\i$}] (y\i) at (0,\i+.1); % Fill with small ellipses \filldraw (\i,0) ellipse (.5pt and 1pt); \filldraw (0,\i) ellipse (1pt and .5pt); } \end \end

An example

The simplest drawing in the ruler and gauge drawing series is explained as an example

\documentclass[tikz,border=3pt] \usetikzlibrary \begin \begin[] % Mark point A, B, C \coordinate[label=left:{$A$}] (A) at (0,2); \coordinate[label=right:{$B$}] (B) at (5,2); \coordinate[label=below right:{$C$}] (C) at (5,0); % Draw line segments AB, AC \draw (A) -- (B); \draw (A) -- (C); % Bisector AC \foreach \i in { \coordinate[label=below:{$\i'$}] (a\i) at ($(A)!\i/5!(4.5,.2)$); \coordinate[label=above:{$\i$}] (b\i) at ($(A)!\i/5!(B)$); \draw (a\i) -- (b\i); } \end \end

18 November 2021, 21:16 | Views: 8646

Add new comment

For adding a comment, please log in
or create account

0 comments