summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tkz/tkz-euclide/doc/latex/TKZdoc-euclide-clipping.tex
blob: 430c8605ccf906aebb0b51486ea0e61e6c5779a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
\section{Controlling Bounding Box}
From the \tkzimp{PgfManual} :"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.
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."


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.

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.
The following command \tkzcname{pgfresetboundingbox} clears a bounding box and establishes a new one.

\subsection{Utility of \tkzcname{tkzInit}} 
 However, it is sometimes necessary to control the size of what will be displayed.
 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 "clip" the definition rectangle in order to control the size of the figure as well as possible.

The two macros that are useful for controlling the bounding box:
\begin{itemize}
   \item \tkzcname{tkzInit}
   \item \tkzcname{tkzClip}
\end{itemize}
\vspace{20pt}

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).

\subsection{\tkzcname{tkzInit}}

\begin{NewMacroBox}{tkzInit}{\oarg{local options}}\hypertarget{init}{}%
\begin{tabular}{lll}%    
options  & default & definition             \\
\midrule    
\TOline{xmin} {0} {minimum value of the abscissae in cm}
\TOline{xmax} {10} {maximum value of the abscissae in cm}
\TOline{xstep}{1} {difference between two graduations in $x$}
\TOline{ymin} {0} {minimum y-axis value in cm }
\TOline{ymax} {10} {maximum y-axis value in cm}
\TOline{ystep}{1} {difference between two graduations in $y$}  
\bottomrule    
\end{tabular}

\medskip 

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. 
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 "Clipping Out".
\end{NewMacroBox}


\subsection{\tkzcname{tkzClip}}

\begin{NewMacroBox}{tkzClip}{\oarg{local options}}
The role of this macro is to make invisible what is outside the rectangle defined by (xmin~;~ymin) and (xmax~;~ymax).

\medskip
\begin{tabular}{lll}
\hline
options  & default & definition             \\
\midrule
\TOline{space} {1} {added value on the right, left, bottom and top of the background}
\bottomrule
\end{tabular}

\medskip

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.
\end{NewMacroBox}



The role of this macro is to "clip" the initial rectangle so that only the paths contained in this rectangle are drawn.

\begin{tkzexample}[latex=8cm,small]
\begin{tikzpicture}
 \tkzInit[xmax=4, ymax=3]
 \tkzDefPoints{-1/-1/A,5/2/B}
 \tkzDrawX \tkzDrawY 
 \tkzGrid
 \tkzClip
 \tkzDrawSegment(A,B)
\end{tikzpicture}
\end{tkzexample} 

It is possible to add a bit of space
\begin{tkzltxexample}[]
  \tkzClip[space=1]
\end{tkzltxexample} 

\subsection{\tkzcname{tkzClip} and the option \tkzname{space}} 
This option allows you to add some space around the "clipped" rectangle.
\begin{tkzexample}[latex=8cm,small]
\begin{tikzpicture}
 \tkzInit[xmax=4, ymax=3]
 \tkzDefPoints{-1/-1/A,5/2/B}
 \tkzDrawX \tkzDrawY 
 \tkzGrid
 \tkzClip[space=1]
 \tkzDrawSegment(A,B)
\end{tikzpicture}
\end{tkzexample}   
The dimensions of the "clipped" rectangle are \tkzname{xmin-1}, \tkzname{ymin-1}, \tkzname{xmax+1} and \tkzname{ymax+1}. 

%<--------------------------------------------------------------------------->
%              tkzShowBB
%<--------------------------------------------------------------------------->
\subsection{tkzShowBB}
The simplest macro. 
\begin{NewMacroBox}{tkzShowBB}{\oarg{local options}}% 
This macro displays the bounding box. A rectangular frame surrounds the bounding box. This macro accepts \TIKZ\ options.
\end{NewMacroBox} 


\subsubsection{Example with \tkzcname{tkzShowBB}}
\begin{tkzexample}[latex=8cm,small]
\begin{tikzpicture}[scale=.5]
  \tkzInit[ymax=5,xmax=8]
  \tkzGrid  
  \tkzDefPoint(3,0){A}
   \begin{scope}
    \tkzClipBB
    \tkzDefCircle[R](A,5) \tkzGetPoint{a}
    \tkzDrawCircle(A,a)
     \tkzShowBB[line width = 4pt,fill=teal!10,opacity=.4]
   \end{scope}
\tkzDefCircle[R](A,4) \tkzGetPoint{b}
\tkzDrawCircle[red](A,b)
\end{tikzpicture}
\end{tkzexample}
%<--------------------------------------------------------------------------->
%         tkzClipBB
%<--------------------------------------------------------------------------->
\subsection{tkzClipBB}
\begin{NewMacroBox}{tkzClipBB}{}%
The idea is to limit future constructions to the current bounding box.
\end{NewMacroBox}

\subsubsection{Example with \tkzcname{tkzClipBB} and the bisectors}

\begin{tkzexample}[latex=6cm,small]
  \begin{tikzpicture}
  \tkzInit[xmin=-3,xmax=6, ymin=-1,ymax=6]
  \tkzDefPoint(0,0){O}\tkzDefPoint(3,1){I}
  \tkzDefPoint(1,4){J}
  \tkzDefLine[bisector](I,O,J) \tkzGetPoint{i}
  \tkzDefLine[bisector out](I,O,J) \tkzGetPoint{j}
  \tkzDrawPoints(O,I,J,i,j)
  \tkzClipBB
  \tkzDrawLines[add = 1 and 2,color=orange](O,I O,J)
  \tkzDrawLines[add = 1 and 2](O,i O,j)
  \tkzShowBB
  \end{tikzpicture}
\end{tkzexample}


\newpage

\section{Clipping different objects}

\subsection{Clipping a polygon} 
 \begin{NewMacroBox}{tkzClipPolygon}{\oarg{local options}\parg{points list}}%
This macro makes it possible to contain the different plots in the designated polygon.

\medskip
\begin{tabular}{lll}%
\toprule
arguments       & example & explanation     \\ 
\midrule
\TAline{\parg{pt1,pt2,pt3,\dots}}{\parg{A,B,C}}{}
\midrule
options  & default & definition             \\
\midrule    
\TOline{out} {} {allows to clip the outside of the object}
 \end{tabular}
\end{NewMacroBox}

\subsubsection{\tkzcname{tkzClipPolygon}}

\begin{tkzexample}[latex=7cm,small]
  \begin{tikzpicture}[scale=1.25] 
  \tkzDefPoint(0,0){A} 
  \tkzDefPoint(4,0){B} 
  \tkzDefPoint(1,3){C} 
  \tkzDrawPolygon(A,B,C) 
  \tkzDefPoint(0,2){D} 
  \tkzDefPoint(2,0){E} 
  \tkzDrawPoints(D,E) 
  \tkzLabelPoints(D,E) 
  \tkzClipPolygon(A,B,C) 
  \tkzDrawLine[new](D,E)
\end{tikzpicture}
\end{tkzexample}

\subsubsection{\tkzcname{tkzClipPolygon[out]}}

\begin{tkzexample}[latex=7cm,small]
  \begin{tikzpicture}[scale=1]
  \tkzDefPoint(0,0){P1}
  \tkzDefPoint(4,0){P2}
  \tkzDefPoint(4,4){P3}
  \tkzDefPoint(0,4){P4}
  \tkzDefPoint(1,1){Q1}
  \tkzDefPoint(3,1){Q2}
  \tkzDefPoint(3,3){Q3}
  \tkzDefPoint(1,3){Q4}
  \tkzDrawPolygon(P1,P2,P3,P4)
  \begin{scope}
     \tkzClipPolygon[out](Q1,Q2,Q3,Q4)
    \tkzFillPolygon[teal!20](P1,P2,P3,P4)
  \end{scope}
  \tkzDrawPolygon(Q1,Q2,Q3,Q4)
  \end{tikzpicture}
\end{tkzexample}

\subsubsection{Example: use of "Clip" for Sangaku in a square} 
\begin{tkzexample}[latex=7cm, small]  
\begin{tikzpicture}[scale=.75]
 \tkzDefPoint(0,0){A} \tkzDefPoint(8,0){B}
 \tkzDefSquare(A,B)   \tkzGetPoints{C}{D}
 \tkzDefPoint(4,8){F}
 \tkzDefTriangle[equilateral](C,D) 
 \tkzGetPoint{I}
 \tkzDefPointBy[projection=onto B--C](I) 
 \tkzGetPoint{J}
 \tkzInterLL(D,B)(I,J)  \tkzGetPoint{K}
 \tkzDefPointBy[symmetry=center K](B)  
 \tkzGetPoint{M}
 \tkzClipPolygon(B,C,D,A)
 \tkzFillPolygon[color = orange](A,B,C,D)
 \tkzFillCircle[color = yellow](M,I)
 \tkzFillCircle[color = blue!50!black](F,D)
\end{tikzpicture}
\end{tkzexample}

\subsection{Clipping a disc}

\begin{NewMacroBox}{tkzClipCircle}{\oarg{local options}\parg{A,B}}%
\begin{tabular}{lll}%
\toprule
arguments           & example & explanation                         \\
\midrule
\TAline{\parg{A,B}}{\parg{A,B}} {AB radius}
\bottomrule
\end{tabular}  
 
\medskip
\begin{tabular}{lll}%
options             & default & definition                         \\ 
\midrule
\TOline{out} {} {allows to clip the outside of the object}
 \bottomrule
\end{tabular}

\medskip
It is not necessary to put \tkzname{radius} because that is the default option.
\end{NewMacroBox}

 \subsubsection{Simple clip} 
\begin{tkzexample}[latex=6cm,small] 
\begin{tikzpicture}[scale=.5]
  \tkzDefPoint(0,0){A} \tkzDefPoint(2,2){O}
  \tkzDefPoint(4,4){B} \tkzDefPoint(5,5){C}
  \tkzDrawPoints(O,A,B,C) 
  \tkzLabelPoints(O,A,B,C)
  \tkzDrawCircle(O,A) 
  \tkzClipCircle(O,A)
  \tkzDrawLine(A,C)
  \tkzDrawCircle[fill=teal!10,opacity=.5](C,O)
\end{tikzpicture} 
\end{tkzexample}

\subsection{Clip out}

\begin{tkzexample}[latex=6cm,small]
\begin{tikzpicture}
  \tkzInit[xmin=-3,ymin=-2,xmax=4,ymax=3]
   \tkzDefPoint(0,0){O}
   \tkzDefPoint(-4,-2){A}
   \tkzDefPoint(3,1){B}
   \tkzDefCircle[R](O,2) \tkzGetPoint{o}
   \tkzDrawPoints(A,B) % to have a good bounding box
   \begin{scope}
    \tkzClipCircle[out](O,o)
    \tkzDrawLines(A,B)
   \end{scope}
\end{tikzpicture}  
\end{tkzexample} 

\subsection{Intersection of disks}

\begin{tkzexample}[latex=6cm,small]
\begin{tikzpicture}
\tkzDefPoints{0/0/O,4/0/A,0/4/B}
\tkzDrawPolygon[fill=teal](O,A,B)
\tkzClipPolygon(O,A,B)
\tkzClipCircle(A,O)
\tkzClipCircle(B,O)
\tkzFillPolygon[white](O,A,B)
\end{tikzpicture}
\end{tkzexample} 

see a more complex example about clipping here : \ref{About clipping circles}

\subsection{Clipping a sector}
\tkzHandBomb\  Attention the arguments vary according to the options. 
\begin{NewMacroBox}{tkzClipSector}{\oarg{local options}\parg{O,\dots}\parg{\dots}}%
\begin{tabular}{lll}%
options             & default & definition                         \\ 
\midrule
\TOline{towards}{towards}{$O$ is the center and the sector starts from $A$ to $(OB)$}
\TOline{rotate} {towards}{The sector starts from $A$ and the angle determines its amplitude. } 
\TOline{R}{towards}{We give the radius and two angles} 
\bottomrule
\end{tabular} 

\medskip
You have to add, of course, all the styles of \TIKZ\ for tracings...

\medskip   
\begin{tabular}{lll}%
\toprule
options             & arguments & example                         \\ 
\midrule
\TOline{towards}{\parg{pt,pt}\parg{pt}}{\tkzcname{tkzClipSector(O,A)(B)}}
\TOline{rotate} {\parg{pt,pt}\parg{angle}}{\tkzcname{tkzClipSector[rotate](O,A)(90)}} 
\TOline{R}{\parg{pt,$r$}\parg{angle 1,angle 2}}{\tkzcname{tkzClipSector[R](O,2)(30,90)}}
\end{tabular}
\end{NewMacroBox}

\subsubsection{Example 1} 
\begin{tkzexample}[latex=7cm,small] 
\begin{tikzpicture}[scale=0.5]
\tkzDefPoint(0,0){a}
\tkzDefPoint(12,0){b}
\tkzDefPoint(4,10){c}
\tkzInterCC[R](a,6)(b,8) 
\tkzGetFirstPoint{AB1} \tkzGetSecondPoint{AB2}
\tkzInterCC[R](a,6)(c,6) 
\tkzGetFirstPoint{AC1} \tkzGetSecondPoint{AC2}
\tkzInterCC[R](b,8)(c,6) 
\tkzGetFirstPoint{BC1} \tkzGetSecondPoint{BC2}
\tkzDrawArc(a,AB2)(AB1)
\tkzDrawArc(b,AB1)(AB2)
\tkzDrawArc(a,AC2)(AC1)
\tkzDrawArc(c,AC1)(AC2)
\tkzDrawArc(b,BC2)(BC1)
\tkzDrawArc(c,BC1)(BC2)
\begin{scope}
\tkzClipSector(b,BC2)(BC1)
\tkzFillSector[teal!40!white](c,BC1)(BC2)
\end{scope}
\begin{scope}
\tkzClipSector(a,AB2)(AB1)
\tkzFillSector[teal!40!white](b,AB1)(AB2)
\end{scope}
\begin{scope}
\tkzClipSector(a,AC2)(AC1)
\tkzFillSector[teal!40!white](c,AC1)(AC2)
\end{scope}
\end{tikzpicture}
\end{tkzexample}

\subsubsection{Example 2} 
\begin{tkzexample}[latex=7cm,small] 
\begin{tikzpicture}[scale=1.5] 
  \tkzDefPoint(0,0){O}
  \tkzDefPoint(2,-1){A}
  \tkzDefPoint(1,1){B} 
  \tkzDrawSector[new,dashed](O,A)(B)
  \tkzDrawSector[new](O,B)(A)
\begin{scope}
\tkzClipSector(O,B)(A)
\tkzDefSquare(O,B) \tkzGetPoints{B'}{O'}
\tkzDrawPolygon[color=teal,fill=teal!20](O,B,B',O')
\end{scope}
\tkzDrawPoints(A,B,O) 
\end{tikzpicture} 
\end{tkzexample}


\subsection{Options from \TIKZ: trim left or right}
See the \tkzimp{pgfmanual}

\subsection{\TIKZ\ Controls \tkzcname{pgfinterruptboundingbox} and \tkzcname{endpgfinterruptboundingbox}}
This command temporarily interrupts the calculation of the box and configures a new box.
See the \tkzimp{pgfmanual}

\subsubsection{Example about contolling the bouding box} 
\begin{tkzexample}[latex=7cm,small] 
\begin{tikzpicture}
\tkzDefPoint(0,5){A}\tkzDefPoint(5,4){B}
\tkzDefPoint(0,0){C}\tkzDefPoint(5,1){D}
\tkzDrawSegments(A,B C,D A,C)
\pgfinterruptboundingbox
   \tkzInterLL(A,B)(C,D)\tkzGetPoint{I}
\endpgfinterruptboundingbox
\tkzClipBB
\tkzDrawCircle(I,B)
\end{tikzpicture}
\end{tkzexample}

\subsection{Reverse clip: tkzreverseclip}

In order to use this option, a bounding box must be defined. 

\begin{tkzltxexample}[]
  \tikzset{tkzreverseclip/.style={insert path={
     (current bounding box.south west) --(current bounding box.north west)
   --(current bounding box.north east) --  (current bounding box.south east)
   -- cycle} }}
\end{tkzltxexample}

\subsubsection{Example with \tkzcname{tkzClipPolygon[out]}}
\tkzcname{tkzClipPolygon[out]}, \tkzcname{tkzClipCircle[out]} use this option.
\begin{tkzexample}[vbox,small]
\begin{tikzpicture}[scale=1]
\tkzInit[xmin=-5,xmax=5,ymin=-4,ymax=6]
\tkzClip
\tkzDefPoints{-.5/0/P1,.5/0/P2}
\foreach \i [count=\j from 3] in {2,...,7}{%
    \tkzDefShiftPoint[P\i]({45*(\i-1)}:1){P\j}}  
\tkzClipPolygon[out](P1,P...,P8)
\tkzCalcLength(P1,P5)\tkzGetLength{r}
\begin{scope}[blend group=screen]
  \foreach \i in {1,...,8}{%
   \tkzDefCircle[R](P\i,\r) \tkzGetPoint{x}
   \tkzFillCircle[color=teal](P\i,x)}
  \end{scope}
\end{tikzpicture}
\end{tkzexample}

\endinput