Debian Codegraph @

texmf-dist/doc/latex/tkz-euclide/TKZdoc-euclide-clipping.tex

raw
1 \section{Controlling Bounding Box}
2 From the \tkzimp{PgfManual} :
3
4 "When you add the clip option, the current path is used for clipping subsequent drawings. Clipping never enlarges the clipping area. Thus, when you clip against a certain path and then clip again against another path, you clip against the intersection of both.
5 The only way to enlarge the clipping path is to end the {pgfscope} in which the clipping was done. At the end of a {pgfscope} the clipping path that was in force at the beginning of the scope is reinstalled."
6
7
8 First of all, you don't have to deal with \TIKZ\ the size of the bounding box. Early versions of \tkzNamePack{tkz-euclide} did not control the size of the bounding box, now with \tkzNamePack{\tkznameofpack} 4 the size of the bounding box is limited.
9
10 The initial bounding box after using the macro \tkzcname{tkzInit} is defined by the rectangle based on the points $(0,0)$ and $(10,10)$. The \tkzcname{tkzInit} macro allows this initial bounding box to be modified using the arguments (\tkzname{xmin}, \tkzname{xmax}, \tkzname{ymin}, and \tkzname{ymax}). Of course any external trace modifies the bounding box. \TIKZ\ maintains that bounding box. It is possible to influence this behavior either directly with commands or options in \TIKZ\ such as a command like \tkzcname{useasboundingbox} or the option \tkzname{use as bounding box}. A possible consequence is to reserve a box for a figure but the figure may overflow the box and spread over the main text.
11 The following command \tkzcname{pgfresetboundingbox} clears a bounding box and establishes a new one.
12
13 \subsection{Utility of \tkzcname{tkzInit}}
14 However, it is sometimes necessary to control the size of what will be displayed.
15 To do this, you need to have prepared the bounding box you are going to work in, this is the role of the macro \tkzNameMacro{tkzInit}. For some drawings, it is interesting to fix the extreme values (xmin,xmax,ymin and ymax) and to \code{clip} the definition rectangle in order to control the size of the figure as well as possible.
16
17 The two macros that are useful for controlling the bounding box:
18 \begin{itemize}
19 \item \tkzcname{tkzInit}
20 \item \tkzcname{tkzClip}
21 \end{itemize}
22 \vspace{20pt}
23
24 To this, I added macros directly linked to the bounding box. You can now view it, backup it, restore it (see the section Bounding Box).
25
26 \subsection{\tkzcname{tkzInit}}
27
28 \begin{NewMacroBox}{tkzInit}{\oarg{local options}}\hypertarget{init}{}%
29 \begin{tabular}{lll}%
30 options & default & definition \\
31 \midrule
32 \TOline{xmin} {0} {minimum value of the abscissae in cm}
33 \TOline{xmax} {10} {maximum value of the abscissae in cm}
34 \TOline{xstep}{1} {difference between two graduations in $x$}
35 \TOline{ymin} {0} {minimum y-axis value in cm }
36 \TOline{ymax} {10} {maximum y-axis value in cm}
37 \TOline{ystep}{1} {difference between two graduations in $y$}
38 \bottomrule
39 \end{tabular}
40
41 \medskip
42
43 The role of \tkzcname{tkzInit} is to define a \textcolor{red}{orthogonal} coordinates system and a rectangular part of the plane in which you will place your drawings using Cartesian coordinates.
44 This macro allows you to define your working environment as with a calculator. With \tkzname{\tkznameofpack} 4 \tkzcname{xstep} and \tkzcname{ystep} are always 1. Logically it is no longer useful to use \tkzcname{tkzInit}, except for an action like \code{Clipping Out}.
45 \end{NewMacroBox}
46
47
48 \subsection{\tkzcname{tkzClip}}
49
50 \begin{NewMacroBox}{tkzClip}{\oarg{local options}}
51 The role of this macro is to make invisible what is outside the rectangle defined by (xmin~;~ymin) and (xmax~;~ymax).
52
53 \medskip
54 \begin{tabular}{lll}
55 \hline
56 options & default & definition \\
57 \midrule
58 \TOline{space} {1} {added value on the right, left, bottom and top of the background}
59 \bottomrule
60 \end{tabular}
61
62 \medskip
63
64 The role of the \tkzname{space} option is to enlarge the visible part of the drawing. This part becomes the rectangle defined by (xmin-space~;~ymin-space) and (xmax+space~;~ymax+space). \tkzname{space} can be negative! The unit is cm and should not be specified.
65 \end{NewMacroBox}
66
67
68
69 The role of this macro is to \code{clip} the initial rectangle so that only the paths contained in this rectangle are drawn.
70
71 \begin{tkzexample}[latex=8cm,small]
72 \begin{tikzpicture}
73 \tkzInit[xmax=4, ymax=3]
74 \tkzDefPoints{-1/-1/A,5/2/B}
75 \tkzDrawX \tkzDrawY
76 \tkzGrid
77 \tkzClip
78 \tkzDrawSegment(A,B)
79 \end{tikzpicture}
80 \end{tkzexample}
81
82 It is possible to add a bit of space
83 \begin{tkzltxexample}[]
84 \tkzClip[space=1]
85 \end{tkzltxexample}
86
87 \subsection{\tkzcname{tkzClip} and the option \tkzname{space}}
88 This option allows you to add some space around the \code{clipped} rectangle.
89 \begin{tkzexample}[latex=8cm,small]
90 \begin{tikzpicture}
91 \tkzInit[xmax=4, ymax=3]
92 \tkzDefPoints{-1/-1/A,5/2/B}
93 \tkzDrawX \tkzDrawY
94 \tkzGrid
95 \tkzClip[space=1]
96 \tkzDrawSegment(A,B)
97 \end{tikzpicture}
98 \end{tkzexample}
99 The dimensions of the \code{clipped} rectangle are \tkzname{xmin-1}, \tkzname{ymin-1}, \tkzname{xmax+1} and \tkzname{ymax+1}.
100
101 %<--------------------------------------------------------------------------->
102 % tkzShowBB
103 %<--------------------------------------------------------------------------->
104 \subsection{tkzShowBB}
105 The simplest macro.
106 \begin{NewMacroBox}{tkzShowBB}{\oarg{local options}}%
107 This macro displays the bounding box. A rectangular frame surrounds the bounding box. This macro accepts \TIKZ\ options.
108 \end{NewMacroBox}
109
110
111 \subsubsection{Example with \tkzcname{tkzShowBB}}
112 \begin{tkzexample}[latex=8cm,small]
113 \begin{tikzpicture}[scale=.5]
114 \tkzInit[ymax=5,xmax=8]
115 \tkzGrid
116 \tkzDefPoint(3,0){A}
117 \begin{scope}
118 \tkzClipBB
119 \tkzDefCircle[R](A,5) \tkzGetPoint{a}
120 \tkzDrawCircle(A,a)
121 \tkzShowBB[line width = 4pt,fill=teal!10,%
122 opacity=.4]
123 \end{scope}
124 \tkzDefCircle[R](A,4) \tkzGetPoint{b}
125 \tkzDrawCircle[red](A,b)
126 \end{tikzpicture}
127 \end{tkzexample}
128 %<--------------------------------------------------------------------------->
129 % tkzClipBB
130 %<--------------------------------------------------------------------------->
131 \subsection{tkzClipBB}
132 \begin{NewMacroBox}{tkzClipBB}{}%
133 The idea is to limit future constructions to the current bounding box.
134 \end{NewMacroBox}
135
136 \subsubsection{Example with \tkzcname{tkzClipBB} and the bisectors}
137
138 \begin{tkzexample}[latex=6cm,small]
139 \begin{tikzpicture}
140 \tkzInit[xmin=-3,xmax=6, ymin=-1,ymax=6]
141 \tkzDefPoint(0,0){O}\tkzDefPoint(3,1){I}
142 \tkzDefPoint(1,4){J}
143 \tkzDefLine[bisector](I,O,J) \tkzGetPoint{i}
144 \tkzDefLine[bisector out](I,O,J) \tkzGetPoint{j}
145 \tkzDrawPoints(O,I,J,i,j)
146 \tkzClipBB
147 \tkzDrawLines[add = 1 and 2,color=orange](O,I O,J)
148 \tkzDrawLines[add = 1 and 2](O,i O,j)
149 \tkzShowBB
150 \end{tikzpicture}
151 \end{tkzexample}
152
153
154 \newpage
155
156 \section{Clipping different objects}
157
158 \subsection{Clipping a polygon}
159 \begin{NewMacroBox}{tkzClipPolygon}{\oarg{local options}\parg{points list}}%
160 This macro makes it possible to contain the different plots in the designated polygon.
161
162 \medskip
163 \begin{tabular}{lll}%
164 \toprule
165 arguments & example & explanation \\
166 \midrule
167 \TAline{\parg{pt1,pt2,pt3,\dots}}{\parg{A,B,C}}{}
168 \midrule
169 options & default & definition \\
170 \midrule
171 \TOline{out} {} {allows to clip the outside of the object}
172 \end{tabular}
173 \end{NewMacroBox}
174
175 \subsubsection{\tkzcname{tkzClipPolygon}}
176
177 \begin{tkzexample}[latex=7cm,small]
178 \begin{tikzpicture}[scale=1.25]
179 \tkzDefPoint(0,0){A}
180 \tkzDefPoint(4,0){B}
181 \tkzDefPoint(1,3){C}
182 \tkzDrawPolygon(A,B,C)
183 \tkzDefPoint(0,2){D}
184 \tkzDefPoint(2,0){E}
185 \tkzDrawPoints(D,E)
186 \tkzLabelPoints(D,E)
187 \tkzClipPolygon(A,B,C)
188 \tkzDrawLine[new](D,E)
189 \end{tikzpicture}
190 \end{tkzexample}
191
192 \subsubsection{\tkzcname{tkzClipPolygon[out]}}
193
194 \begin{tkzexample}[latex=7cm,small]
195 \begin{tikzpicture}[scale=1]
196 \tkzDefPoint(0,0){P1}
197 \tkzDefPoint(4,0){P2}
198 \tkzDefPoint(4,4){P3}
199 \tkzDefPoint(0,4){P4}
200 \tkzDefPoint(1,1){Q1}
201 \tkzDefPoint(3,1){Q2}
202 \tkzDefPoint(3,3){Q3}
203 \tkzDefPoint(1,3){Q4}
204 \tkzDrawPolygon(P1,P2,P3,P4)
205 \begin{scope}
206 \tkzClipPolygon[out](Q1,Q2,Q3,Q4)
207 \tkzFillPolygon[teal!20](P1,P2,P3,P4)
208 \end{scope}
209 \tkzDrawPolygon(Q1,Q2,Q3,Q4)
210 \end{tikzpicture}
211 \end{tkzexample}
212
213 \subsubsection{Example: use of \code{Clip} for Sangaku in a square}
214 \begin{tkzexample}[latex=7cm, small]
215 \begin{tikzpicture}[scale=.75]
216 \tkzDefPoint(0,0){A} \tkzDefPoint(8,0){B}
217 \tkzDefSquare(A,B) \tkzGetPoints{C}{D}
218 \tkzDefPoint(4,8){F}
219 \tkzDefTriangle[equilateral](C,D)
220 \tkzGetPoint{I}
221 \tkzDefPointBy[projection=onto B--C](I)
222 \tkzGetPoint{J}
223 \tkzInterLL(D,B)(I,J) \tkzGetPoint{K}
224 \tkzDefPointBy[symmetry=center K](B)
225 \tkzGetPoint{M}
226 \tkzClipPolygon(B,C,D,A)
227 \tkzFillPolygon[color = orange](A,B,C,D)
228 \tkzFillCircle[color = yellow](M,I)
229 \tkzFillCircle[color = blue!50!black](F,D)
230 \end{tikzpicture}
231 \end{tkzexample}
232
233 \subsection{Clipping a disc}
234
235 \begin{NewMacroBox}{tkzClipCircle}{\oarg{local options}\parg{A,B}}%
236 \begin{tabular}{lll}%
237 \toprule
238 arguments & example & explanation \\
239 \midrule
240 \TAline{\parg{A,B}}{\parg{A,B}} {AB radius}
241 \bottomrule
242 \end{tabular}
243
244 \medskip
245 \begin{tabular}{lll}%
246 options & default & definition \\
247 \midrule
248 \TOline{out} {} {allows to clip the outside of the object}
249 \bottomrule
250 \end{tabular}
251
252 \medskip
253 It is not necessary to put \tkzname{radius} because that is the default option.
254 \end{NewMacroBox}
255
256 \subsubsection{Simple clip}
257 \begin{tkzexample}[latex=6cm,small]
258 \begin{tikzpicture}[scale=.5]
259 \tkzDefPoint(0,0){A} \tkzDefPoint(2,2){O}
260 \tkzDefPoint(4,4){B} \tkzDefPoint(5,5){C}
261 \tkzDrawPoints(O,A,B,C)
262 \tkzLabelPoints(O,A,B,C)
263 \tkzDrawCircle(O,A)
264 \tkzClipCircle(O,A)
265 \tkzDrawLine(A,C)
266 \tkzDrawCircle[fill=teal!10,opacity=.5](C,O)
267 \end{tikzpicture}
268 \end{tkzexample}
269
270 \subsection{Clip out}
271
272 \begin{tkzexample}[latex=6cm,small]
273 \begin{tikzpicture}
274 \tkzInit[xmin=-3,ymin=-2,xmax=4,ymax=3]
275 \tkzDefPoint(0,0){O}
276 \tkzDefPoint(-4,-2){A}
277 \tkzDefPoint(3,1){B}
278 \tkzDefCircle[R](O,2) \tkzGetPoint{o}
279 \tkzDrawPoints(A,B) % to have a good bounding box
280 \begin{scope}
281 \tkzClipCircle[out](O,o)
282 \tkzDrawLines(A,B)
283 \end{scope}
284 \end{tikzpicture}
285 \end{tkzexample}
286
287 \subsection{Intersection of disks}
288
289 \begin{tkzexample}[latex=6cm,small]
290 \begin{tikzpicture}
291 \tkzDefPoints{0/0/O,4/0/A,0/4/B}
292 \tkzDrawPolygon[fill=teal](O,A,B)
293 \tkzClipPolygon(O,A,B)
294 \tkzClipCircle(A,O)
295 \tkzClipCircle(B,O)
296 \tkzFillPolygon[white](O,A,B)
297 \end{tikzpicture}
298 \end{tkzexample}
299
300 see a more complex example about clipping here : \ref{About clipping circles}
301
302 \subsection{Clipping a sector}
303 \tkzHandBomb\ Attention the arguments vary according to the options.
304 \begin{NewMacroBox}{tkzClipSector}{\oarg{local options}\parg{O,\dots}\parg{\dots}}%
305 \begin{tabular}{lll}%
306 options & default & definition \\
307 \midrule
308 \TOline{towards}{towards}{$O$ is the center and the sector starts from $A$ to $(OB)$}
309 \TOline{rotate} {towards}{The sector starts from $A$ and the angle determines its amplitude. }
310 \TOline{R}{towards}{We give the radius and two angles}
311 \bottomrule
312 \end{tabular}
313
314 \medskip
315 You have to add, of course, all the styles of \TIKZ\ for tracings...
316
317 \medskip
318 \begin{tabular}{lll}%
319 \toprule
320 options & arguments & example \\
321 \midrule
322 \TOline{towards}{\parg{pt,pt}\parg{pt}}{\tkzcname{tkzClipSector(O,A)(B)}}
323 \TOline{rotate} {\parg{pt,pt}\parg{angle}}{\tkzcname{tkzClipSector[rotate](O,A)(90)}}
324 \TOline{R}{\parg{pt,$r$}\parg{angle 1,angle 2}}{\tkzcname{tkzClipSector[R](O,2)(30,90)}}
325 \end{tabular}
326 \end{NewMacroBox}
327
328 \subsubsection{Example 1}
329 \begin{tkzexample}[latex=7cm,small]
330 \begin{tikzpicture}[scale=0.5]
331 \tkzDefPoint(0,0){a}
332 \tkzDefPoint(12,0){b}
333 \tkzDefPoint(4,10){c}
334 \tkzInterCC[R](a,6)(b,8)
335 \tkzGetFirstPoint{AB1} \tkzGetSecondPoint{AB2}
336 \tkzInterCC[R](a,6)(c,6)
337 \tkzGetFirstPoint{AC1} \tkzGetSecondPoint{AC2}
338 \tkzInterCC[R](b,8)(c,6)
339 \tkzGetFirstPoint{BC1} \tkzGetSecondPoint{BC2}
340 \tkzDrawArc(a,AB2)(AB1)
341 \tkzDrawArc(b,AB1)(AB2)
342 \tkzDrawArc(a,AC2)(AC1)
343 \tkzDrawArc(c,AC1)(AC2)
344 \tkzDrawArc(b,BC2)(BC1)
345 \tkzDrawArc(c,BC1)(BC2)
346 \begin{scope}
347 \tkzClipSector(b,BC2)(BC1)
348 \tkzFillSector[teal!40!white](c,BC1)(BC2)
349 \end{scope}
350 \begin{scope}
351 \tkzClipSector(a,AB2)(AB1)
352 \tkzFillSector[teal!40!white](b,AB1)(AB2)
353 \end{scope}
354 \begin{scope}
355 \tkzClipSector(a,AC2)(AC1)
356 \tkzFillSector[teal!40!white](c,AC1)(AC2)
357 \end{scope}
358 \end{tikzpicture}
359 \end{tkzexample}
360
361 \subsubsection{Example 2}
362 \begin{tkzexample}[latex=7cm,small]
363 \begin{tikzpicture}[scale=1.5]
364 \tkzDefPoint(0,0){O}
365 \tkzDefPoint(2,-1){A}
366 \tkzDefPoint(1,1){B}
367 \tkzDrawSector[new,dashed](O,A)(B)
368 \tkzDrawSector[new](O,B)(A)
369 \begin{scope}
370 \tkzClipSector(O,B)(A)
371 \tkzDefSquare(O,B) \tkzGetPoints{B'}{O'}
372 \tkzDrawPolygon[color=teal,fill=teal!20](O,B,B',O')
373 \end{scope}
374 \tkzDrawPoints(A,B,O)
375 \end{tikzpicture}
376 \end{tkzexample}
377
378
379 \subsection{Options from \TIKZ: trim left or right}
380 See the \tkzimp{pgfmanual}
381
382 \subsection{\TIKZ\ Controls \tkzcname{pgfinterruptboundingbox} and \tkzcname{endpgfinterruptboundingbox}}
383 This command temporarily interrupts the calculation of the box and configures a new box.
384 See the \tkzimp{pgfmanual}
385
386 \subsubsection{Example about contolling the bouding box}
387 \begin{tkzexample}[latex=7cm,small]
388 \begin{tikzpicture}
389 \tkzDefPoint(0,5){A}\tkzDefPoint(5,4){B}
390 \tkzDefPoint(0,0){C}\tkzDefPoint(5,1){D}
391 \tkzDrawSegments(A,B C,D A,C)
392 \pgfinterruptboundingbox
393 \tkzInterLL(A,B)(C,D)\tkzGetPoint{I}
394 \endpgfinterruptboundingbox
395 \tkzClipBB
396 \tkzDrawCircle(I,B)
397 \end{tikzpicture}
398 \end{tkzexample}
399
400 \subsection{Reverse clip: tkzreverseclip}
401
402 In order to use this option, a bounding box must be defined.
403
404 \begin{tkzltxexample}[]
405 \tikzset{tkzreverseclip/.style={insert path={
406 (current bounding box.south west) --(current bounding box.north west)
407 --(current bounding box.north east) -- (current bounding box.south east)
408 -- cycle} }}
409 \end{tkzltxexample}
410
411 \subsubsection{Example with \tkzcname{tkzClipPolygon[out]}}
412 \tkzcname{tkzClipPolygon[out]}, \tkzcname{tkzClipCircle[out]} use this option.
413 \begin{tkzexample}[vbox,small]
414 \begin{tikzpicture}[scale=1]
415 \tkzInit[xmin=-5,xmax=5,ymin=-4,ymax=6]
416 \tkzClip
417 \tkzDefPoints{-.5/0/P1,.5/0/P2}
418 \foreach \i [count=\j from 3] in {2,...,7}{%
419 \tkzDefShiftPoint[P\i]({45*(\i-1)}:1){P\j}}
420 \tkzClipPolygon[out](P1,P...,P8)
421 \tkzCalcLength(P1,P5)\tkzGetLength{r}
422 \begin{scope}[blend group=screen]
423 \foreach \i in {1,...,8}{%
424 \tkzDefCircle[R](P\i,\r) \tkzGetPoint{x}
425 \tkzFillCircle[color=teal](P\i,x)}
426 \end{scope}
427 \end{tikzpicture}
428 \end{tkzexample}
429
430 \endinput