Debian Codegraph @

texmf-dist/source/latex/euclideangeometry/euclideangeometry.dtx

raw
1 % \iffalse
2 % !TEX encoding = UTF-8 Unicode
3 %<*internal>
4 \begingroup
5 \input docstrip.tex
6 \keepsilent
7 \preamble
8
9 Copyright (C) 2020-2023 Claudio Beccari all rights reserved.
10
11 Distributable under the LaTeX Project Public License,
12 version 1.3c or higher (your choice). The latest version of
13 this license is at: http://www.latex-project.org/lppl.txt
14
15 \endpreamble
16
17 \askforoverwritefalse
18
19 \generate{\file{euclideangeometry.sty}{\from{euclideangeometry.dtx}{package}}}
20
21 \def\tmpa{plain}
22 \ifx\tmpa\fmtname\endgroup\expandafter\bye\fi
23 \endgroup
24 %</internal>
25 % \fi
26 %
27 % \iffalse
28 %<*driver>
29 \ProvidesFile{euclideangeometry.dtx}%
30 %</driver>
31 %<package>\NeedsTeXFormat{LaTeX2e}[2019/01/01]
32 %<package>\ProvidesPackage{euclideangeometry}%
33 %<readme>File README.txt for package euclideangeometry
34 %<*package|readme>
35 [2023-07-11 v.0.2.2 Extension package for curve2e]
36 %</package|readme>
37 %<*driver>
38 \documentclass{ltxdoc}\errorcontextlines=100
39 \hfuzz 10pt
40 \usepackage[utf8]{inputenc}
41 \usepackage{lmodern,textcomp}
42 \usepackage{mflogo}
43 \usepackage{multicol,amsmath,fancyvrb,graphicx,verbatim}
44 \usepackage{etoolbox,enumitem,xspace,xcolor,euclideangeometry}
45 \providecommand*\diff{\mathop{}\!\mathrm{d}}
46 \providecommand\file{}
47 \renewcommand*\file[1]{{\normalfont\texttt{#1}}}
48 \providecommand\prog{}
49 \renewcommand*\prog[1]{{\normalfont\texttt{#1}}}
50 \newcommand*\conta[1]{\texttt{\slshape#1}}
51 \providecommand\cs{}
52 \renewcommand\cs[1]{{\normalfont\texttt{\char92#1}}}
53 \renewcommand\meta[1]{{\normalfont\textlangle\textit{#1}\textrangle}}
54 \renewcommand\marg[1]{\texttt{\{\meta{#1}\}}}
55 \providecommand\Marg{}
56 \renewcommand*\Marg[1]{\texttt{\{#1\}}}
57 \providecommand\oarg{}
58 \renewcommand*\oarg[1]{\texttt{[\meta{#1}]}}
59 \providecommand\Oarg{}
60 \renewcommand*\Oarg[1]{\texttt{[#1]}}
61 \providecommand\aarg{}
62 \renewcommand*\aarg[1]{\texttt{<\meta{#1}>}}
63 \providecommand\Aarg{}
64 \renewcommand*\Aarg[1]{\texttt{<#1>}}
65 \providecommand\parg{}
66 \renewcommand*\parg[1]{\texttt{(\meta{#1})}}
67 \providecommand\Parg{}
68 \renewcommand*\Parg[1]{\texttt{(#1)}}
69 \providecommand\pack{}
70 \renewcommand*\pack[1]{{\textsf{#1}}}
71 \providecommand\opt{}
72 \renewcommand*\opt[1]{{\normalfont\textsl{#1}}}\let\opz\opt
73 \providecommand\env{}
74 \renewcommand*\env[1]{{\normalfont\textit{\bfseries#1}}}\let\amb\env
75
76 \providecommand\TB{\mbox{\normalfont\slshape TUGboat}\xspace}
77
78 \definecolor{verdeguit}{rgb}{0, 0.40, 0}
79 \def\GuIT{\mbox{\color{verdeguit}\def\I{\textcolor{black}{I}}%
80 \fontfamily{lmr}\fontseries{m}\fontshape{sc}\selectfont
81 g\raisebox{-0.715ex}{\kern-0.26em u}\kern-0.13em\I\kern-0.14em t}\xspace}
82 \RequirePackage{etoolbox}
83
84 \makeatletter
85
86 \AfterEndPreamble{%
87 \DeclareRobustCommand{\TeX}{T\kern-.1667em
88 \lower.5ex\hbox{E}\kern-.125emX\@\xspace}
89 \DeclareRobustCommand{\LaTeX}{L\kern-.36em%
90 {\sbox\z@ T%
91 \vbox to\ht\z@{\hbox{\check@mathfonts
92 \fontsize\sf@size\z@
93 \math@fontsfalse\selectfont
94 A}%
95 \vss}%
96 }%
97 \kern-.15em%
98 \TeX}}
99 \makeatother
100
101 \DeclareRobustCommand*\TeXLive{\TeX\ Live\xspace}
102 \DeclareRobustCommand*\MikTeX{Mik\TeX}
103 \DeclareRobustCommand*\MacTeX{Mac\TeX}
104 \DeclareRobustCommand*\pdfLaTeX{pdf\/\LaTeX}
105 \DeclareRobustCommand*\LuaLaTeX{Lua\LaTeX}
106 \DeclareRobustCommand*\XeLaTeX{X\ifdim\fontdimen1\font=0pt\kern-0.15em\fi
107 \lower.5ex\hbox{\rotatebox[origin=c]{180}{E}}%
108 \ifdim\fontdimen1\font=0pt\kern-0.15em\else\kern-0.275em\fi
109 \LaTeX}
110 \DeclareRobustCommand*\TikZ{Ti\emph{k}Z\xspace}
111
112 \newenvironment{ttsintassi}{\begin{lrbox}{0}
113 \minipage{\dimexpr\linewidth-2\fboxrule-2\fboxsep}\ttfamily\obeylines}%
114 {\endminipage\end{lrbox}\center\fbox{\box0}\endcenter}
115 \let\ttsyntax\ttsintassi \let\endttsyntax\endttsintassi
116
117 \unless\ifcsname Gr@phGrid\endcsname
118 \let\originalGraphGrid\GraphGrid
119 \RenewDocumentCommand\GraphGrid{r() d()}{%
120 \IfValueTF{#2}{\put(#1){\originalGraphGrid(#2)}}%
121 {\put(0,0){\originalGraphGrid(#1)}}}\fi
122
123
124 \begin{document}\errorcontextlines=100
125 \GetFileInfo{euclideangeometry.dtx}
126 \title{The \textsf{euclideangeometry} package}
127 \author{Claudio Beccari\\[1ex]\texttt{claudio dot beccari at gmail dot com}}
128 \date{Version \fileversion~--~Last revised \filedate.}
129 \maketitle
130 \columnseprule=0.4pt
131 \begin{multicols}{2}
132 \tableofcontents
133 \end{multicols}
134 \DocInput{euclideangeometry.dtx}
135 \end{document}
136 %</driver>
137 % \fi
138 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 % \section*{Preface}
140 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 %
142 % This file contains the documented code of \pack{euclideangeometry}.
143 % The user manual source file \file{euclideangeometry-man.tex} and the
144 % readable document is \file{euclideangeometry.pdf}; it should already be
145 % installed with your updated complete \TeX system installation.
146
147 % Please refer to the user manual before using this package.
148 % \CheckSum{1315}
149 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 %\StopEventually{}
151 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 %
153 %\iffalse
154 %<*package>
155 %\fi
156 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 % \section{The code}
158 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 %
160 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 % \subsection{Test the date of a sufficiently recent \texttt{curve2e}
162 % package}
163 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 % This package has been already identified by the commands extracted
165 % by the |docstrip| package, during the |.dtx| file compilation.
166 % In any case, if the test checks that the |curve2e| file date is too old;
167 % it warns the user with an emphasised error message on the console,
168 % loading this |euclideangeometry| package is stopped and the whole
169 % job aborts. The emphasised error message appears like this:\\~
170 %\begin{flushleft}\ttfamily\obeylines
171 %*************************************************************
172 %Package curve2e too old
173 %Be sure that your TeX installation is complete and up to date
174 %*************************************************************
175 %Input of euclideangeometry is stopped and job aborted
176 %*************************************************************
177 %\end{flushleft}
178 % This message should be sufficiently strong in order to avoid using
179 % this package with a vintage version of \TeXLive or \MikTeX.
180 % \begin{macrocode}
181 \RequirePackage{curve2e}
182 \@ifpackagelater{curve2e}{2020/01/18}{}%
183 {%
184 \typeout{*************************************************************}
185 \typeout{Package curve2e too old}
186 \typeout{Be sure that your TeX installation is complete and up to date}
187 \typeout{*************************************************************}
188 \typeout{Input of euclideangeometry stopped and job aborted}
189 \typeout{*************************************************************}
190 \@@end
191 }%
192
193 % \end{macrocode}
194 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 %\subsection{Labelling}
196 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197 %
198 % While doing any graphical geometrical drawing it is necessary to label
199 % points, lines, angles and other such items. Non measurable labels
200 % should be in upright sans serif font, according to the ISO regulations,
201 % but here we are dealing with point identified by macros the contain
202 % their (cartesian or polar) coordinates that very often are both labels
203 % and math variables.
204 %
205 % Here we provide a versatile macro that can do several things. Its name
206 % is |\Pbox| and it produces a box containing the label in math format. By
207 % default the point label is typeset with the math font variant produced
208 % by command |\mathsf|, but the macro is sufficiently versatile to allow
209 % other settings; it accepts several optional arguments, therefore it
210 % syntax is particular:
211 %\begin{ttsyntax}
212 %\cs{Pbox}\parg{coordinates}\oarg{alignment}\marg{label}\oarg{diameter}\meta{$\star$}\aarg{angle}
213 %\end{ttsyntax}
214 % where \meta{coordinates} are the coordinates where to possibly set a
215 % black dot with the specified \meta{diameter}; in any case it is the
216 % reference point of the \meta{label}; the \meta{alignment} is formed by
217 % the usual letters \texttt{t, b, c, l, r} that can be paired in a
218 % coherent way (for example the couple \texttt{tb} is evidently
219 % incoherent, as well as \texttt{lr}), but in absence of this optional
220 % specification, the couple \texttt{cc} is assumed; most often than
221 % not, the label position becomes such that when the user reviews the
222 % document drafts, s/he understands immediately that s/he forgot to
223 % specify some reasonable \meta{alignment} codes; in any case the
224 % \texttt{cc} code works fine to just put the dot of a specified
225 % diameter but with an empty label. Think of the \meta{alignment}
226 % letters as the position of the reference point with respect to the
227 % the \meta{label} optical center. The optional \meta{angle} argument
228 % produces a rotation of the whole label by that angle; it may be used
229 % in several circumstances, especially when the label is just text, to
230 % produce, for example, a sideways legend. It is useful also when the
231 % labels are produced within a rotated box, in order to counterrotate
232 % them.
233 %
234 % The optional asterisk draws a frame around the \emph{label}. Notice
235 % that the separator between the visible or the invisible frame and the
236 % box contents varies according the the fact that the \meta{alignment}
237 % specification contains just one or two letter codes; this is useful,
238 % because the diagonal position of the label should be optically equal
239 % to the gap that exists between the reference point and the \meta{label}
240 % box.
241 %
242 % If the \meta{diameter} is zero, no dot is drawn, the whole \meta{label}
243 % is typeset with the |\mathit| math font; otherwise only the first symbol
244 % of a math expression is typeset in sans serif. The presence of subscripts
245 % makes the labels appear more distant from their reference point; the same
246 % is true when math symbols, even without subscripts, are used, because
247 % of the oblique nature of the math ‘letters’ alphabet.
248 %
249 % If some text has to be printed as a label, it suffices to surround it
250 % with dollar signs, that switch back to text mode when the default mode
251 % is the math one. With this kind of textual labels it might be convenient
252 % to use the optional asterisk to frame the text.
253 % The final optional argument \meta{angle} (to be delimited with the
254 % \texttt{<~>} signs) specifies the inclination of the label with respect
255 % to the horizontal line; it is useful, for example to set a label along
256 % a sloping line.
257 % \begin{macrocode}
258 \providecommand\Pbox{}
259 \RenewDocumentCommand\Pbox{D(){0,0} O{cc} m O{0.5ex} s D<>{0}}{%
260 \put(#1){\rotatebox{#6}{\makebox(0,0){%
261 \settowidth\PbDim{#2}%
262 \edef\Rapp{\fpeval{\PbDim/{1ex}}}%
263 \fptest{\Rapp > 1.5}{\fboxsep=0.5ex}{\fboxsep=0.75ex}%
264 \IfBooleanTF{#5}{\fboxrule=0.4pt}{\fboxrule=0pt}%
265 \fptest{#4 = 0sp}%
266 {\makebox(0,0)[#2]{\fbox{$\relax#3\relax$}}}%
267 {\edef\Diam{\fpeval{(#4)/\unitlength}}%
268 \makebox(0,0){\circle*{\Diam}}%
269 \makebox(0,0)[#2]{\fbox{$\relax\mathsf#3\relax$}}%
270 }}}%
271 }\ignorespaces}
272 % \end{macrocode}
273 % The following command, to be used always within a group, or a
274 % environment or inside a box, works only with piecewise continuously
275 % scalable font collection, such as, for example, the Latin Modern
276 % fonts, or with continuously scalable fonts, such as, for example,
277 % the Times ones. They let the operator select, for the scope of the
278 % command ,any size, even fractional so as to fine adjust the text
279 % width in the space allowed for it; it is particularly useful with
280 % the monospaced fonts, that forbid hyphenation, and therefore cannot
281 % be adjusted to the current line width.
282 % \begin{macrocode}
283 \DeclareRobustCommand\setfontsize[2][1.2]{%
284 \linespread{#1}\fontsize{#2}{#2}\selectfont}
285 % \end{macrocode}
286 % With OpenType fonts there should not be any problems even with math
287 % fonts; with Type~1 fonts the only scalable fonts I know of, are the
288 % LibertinusMath fonts, usable through the LibertinusT1math package, are
289 % also the only ones that have 8~bit encoded math fonts (256
290 % glyph fonts), while the standard default math fonts are just
291 % 7~bit encoded (128 glyphs fonts).
292 %
293 % Another useful labelling command is |Zbox|; this command is an
294 % evolution of a command that I have been using for years in several
295 % documents of mine. It uses some general text, not necessarily
296 % connected to a particular point of the |picture| environment,
297 % as a legend; It can draw short text as a simple horizontal box,
298 % and longer texts as a vertical box of specified width and height
299 %
300 % Is syntax is the following:
301 %\begin{ttsyntax}
302 %\cs{Zbox}\parg{position}\parg{dimensions}\oarg{alignment}\marg{text}
303 %\end{ttsyntax}
304 % where \meta{position} is where the box reference point has
305 % to be put in the picture; \meta{dimensions} are optional; if not
306 % specified, the box is a horizontal one, and it is as wide as its
307 % contents; if it is specified, it must be a comma separated list
308 % of two integer or fractional numbers that are the width and the
309 % height of the box; if the height is specified as zero, the width
310 % specifies a horizontal box of that width; \meta{alignment} is optional
311 % and is formed by one or two coherent letter codes from the usual set
312 % \texttt{t, b, c, l, r}; if the \meta{alignment} is absent, the
313 % default alignment letters are \texttt{bl}, i.e. the box reference
314 % point is the bottom left corner; \meta{text} contains general text,
315 % even containing some math.
316 % \begin{macrocode}
317
318 \def\EUGsplitArgs(#1,#2)#3#4{\edef#3{#1}\edef#4{#2}}
319 \newlength\EUGZbox
320 \providecommand\Zbox{}
321 \RenewDocumentCommand\Zbox{r() D(){0,0} O{bl} m}{%
322 \EUGsplitArgs(#2)\ZboxX\ZboxY % splits box dimensions
323 \fboxsep=2\unitlength
324 \ifnum\ZboxX=\z@
325 \def\ZTesto{\fbox{#4}}%
326 \else
327 \ifnum\ZboxY=\z@
328 \def\ZTesto{\fbox{\parbox{\ZboxX\unitlength}{#4}}}%
329 \else
330 \def\ZTesto{%
331 \setbox\EUGZbox=\hbox{\fbox{%
332 \parbox[c][\ZboxY\unitlength][c]{\ZboxX\unitlength}{#4}}}%
333 \dimen\EUGZbox=\dimexpr(\ht\EUGZbox +\dp\EUGZbox)/2\relax
334 \ht\EUGZbox=\dimen\EUGZbox\relax
335 \dp\EUGZbox=\dimen\EUGZbox\relax
336 \box\EUGZbox%
337 }%
338 \fi
339 \fi
340 \put(#1){\makebox(0,0)[#3]{\ZTesto}}\ignorespaces}
341 % \end{macrocode}
342
343 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344 % \subsection{Service macros for ellipses}
345 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346 % The |\ellisse| has a control sequence name in Italian; it differs for
347 % just one letter from the name |ellipse| English name, but we cannot use
348 % the latter one because it may conflict with other packages loaded by
349 % the user; actually this command and the next one are just shortcuts
350 % for executing more general commands with specific sets of arguments.
351 % For details and syntax, please refer yourself to
352 % section~\ref{ssec:ellissi}
353 % \begin{macrocode}
354
355 \NewDocumentCommand\ellisse{ s m m}{%
356 \IfBooleanTF{#1}%
357 {\let\fillstroke\fillpath}%
358 {\let\fillstroke\strokepath}%
359 \Sellisse{#2}{#3}%
360 }
361
362 \NewDocumentCommand\Xellisse{ s D(){0,0} O{0} m m O{} o}{%
363 \IfBooleanTF{#1}%
364 {\XSellisse*(#2)[#3]{#4}{#5}[#6][#7]}%
365 {\XSellisse(#2)[#3]{#4}{#5}[#6][#7]}%
366 }
367 % \end{macrocode}
368 %
369 % We do not know if the following macro |\polyvector| may be useful for
370 % euclidean geometry constructions, but it may be useful in block
371 % diagrams; it is simply a polyline where the last segment is a geometrical
372 % vector. As in polyline the number of recursions is done until the last
373 % specified coordinate pair; recognising that it is the last one, instead
374 % of drawing a segment, the macro draws a vector.
375 %
376 % \begin{macrocode}
377
378 \def\polyvector(#1){\roundcap\def\EUGpreviouspoint{#1}\EUGpolyvector}
379 \def\EUGpolyvector(#1){%
380 \@ifnextchar({%
381 \segment(\EUGpreviouspoint)(#1)\def\EUGpreviouspoint{#1}\EUGpolyvector}%
382 {\VECTOR(\EUGpreviouspoint)(#1)}%
383 }
384 % \end{macrocode}
385 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
386 % \subsection{Processing lines and segments}
387 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388 %
389 % The next macros are functional for the geometric constructions we are
390 % going to make: finding the intersection of lines or segments,
391 % finding the lengths and arguments of segments, directions, distances,
392 % distance of a point from a line or a segment, the symmetrical
393 % point of a another one specified with respect to a given center of
394 % symmetry; the axes of segments, the solutions of the relationship
395 % between the semi axes of an ellipse and the semi focal distance,
396 % and so on.
397 %
398 % Most of these commands have delimited arguments; the delimiters
399 % may be the usual parentheses, but they may be keywords; many
400 % commands contain the keyword \texttt{to}, not necessarily the
401 % last one; the arguments before such keyword may be entered as
402 % ordered comma separated numerical couples, or comma separated
403 % macros the containing scalar values; or they may be macros that
404 % contain the ordered couples representing vectors or directions;
405 % they all may be in cartesian or polar form. Remember that such
406 % ordered couples are complex numbers, representable by
407 % vectors applied to the origin of the axes; therefore sometimes it is
408 % necessary that the underlying commands execute some vector
409 % differences so as to work with generic vectors.
410 %
411 % On the opposite the output values, i.e. the argument after that
412 % \texttt{to} keyword, should be tokens that can receive a definition,
413 % in general macros, to which the user should assign a mnemonic name;
414 % s/he should use such macros for further computations or for drawing
415 % commands.
416 %
417 % The first and principal command is |\IntersectionOfLines| and
418 % it has the following syntax:
419 %\begin{ttsyntax}
420 %\cs{IntersectionOfLines}\parg{point1}\parg{dir1}and\parg{point2}\parg{dir2}to\meta{crossing point}
421 %\end{ttsyntax}
422 % where \meta{point1} and \meta{dir1} are respectively a point of the
423 % first line and its \emph{direction}, not a second point, but the
424 % \emph{direction} — it is important to stress this point; similarly
425 % for the second line; the output is stored in
426 % the macro that identifies the \meta{crossing point}. The directions
427 % do not need to be expressed with unit vectors, but the lines must not
428 % be parallel or anti parallel (equal directions or differing by
429 % $180^\circ$); the macro contains a test that checks this anomalous
430 % situation because an intersection at infinity or too far away
431 % ($2^{14}-1$ typographical points, approximately 5,758\,m) is of no
432 % interest; in case, no warning message is issued, the result is
433 % put to \texttt{0,0}, and the remaining computations become nonsense.
434 % It is a very unusual situation and I never encountered~it;
435 % nevertheless\dots
436
437 % \begin{macrocode}
438
439 \def\IntersectionOfLines(#1)(#2)and(#3)(#4)to#5{\bgroup
440 \def\IntPu{#1}\def\Uu{#2}\def\IntPd{#3}\def\Ud{#4}%
441 \DirOfVect\Uu to\Du
442 \DirOfVect\Ud to\Dd
443 \XpartOfVect\Du to \a \YpartOfVect\Du to \b
444 \XpartOfVect\Dd to \c \YpartOfVect\Dd to \d
445 \XpartOfVect\IntPu to \xu \YpartOfVect\IntPu to \yu
446 \XpartOfVect\IntPd to \xd \YpartOfVect\IntPd to \yd
447 \edef\Den{\fpeval{-(\a*\d-\b*\c)}}%
448 \fptest{abs(\Den)<1e-5}{% Almost vanishing determinant
449 \def#5{0,0}%
450 }{% Determinant OK
451 \edef\Numx{\fpeval{(\c*(\b*\xu-\a*\yu)-\a*(\d*\xd-\c*\yd))/\Den}}%
452 \edef\Numy{\fpeval{(\d*(\b*\xu-\a*\yu)-\b*(\d*\xd-\c*\yd))/\Den}}%
453 \CopyVect\Numx,\Numy to\Paux
454 \edef\x{\egroup\noexpand\edef\noexpand#5{\Paux}}\x\ignorespaces}}
455 % \end{macrocode}
456 %
457 % The |IntersectionOfSegments| macro is similar but in input it
458 % contains the end points of two segments: internally it uses
459 % |\IntersectionOfLines| and to do so it has to determine the
460 % directions of both segments. The syntax is the following:
461 %\begin{ttsyntax}
462 %\cs{IntersectionOfSegments}\parg{point11}\parg{point12}and\parg{point21}\parg{point22}
463 %\qquad to\meta{crossing}
464 %\end{ttsyntax}
465 % The \meta{crossing} point might fall outside one or both segments.
466 % It is up to the users to find out if the result is meaningful
467 % or nonsense. Two non parallel lines are infinitely long in both
468 % directions and any \meta{crossing} point is acceptable; with
469 % segments the situation might become nonsense.
470 % \begin{macrocode}
471
472 \def\IntersectionOfSegments(#1)(#2)and(#3)(#4)to#5{%
473 \SubVect#1from#2to\IoSvectu \DirOfVect\IoSvectu to\DirIoSVecu
474 \SubVect#3from#4to\IoSvectd \DirOfVect\IoSvectd to\DirIoSVecd
475 \IntersectionOfLines(#1)(\DirIoSVecu)and(#3)(\DirIoSVecd)to#5\ignorespaces}
476 % \end{macrocode}
477 %
478 % An application of the above intersections is formed by the next
479 % two macros; they find the axes of a couple of sides of a triangle
480 % and use their base point and direction to identify two lines the
481 % intersection of which is the circumcenter; the distance of one
482 % base point from the circumcenter is the radius of the circumcircle
483 % that can be drawn with the usual macros. We have to describe
484 % the macros |\AxisOf| and |CircleWithCenter| and we will do it in
485 % a little while. Meanwhile the syntax of the whole macro is the
486 % following:
487 %\begin{ttsyntax}
488 %\cs{ThreePointCircle}\meta{$\star$}\parg{vertex1}\parg{vertex2}\parg{vertex3}
489 %\end{ttsyntax}
490 % where the three vertices are the three points where the circle
491 % must pass, but they identify also a triangle. Its side axes
492 % intersect in one point that by construction is at the same
493 % distance from the three vertices, therefore it is the center of
494 % the circle that passes through the three vertices. A sub product
495 % of the computations is the macro |\C| that contains the center
496 % coordinates. If the optional asterisk is used the whole drawing
497 % is executed, while if it is missing, only the |\C| macro remains
498 % available but the user is responsible to save/copy its value
499 % into another macro; for this reason another macro should be more
500 % easy to use; its syntax is the following:
501 %\begin{ttsyntax}
502 %\cs{ThreePointCircleCenter}\parg{vertex1}\parg{vertex2}\parg{vertex3}
503 %\qquad to\meta{center}
504 %\end{ttsyntax}
505 % where the vertices have the same meaning, but\meta{center} is
506 % the user chosen macro that contains the center coordinates.
507 %
508 % \begin{macrocode}
509
510 \NewDocumentCommand\ThreePointCircle{s r() r() r()}{%
511 \AxisOf#2and#3to\Mu\Du \AxisOf#2and#4to\Md\Dd
512 \IntersectionOfSegments(\Mu)(\Du)and(\Md)(\Dd)to\C
513 \SubVect#2from\C to\R
514 \IfBooleanTF{#1}{\CircleWithCenter\C Radius\R}{}\ignorespaces}
515
516 \NewDocumentCommand\ThreePointCircleCenter{r() r() r() m}{%
517 \ThreePointCircle(#1)(#2)(#3)\CopyVect\C to#4}
518 % \end{macrocode}
519 %
520 % There are some useful commands that help creating |picture|
521 % diagrams in an easier way; for example one of the above described
522 % commands internally uses |\CircleWithCenter|. It is well known
523 % that the native |picture| command |\circle| requires the
524 % specification of the diameter but many |euclideangeometry|
525 % commands already get the distance of two points, or the magnitude
526 % of a segment, or similar objects that may be used as a radius, rather
527 % than the diameter; why should we not have macros that simultaneously
528 % compute the require diameter and draw the circle. Here there are two
529 % such macros; they are similar to one another but their names differ in
530 % capitalisation, but also in the way they use the available input
531 % information. The syntax is the following:
532 %\begin{ttsyntax}
533 %\cs{CircleWithCenter}\meta{center} Radius\meta{Radius}
534 %\cs{Circlewithcenter}\meta{center} radius\meta{radius}
535 %\end{ttsyntax}
536 % where in both cases \meta{center} is a vector/ordered couple
537 % that points to the circle center. On the contrary \meta{Radius}
538 % is a vector obtained through previous calculations, while
539 % \meta{radius} is a scalar containing a previously calculated length.
540 % \begin{macrocode}
541 \def\CircleWithCenter#1Radius#2{\put(#1){\ModOfVect#2to\CWR
542 \circle{\fpeval{2*\CWR}}}\ignorespaces}
543 %
544 \def\Circlewithcenter#1radius#2{\put(#1){\circle{\fpeval{2*abs(#2)}}}%
545 \ignorespaces}
546 % \end{macrocode}
547 %
548 % As announced, here we have a macro to compute the axis of a segment;
549 % given two points $P_1$ and $P_2$, for example the end points of a
550 % segment, or better the end points of the vector that goes from
551 % $P_1$ to $P_2$, the macro determines the segment middle point and
552 % a second point the lays on the perpendicular at a distance equal to half
553 % the first two points distance; this second point lays at the left of
554 % vector $P_2-P_1$, therefore it is important to select the right initial
555 % vector, in order to have the second axis point on the desired side.
556 % This macro did not work well because sometimes its internal variables
557 % interfered with other commands internal ones; enclosing everything
558 % within an auto deleting group by means of the auto deleting |\x| macro
559 % usual trick, such interferences should be avoided.
560 %\begin{ttsyntax}
561 %\cs{AxisOf}\meta{P1} and\meta{P2} to\meta{Axis1}\meta{Axis2}
562 %\end{ttsyntax}
563 % Macros |\SegmentCenter| and |\MiddlePointOf| are alias of one another;
564 % their syntax is:
565 %\begin{ttsyntax}
566 %\cs{SegmentCenter}\parg{P1}\parg{P2}to\meta{center}
567 %\cs{MiddlePointOf}\parg{P1}\parg{P2}to\meta{center}
568 %\end{ttsyntax}
569 % \meta{P1}, \meta{P2}, \meta{Axis1}, \meta{Axis2} and \meta{center} are
570 % all ordered pairs (vectors).
571 % \begin{macrocode}
572
573 \def\AxisOf#1and#2to#3#4{\bgroup
574 \SubVect#1from#2to\Base \ScaleVect\Base by0.5to\Base
575 \AddVect\Base and#1to\Mout \MultVect\Base by0,1to\Base
576 \AddVect\Mout and\Base to\Dout
577 \edef\x{\egroup\noexpand\CopyVect\Mout to\noexpand#3\relax
578 \noexpand\CopyVect\Dout to\noexpand#4}\x\ignorespaces}
579
580 \def\SegmentCenter(#1)(#2)to#3{\AddVect#1and#2to\Segm
581 \ScaleVect\Segm by0.5to#3\ignorespaces}
582
583 \let\MiddlePointOf\SegmentCenter
584 % \end{macrocode}
585 %
586 % Some other macros are needed to solve certain triangle problems;
587 % one of such macros is the one allows to determine the length of one
588 % leg of a right triangle by knowing the lengths of the hypothenuse
589 % and the other leg. The syntax is the following:
590 %\begin{ttsyntax}
591 %\cs{LegFromHypotenuse}\meta{hypothenuse} AndOtherLeg\meta{leg1} to\meta{leg2}
592 %\end{ttsyntax}
593 % where the three parameters may be macros, especially the last one;
594 % all of them contina scalar values.
595 %
596 % \begin{macrocode}
597 \def\LegFromHypotenuse#1AndOtherLeg#2to#3{%
598 \edef#3{\fpeval{sqrt(#1**2-#2**2)}}}
599 % \end{macrocode}
600 %
601 % Another useful macro determines the two intersections of a line with
602 % a circumference if they exist; otherwise it issues a warning and sets
603 % both output values to vector \texttt{0,0}, which, of course, is wrong,
604 % but it allows to go on with typesetting, although with non sense results.
605 % Warnings do not stop the compilation program, therefore their message
606 % goes to the \file{.log} file and the user might not notice it; but
607 % since the results are probably absurd, s/he certainly notices this
608 % fact and looks for messages; the user, therefore, who has carefully
609 % read this user manual, immediately looks onto the \file{.log} file
610 % and realises the reason of the wrong results. A similar approach
611 % is used for the macro that determines the intersection of two circles;
612 % see below
613 % The syntax of this macro is the following:
614 %\begin{ttsyntax}
615 %\cs{IntersectionsOfLine}\parg{point}\parg{direction} WithCircle\parg{center}\marg{radius} to\meta{int1} and\meta{int2}
616 %\end{ttsyntax}
617 % where \meta{point} and \meta{direction} are the line parameters
618 % that can be explicit complex values or macros; \meta{center} is
619 % the circumference explicit complex value, or a macro, containing
620 % the center coordinates; \meta{radius} is the scalar explicit or
621 % macro radius length; The intersection points \meta{int1} and
622 % \meta{ind2} are supposed to be macros that get defined with the
623 % intersection point coordinates; \meta{int1} is the first intersection
624 % that is determined along the line \emph{direction}. Please notice the
625 % different first part of the macro name \texttt{IntersectionsOfLine}
626 % compared to the macro that determines the intersection of two lines
627 % \texttt{IntersectionOfLines}: two intersections and one line vs. one
628 % intersection with two lines.
629 % \begin{macrocode}
630 \def\IntersectionsOfLine(#1)(#2)WithCircle(#3)#4to#5and#6{%
631 \CopyVect#3 to\C \edef\R{#4}
632 \CopyVect#1to\Pu \CopyVect#2to\Pd
633 \Circlewithcenter\C radius\R
634 \segment(\Pu)(\Pd)\SegmentArg(\Pu)(\Pd)to\Diru
635 \edef\Dird{\fpeval{\Diru+90}}\Pbox(\C)[b]{C}[2]
636 \IntersectionOfLines(\Pu)(\Diru:1)and(\C)(\Dird:1)to\Int
637 \SegmentLength(\C)(\Int)to\A
638 \fptest{\A > \R}{\PackageError{euclideangeometry}%
639 {Distance of line \A\space larger than radius \R. No intersections}%
640 {Check your data; correct and retry}}{%
641 \LegFromHypotenuse\R AndOtherLeg\A to\B
642 \AddVect\Int and\Diru:-\B to\Pt \edef#5{\Pt}
643 \SymmetricalPointOf\Pt respect\Int to\Pq \edef#6{\Pq}
644 }}
645 % \end{macrocode}
646 %
647 % Another useful macro determines the point \meta{p2} symmetric
648 % to a given point \meta{p1} with respect to a given segment the
649 % end points of which are \meta{Segm1} and \meta{Segm2}:
650 %\begin{ttsyntax}
651 %\cs{Segment}\parg{Segm1}\parg{Segm2}SymmetricPointOf\marg{p1} to\meta{p2}
652 %\end{ttsyntax}
653 % where, as usual, the input data may be explicit or macro defined
654 % coordinates, while the output result should be a macro name.
655 % \begin{macrocode}
656 \def\Segment(#1)(#2)SymmetricPointOf#3to#4{%
657 \SegmentArg(#1)(#2)to\Sanguno\edef\Sangdue{\fpeval{\Sanguno+90}}
658 \IntersectionOfLines(#1)(\Sanguno:1)and(#3)(\Sangdue:1)to\Smed
659 \SymmetricalPointOf#3respect\Smed to#4\ignorespaces}
660 % \end{macrocode}
661 %
662 % This useful macro draws a circle given its \meta{center} and the
663 % coordinates of the \meta{point} which the circumference should pass
664 % through. The syntax is:
665 %\begin{ttsyntax}
666 %\cs{CircleThrough}\parg{[point}WithCenter\marg{center}
667 %\end{ttsyntax}
668 % As usual, the parameters are all explicit or macro defined complex
669 % numbers.
670 % \begin{macrocode}
671 \def\CircleThrough#1WithCenter#2{%
672 \SegmentLength(#1)(#2)to\Radius
673 \Circlewithcenter#2radius\Radius}
674 % \end{macrocode}
675 % The above macro is the building block for a simple macro that draws
676 % two circles that cross at a given point; but it is so simple that
677 % it is not worth defining a macro: if the user wants to try his/her
678 % ability, s/he may define:
679 %\begin{flushleft}\obeylines
680 %| \NewDocumentCommand{r() r() r()}{%|
681 %| \CircleThrough#3 WithCenter{#1}|
682 %| \CircleThrough#3 WithCenter{#2}\ignorespaces}|
683 %\end{flushleft}
684 % where \cs{ignorespaces} may be superfluous, but is always a safety action
685 % when defining commands to be used within the \amb{picture} environment.
686 % In any case see example~15 in \file{euclideangeometry-man.pdf}
687 %^^A\ref{fig:two-intersecting-circles}.
688 %
689 % If it is necessary to find the intersections of two circles that
690 % do not share a previously known point; we can use the following
691 % macro. Analytically given the equations of two circumferences,
692 % it is necessary to solve a system of two second degree equations
693 % the processing of which ends up with a second degree polynomial
694 % that might have real roots (the coordinates of the intersection
695 % points), or two coincident roots (the circles are tangent), or
696 % complex roots (the circles do not intersect), or they may be
697 % indefinite (the two circles heve the same center and the same
698 % radii). Let us exclude the last case, although it would be trivial
699 % to create the macro with a test that controls such situation. But
700 % even the analysis of the discriminant of the second degree equation
701 % requires a complicated code.
702 %
703 % On the opposite a simple drawing of the two circles, with centers
704 % $C_1$ and $C_2$ and radii $R_1$ and $R_2$, with the centers distance
705 % of $ a= |C_1-C_2|$, allows to understand that in order to have
706 % intersections: $(\alpha)$ if $a\leq \max(R_1,R_2)$ (the center
707 % of a circle is contained within the other one) then it must be
708 % $ a \geq |R_1 - R_2|$, where the ‘equals’ sign applies when the
709 % circles are internally tangent; $(\beta)$ otherwise
710 % $a \geq \max(R_1,R_2)$ and it must be $a \leq R_1+R_2$ , where
711 % the ‘equals’ sign applies when the circles are externally tangent.
712 % In conclusion in any case il the range $|R_1-R_2|\leq a\leq R_1+R_2$
713 % is where the two circles intersect, while outside this distance
714 % range the circles do not intersect.
715 %
716 % For simplicity let us assume that $R_1 \geq R_2$; the macro can
717 % receive the circle data in any order, but the macro very easily
718 % switches their data so that circle number~1 is the one with larger
719 % radius. If the distance $a$ is outside the allowed range, there
720 % are no intersections, therefore a warning message is output and the
721 % intersection point coordinates are both set to \texttt{0,0}, so that
722 % processing continues with non sense data; the remaining geometric
723 % construction based on such intersection points might continue with
724 % other error messages or to absurd results; a string message to the
725 % user who, having read the documentation, understand the problem and
726 % provides for.
727 %
728 % The new macro has the following syntax:
729 %\begin{ttsyntax}
730 %\cs{TwoCirclesIntersections}\parg{C1}\parg{C2}withradii\marg{R1} and\marg{R2} to\meta{P1} and\meta{P2}
731 %\end{ttsyntax}
732 % where the symbols in input may be macros or explicit numerical
733 % values; the output point coordinates \meta{P1} and \meta{P2}
734 % should be definable single tokens, therefore the surrounding
735 % braces are not necessary.
736 % \begin{macrocode}
737 \def\TwoCirclesIntersections(#1)(#2)withradii#3and#4to#5and#6{%
738 \fptest{#3 >=#4}{%
739 \edef\Cuno{#1}\edef\Cdue{#2}%
740 \edef\Runo{#3}\edef\Rdue{#4}%
741 }{%
742 \edef\Cdue{#2}\edef\Cuno{#2}%
743 \edef\Rdue{#3}\edef\Runo{#4}%
744 }
745 % \end{macrocode}
746 % Above we switched the circle data so as to be sure that symbols relating
747 % to circle ‘one’ refer to the circle with larger (or equal) radius.
748 % Now we define the centers distance in macro \cs{A}; the test if \cs{A}
749 % lays in the correct range, otherwise we output a warning message.
750 % \begin{macrocode}
751 \SegmentLength(\Cuno)(\Cdue)to\A
752 \edef\TCIdiffR{\fpeval{\Runo-\Rdue}}\edef\TCIsumR{\fpeval{\Runo+\Rdue}}
753 \fptest{\TCIdiffR > \A || \A > \TCIsumR}{%
754 \edef#5{0,0}\edef#6{0,0}% Valori assurdi se i cerchi non si intersecano
755 \PackageWarning{euclideangeometry}{%
756 ***********************************\MessageBreak
757 Circles do not intersect \MessageBreak
758 Check centers and radii and retry \MessageBreak
759 Both intersection point are set to \MessageBreak
760 (0,0) therefore expect errors \MessageBreak
761 ***********************************\MessageBreak}%
762 }{%
763 % \end{macrocode}
764 % Here we are within the correct range and we proceed with the
765 % calculations. We take as a temporary reference the segment
766 % that joins the centers. The common chord that joins the
767 % intersection points is perpendicular to such a segment crossing
768 % it by a distance $c$ form $C_1$, and, therefore by a distance
769 % $a-c$ from $C_2$; this chord forms two isosceles triangles with the
770 % centers; the above segment bisects such triangles, forming four right
771 % triangles; their hypotenuses equal the radii of the respective
772 % circles; their bases $h$ are all equal to half the chord; Pythagoras'
773 % theorem allows us to write:
774 %\[
775 %\left\{
776 % \begin{aligned}
777 % h^2 &= R_1^2 - c^2\\
778 % h^2 &= R_2^2 - (a-c)^2
779 % \end{aligned}
780 %\right.
781 %\]
782 % Solving for $c$, we get:
783 %\[\left\{
784 %\begin{aligned}
785 %c &= \frac{R_1^2 - R_2^2 + a^2 }{2a}\\
786 %h &= \sqrt{R_1^2 -c^2}
787 %\end{aligned}
788 %\right.
789 %\]
790 % \begin{macrocode}
791 \SegmentArg(\Cuno)(\Cdue)to\Acompl
792 \SubVect\Cuno from\Cdue to \Cdue
793 \edef\CI{\fpeval{(\Runo^2 - \Rdue^2 +\A^2)/(2*\A)}}
794 \edef\H{\fpeval{sqrt(\Runo^2 - \CI^2)}}
795 \CopyVect\CI,-\H to\Puno
796 \CopyVect\CI,\H to\Pdue
797 % \end{macrocode}
798 % Now we do not need anymore the chord intersection distance \cs{CI}
799 % any more, so we can use for other tasks, and we create a vector with
800 % absolute coordinates; We then add the rotated vector corresponding
801 % to the base \cs{H} so as to get the absolute chord extrema \cs{PPuno}
802 % and \cs{PPdue}.
803 % \begin{macrocode}
804 \MultVect\CI,0 by\Acompl:1 to\CI
805 \AddVect\Cuno and\CI to\CI
806 \MultVect\Puno by\Acompl:1 to\PPunorot
807 \AddVect\PPunorot and \Cuno to \PPuno
808 \MultVect\Pdue by\Acompl:1 to\PPduerot
809 \AddVect\PPduerot and \Cuno to \PPdue
810 \edef#5{\PPuno}\edef#6{\PPdue}%
811 }%
812 }
813 % \end{macrocode}
814 % It may be noticed that the first intersection point, assigned to
815 % parameter |#5| is the one found along the orthogonal direction
816 % to the vector form $C_1$ to $C_2$, obtained by a rotation of
817 % $90^\circ$ counterclockwise.
818 % The whole construction of the geometry described above is shown
819 % in figure~16 in the user manual \file{euclideangeometry-man.pdf}.
820 %
821 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
822 % \subsection{Triangle special points}
823 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
824 % Here we have the macros to find the special points on a triangle
825 % side that are the “foot” of special lines from one vertex to the
826 % opposite side. We already described the circumcircle and the
827 % circumcenter, but that is a separate case, because the circumcenter
828 % is not the intersection of special lines from one vertex to the
829 % opposite base. The special lines we are interested in here are
830 % the height, the median, and the bisector
831 % The macros have the same aspect |\Triangle...Base|, where the dots
832 % are replaced with each of the (capitalised) special line names.
833 % Their syntaxes are therefore very similar:
834 %\begin{ttsyntax}
835 %\cs{TriangleMedianBase}\meta{vertex} on\meta{base1} and\meta{base2} to\meta{M}
836 %\cs{TriangleHeightBase}\meta{vertex} on\meta{base1} and\meta{base2} to\meta{H}
837 %\cs{TrinagleBisectorBase}\meta{vertex} on\meta{base1} and\meta{base2} to\meta{B}
838 %\end{ttsyntax}
839 % where \meta{vertex} contains one of the vertices coordinates, and
840 % \meta{base1} and \meta{base2} are the end points of the side
841 % opposite to that triangle vertex; \meta{M}, meta{H}, and \meta{B}
842 % are the intersections of these special lines from the \meta{vertex}
843 % to the opposite side; in order, they are the foot of the median,
844 % the foot of the height; the foot of the bisector. The construction
845 % of the median foot \meta{M} is trivial because this foot is the base
846 % center; the construction of the height foot is a little more
847 % complicated, because it is necessary to find the exact direction
848 % of the perpendicular from the vertex to the base in order to
849 % find the intersection \meta{H}; the construction of the bisector
850 % base implies finding the exact direction of the two sides starting at the
851 % \meta{vertex}, and taking the mean direction, which is trivial if
852 % polar coordinates are used; at this point the bisector line is completely
853 % determined and the intersection with the base line \meta{B} is
854 % easily obtained.
855 % \begin{macrocode}
856
857 \def\TriangleMedianBase#1on#2and#3to#4{%
858 \SubVect#1from#2to\TMBu \SubVect#1from#3to\TMBd
859 \SubVect\TMBu from\TMBd to\Base
860 \ScaleVect\Base by0.5to\TMBm\AddVect#2and\TMBm to#4\ignorespaces}
861 %
862 \def\TriangleHeightBase#1on#2and#3to#4{%
863 \SubVect#2from#3to\Base
864 \ArgOfVect\Base to\Ang \CopyVect\fpeval{\Ang+90}:1 to\Perp
865 \IntersectionOfLines(#1)(\Perp)and(#2)(\Base)to#4\ignorespaces}
866 %
867 \def\TriangleBisectorBase#1on#2and#3to#4{%
868 \SubVect#2from#1to\Luno \SubVect#3from#1to\Ldue
869 \SubVect#2from#3to\Base
870 \ArgOfVect\Luno to\Arguno \ArgOfVect\Ldue to\Argdue
871 \edef\ArgBis{\fpeval{(\Arguno+\Argdue)/2}}%
872 \CopyVect \ArgBis:1to \Bisect
873 \IntersectionOfLines(#2)(\Base)and(#1)(\Bisect)to#4\ignorespaces}
874 % \end{macrocode}
875 % Having defined the previous macros, it becomes very easy to create
876 % the macros to find the\emph{barycenter}, the \emph{orthocenter},
877 % the\emph{incenter}; for the \emph{circumcenter} and the
878 % \emph{circumcircle} we have already solved the question with the
879 % |\ThreePointCircleCenter| and the |ThreePointCircle| macros; for
880 % homogeneity, we create here their aliases with the same form as
881 % the new “center” macros. Actually, for the “circle” macros,
882 % once the center is known, there is no problem with the circumcircle,
883 % while for the incircle it suffices a macro to determine the distance
884 % of the incenter from one of the triangle sides; such a macro is going to
885 % be defined in a little while; it is more general than simply to
886 % determine the radius of the incircle.
887 % \begin{macrocode}
888
889 \let\TriangleCircumcenter\ThreePointCircleCenter
890 \let\TriangleCircummcircle\ThreePointCircle
891 % \end{macrocode}
892 %
893 % The other “center” macros are the following; they all consist
894 % in finding two of the specific triangle lines, and finding their
895 % intersection. Therefore for the barycenter we intersect two
896 % median lines; for the orthocenter we intersect two height lines;
897 % for the incenter we intersect two bisector lines;
898 % \begin{macrocode}
899
900 \def\TriangleBarycenter(#1)(#2)(#3)to#4{%
901 \TriangleMedianBase#1on#2and#3to\Pa
902 \TriangleMedianBase#2on#3and#1to\Pb
903 \DistanceAndDirOfVect#1minus\Pa to\ModPa and\AngPa
904 \DistanceAndDirOfVect#2minus\Pb to\ModPb and\AngPb
905 \IntersectionOfLines(#1)(\AngPa)and(#2)(\AngPb)to#4}
906
907 \def\TriangleOrthocenter(#1)(#2)(#3)to#4{%
908 \TriangleHeightBase#1on#2and#3to\Pa
909 \TriangleHeightBase#2on#3and#1to\Pb
910 \DistanceAndDirOfVect#1minus\Pa to\ModPa and\AngPa
911 \DistanceAndDirOfVect#2minus\Pb to\ModPb and\AngPb
912 \IntersectionOfLines(#1)(\AngPa)and(#2)(\AngPb)to#4}
913
914 \def\TriangleIncenter(#1)(#2)(#3)to#4{%
915 \TriangleBisectorBase#1on#2and#3to\Pa
916 \TriangleBisectorBase#2on#3and#1to\Pb
917 \DistanceAndDirOfVect#1minus\Pa to\ModPa and\AngPa
918 \DistanceAndDirOfVect#2minus\Pb to\ModPb and\AngPb
919 \IntersectionOfLines(#1)(\AngPa)and(#2)(\AngPb)to#4}
920 % \end{macrocode}
921 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
922 %\subsection{Other specific service macros}\label{ssec:ellissi}
923 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
924 %
925 % And here it comes the general macro to determine the distance
926 % of a point from a segment or from a line that contains that
927 % segment; it may be used for determining the radius of the
928 % incenter, but it is going to be used also for other purposes.
929 % Its syntax is the following:
930 %\begin{ttsyntax}
931 %\cs{DistanceOfPoint}\meta{point} from\parg{P1}\parg{P2}to\meta{distance}
932 %\end{ttsyntax}
933 % where \meta{point} is a generic point; \meta{P1} and \meta{P2}
934 % are a segment end points, or two generic points on a line;
935 % \meta{distance} is the macro that receives the computed scalar
936 % distance value.
937 % \begin{macrocode}
938
939 \def\DistanceOfPoint#1from(#2)(#3)to#4{%
940 \SubVect#2from#3to\Base \MultVect\Base by0,1to\AB
941 \IntersectionOfLines(#1)(\AB)and(#2)(\Base)to\D
942 \SubVect#1from\D to\D
943 \ModOfVect\D to#4}
944 % \end{macrocode}
945 % The following macros are specific to solve other little geometrical
946 % problems that arise when creating more complicated constructions.
947 %
948 % The |\AxisFromAxisAndFocus| is an unhappy name that describes
949 % the solution of an ellipse relationship between the ellipse axes
950 % and the focal distance
951 %\begin{equation} a^2 = b^2 + c^2\label{equ:axes-foci}\end{equation}
952 % This relation exists between the “semi” values, but it works equally
953 % well with the full values. Evidently $a$ is the largest quantity and
954 % refers to the main ellipse axis, the one that passes through the two
955 % foci; $b$ refers to the other shorter ellipse axis and $c$ refers to
956 % the foci; $b$ and $c$ are smaller than $a$, but there is no specific
957 % relationship among these two quantities It goes by itself that
958 % these statements apply to a veritable ellipse, not to a circle,
959 % that is the special case where $b=a$ and $c=0$.
960 %
961 % Since to solve the above equation we have one unknown and two
962 % known data, but we do not know what they represent, we have to
963 % assume some relationship exist between the known data; therefore
964 % if $a$ is known it must be entered as the first macro argument;
965 % otherwise $a$ is the unknown and the first Argument has to be the
966 % smaller one among $b$ and $c$. Since $b$ and$c$ may come from other
967 % computation the user has a dilemma: which is the smaller one?
968 % But this is a wrong approach; of course if the user knows which is the
969 % smaller, s/he can use the macro by entering the data in the proper
970 % order; but the user is determining the main axis, therefore it better
971 % that s/he uses directly the second macro |\MainAxisFromAxisAndFocus|
972 % that directly computes $a$ disregarding the order with which $b$
973 % and $c$ are entered; the macro name suggests to enter $b$ first
974 % and $c$ second, but it is irrelevant thanks to the sum properties.
975 % Summarising:
976 %\begin{itemize}[noitemsep]
977 %\item if the main axis is known use |\AxisFromAxisAndFocus| by
978 % entering the main axis as the first argument; otherwise
979 %\item ~
980 % \begin{itemize}
981 % \item if it is known which is smaller among $b$ and $c$, it is
982 % possible to use |\AxisFromAxisAndFocus| by entering the smaller
983 % one as the first argument; otherwise
984 % \item determine the main axis by using |\MainAxisFromAxisAndFocus|
985 % \end{itemize}
986 %\end{itemize}
987 % Their syntaxes of these two commands are basically the following:
988 %\begin{ttsyntax}
989 %\cs{AxisFromAxisAndFocus}\meta{main axis} and\meta{axis or focus} to\meta{focus or axis}
990 %\cs{MainAxisFromAxisAndFocus}\meta{axis or focus} and\meta{focus or axis} to\meta{main axis}
991 %\end{ttsyntax}
992 % but it is possible to enter the data in a different way with the
993 % first command; the described syntax is the suggested one.
994 % Evidently \meta{axis or focus} and \meta{focus or axis} imply
995 % that if you specify the focus in one of the two, you have to
996 % specify the axis in the other one.
997 % \begin{macrocode}
998
999 \def\AxisFromAxisAndFocus#1and#2to#3{%
1000 \fptest{abs(#1)>abs(#2)}%
1001 {\edef#3{\fpeval{sqrt(#1**2-#2**2)}}}%
1002 {\edef#3{\fpeval{sqrt(#2**2+#1**2)}}}}
1003
1004 \def\MainAxisFromAxisAndFocus#1and#2to#3{%
1005 \edef#3{\fpeval{sqrt(#2**2+#1**2)}}}
1006 % \end{macrocode}
1007 % The following macros allow to determine some scalar values relative
1008 % to segments; in the second one the order of the segment end points is
1009 % important, because the computed argument refers to the vector $P_2 - P_1$.
1010 % Their syntaxes are the following:
1011 %\begin{ttsyntax}
1012 %\cs{SegmentLength}\parg{P1}\parg{P2}to\meta{length}
1013 %\cs{SegmentArg}\parg{P1}\parg{P2}to\meta{argument}
1014 %\end{ttsyntax}
1015 % Both \meta{length} and \meta{argument} are macros that contain
1016 % scalar quantities; the argument is in the range
1017 % $-180^\circ <\Phi \leq +180^\circ$.
1018 % \begin{macrocode}
1019
1020 \def\SegmentLength(#1)(#2)to#3{\SubVect#1from#2to\Segm
1021 \ModOfVect\Segm to#3}
1022
1023 \def\SegmentArg(#1)(#2)to#3{\SubVect#1from#2to\Segm
1024 \GetCoord(\Segm)\SegmX\SegmY\edef#3{\fpeval{atand(\SegmY,\SegmX)}}%
1025 \ignorespaces}
1026 % \end{macrocode}
1027 %
1028 % In the following sections we need some transformations, in
1029 % particular the affine shear one. The macros we define here are
1030 % not for general use, but are specific for the purpose of this package.
1031 %
1032 % The fist macro shears a segment, or better a vector that goes
1033 % from point $P_1$ to point $P_2$ with a horizontal shear
1034 % factor/angle $\alpha$; the origin of the vector does not vary
1035 % and remains $P_1$ but the arrow tip of the vector is moved
1036 % according to the shear factor; in practice this shearing macro
1037 % is valid only for vectors that start from any point laying on
1038 % the $x$ axis. The shear factor $\alpha$ is the angle of the
1039 % \emph{clock wise} rotation vector operator by which the vertical
1040 % coordinate lines get rotated with respect to their original position.
1041 % The syntax is the following:
1042 %\begin{ttsyntax}
1043 %\cs{ShearVect}\parg{P1}\parg{P2}by\meta{shear} to\meta{vector}
1044 %\end{ttsyntax}
1045 % where \meta{P1} and \meta{P2} are the initial and final points of the
1046 % vector to be sheared with the \meta{shear} angle, and the result is put
1047 % in the output \meta{vector}
1048 % \begin{macrocode}
1049
1050 \def\ShearVect(#1)(#2)by#3to#4{%
1051 \SubVect#1from#2to\AUX
1052 \GetCoord(\AUX)\Aux\Auy
1053 \edef\Aux{\fpeval{\Aux + #3*\Auy}}%
1054 \edef\Auy{\fpeval{\Auy}}%
1055 \AddVect\Aux,\Auy and#1to#4\ignorespaces}
1056
1057 % \end{macrocode}
1058 % Again we have another different |\ScaleVector| macro that takes in input
1059 % the starting and ending points of a vector, and scales the vector
1060 % independently of the initial point.
1061 % \begin{macrocode}
1062
1063 \def\ScaleVector(#1)(#2)by#3to#4{%
1064 % Scala per il fattore #3 il vettore da #1 a #2
1065 \SubVect#1from#2to\AUX
1066 \ScaleVect\AUX by#3to\AUX
1067 \AddVect\AUX and#1to#4\ignorespaces}
1068 % \end{macrocode}
1069 %
1070 % The following macro to draw a possibly sheared ellipse appears
1071 % complicated; but in reality it is not much different from a
1072 % “normal” ellipse drawing command. In oder to do the whole work
1073 % the ellipse center is set in the origin of the axes, therefore
1074 % it is not altered by the shearing process; everything else is
1075 % horizontally sheared by the shear angle $\alpha$. In particular the
1076 % 12~nodes and control point that are required by the Bézier
1077 % splines that draw the four ellipse quarters. It is this multitude
1078 % of shearing commands that makes the macro mach longer and apparently
1079 % complicated.
1080 % The syntax is the following:
1081 %\begin{ttsyntax}
1082 %\cs{Sellisse}\meta{$\star$}\marg{h-axis}\marg{v-axis}\oarg{shear}
1083 % \end{ttsyntax}
1084 % where the optional asterisk is used to mark and label the Bézier
1085 % spline nodes and the control points of the possibly sheared ellipse;
1086 % without the asterisk the ellipse is drawn without any “decoration”;
1087 % the optional \meta{shear} is as usual the angle of the sheared
1088 % vertical coordinate lines; its default value is zero.
1089 % \begin{macrocode}
1090 %
1091 \NewDocumentCommand\Sellisse{s m m O{0}}{\bgroup
1092 \CopyVect#2,#3to\Ptr \ScaleVect\Ptr by-1to\Pbl
1093 \CopyVect#2,-#3to\Pbr \ScaleVect\Pbr by-1to\Ptl
1094 \edef\Ys{\fpeval{tand{#4}}}%
1095 \edef\K{\fpeval{4*(sqrt(2)-1)/3}}%
1096 %
1097 \ShearVect(0,0)(0,#3)by\Ys to\Pmt
1098 \ShearVect(0,0)(0,-#3)by\Ys to\Pmb
1099 \ShearVect(0,0)(#2,0)by\Ys to\Pmr
1100 \ShearVect(0,0)(-#2,0)by\Ys to\Pml
1101 %
1102 \ShearVect(\Pmr)(\Ptr)by\Ys to\Ptr
1103 \ShearVect(\Pml)(\Ptl)by\Ys to\Ptl
1104 \ShearVect(\Pmr)(\Pbr)by\Ys to\Pbr
1105 \ShearVect(\Pml)(\Pbl)by\Ys to\Pbl
1106 %
1107 \IfBooleanTF{#1}{\Pbox(\Ptr)[bl]{P_{tr}}\Pbox(\Pbl)[tr]{P_{bl}}%
1108 \Pbox(\Pbr)[tl]{P_{br}}\Pbox(\Ptl)[br]{P_{tl}}%
1109 \polygon(\Pbr)(\Ptr)(\Ptl)(\Pbl)}{}%
1110 %
1111 \ScaleVector(\Pmr)(\Ptr)by\K to\Crt
1112 \ScaleVector(\Pmr)(\Pbr)by\K to\Crb
1113 \ScaleVector(\Pml)(\Ptl)by\K to\Clt
1114 \ScaleVector(\Pml)(\Pbl)by\K to\Clb
1115 \ScaleVector(\Pmt)(\Ptr)by\K to\Ctr
1116 \ScaleVector(\Pmt)(\Ptl)by\K to\Ctl
1117 \ScaleVector(\Pmb)(\Pbr)by\K to\Cbr
1118 \ScaleVector(\Pmb)(\Pbl)by\K to\Cbl
1119 %
1120 \IfBooleanTF{#1}{%
1121 \Pbox(\Crt)[l]{C_{rt}}\Pbox(\Crb)[l]{C_{rb}}
1122 \Pbox(\Clt)[r]{C_{lt}}\Pbox(\Clb)[r]{C_{lb}}
1123 \Pbox(\Ctr)[b]{C_{tr}}\Pbox(\Ctl)[b]{C_{tl}}
1124 \Pbox(\Cbr)[t]{C_{br}}\Pbox(\Cbl)[t]{C_{bl}}
1125 %
1126 \Pbox(\Pmr)[l]{P_{mr}}\Pbox(\Pmt)[b]{P_{mt}}%
1127 \Pbox(\Pml)[r]{P_{ml}}\Pbox(\Pmb)[t]{P_{mb}}%
1128 %
1129 \polygon(\Pbr)(\Ptr)(\Ptl)(\Pbl)\thicklines}{}%
1130 %
1131 \moveto(\Pmr)
1132 \curveto(\Crt)(\Ctr)(\Pmt)
1133 \curveto(\Ctl)(\Clt)(\Pml)
1134 \curveto(\Clb)(\Cbl)(\Pmb)
1135 \curveto(\Cbr)(\Crb)(\Pmr)
1136 \fillstroke
1137 \egroup}
1138
1139 % \end{macrocode}
1140 % This user macro is used to call the |\Sellisse| macro with
1141 % the desired parameters, but also to act with it on order
1142 % to fill or stroke the ellipse contour, and to select some
1143 % settings such as the contour line thickness, or the color
1144 % of the ellipse contour or interior.
1145 % the syntax is the following:
1146 %\begin{ttsyntax}
1147 %\cs{XSellisse}\meta{$\star$1}\parg{center}\oarg{angle}\aarg{shear}\marg{h-axis}\marg{v axis}\meta{$\star$2}\oarg{settings1}\oarg{settings2}
1148 %\end{ttsyntax}
1149 % where there are two optional asterisks, \meta{$\star$1} and
1150 % \meta{$\star$2}; the first one controls the coloring of the ellipse:
1151 % if present the interior is filled, if absent the contour is stroked; the
1152 % second one controls the way a possibly sheared ellipse appears:
1153 % if present, the construction is shown, if absent only the final result
1154 % is shown; \meta{center} is optional: if present, the ellipse center is
1155 % specified; if absent, its center is at the origin of the picture axes;
1156 % \meta{angle} is optional with default value zero: if absent,
1157 % the ellipse is not rotated and the \meta{h-axis} remains horizontal,
1158 % while the \meta{v-axis} remains vertical, while if present and with a
1159 % non vanishing value, the ellipse is rotated counterclockwise
1160 % the amount specified, and, of course, if the value is negative,
1161 % the rotation is clockwise. The optional parameter \meta{shear},
1162 % if present, shears the ellipse paralle the \meta{h-axis} direction;
1163 % the \meta{settings1} and \meta{settings2} operate as described
1164 % for command \cs{Xellisse}.
1165 % \begin{macrocode}
1166
1167 \NewDocumentCommand\XSellisse{ s D(){0,0} O{0} D<>{0} m m s O{} o }%
1168 {\IfBooleanTF#1{\let\fillstroke\fillpath}%
1169 {\let\fillstroke\strokepath}%
1170 \put(#2){\rotatebox{#3}{#8\relax
1171 \IfBooleanTF{#7}{\Sellisse*{#5}{#6}[#4]}%
1172 {\Sellisse{#5}{#6}[#4]}%
1173 \IfValueTF{#9}{\let\fillstroke\strokepath
1174 #9\Sellisse{#5}{#7}[#4]}{}}}%
1175 \ignorespaces}
1176 % \end{macrocode}
1177 %
1178 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1179 % \subsection{Regular polygons and special ellipses}
1180 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1181 %
1182 % We finally arrive to more complex macros used to create special
1183 % polygons and special ellipses.
1184 %
1185 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1186 % \subsubsection{Regular polygons}
1187 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1188 % Regular polygons are not that special; it is possible to draw them
1189 % by using the |\multiput| or |\xmultiput| commands, but a single
1190 % command that does everything by itself with more built in
1191 % functionalities is much handier. The new command |\RegPolygon|
1192 % has the following syntax:
1193 %\begin{ttsyntax}
1194 %\cs{RegPoligon}\meta{$\star$}\parg{center}\marg{radius}\marg{number}\oarg{angle}\aarg{settings}
1195 %\end{ttsyntax}
1196 % where \meta{$\star$} is an optional asterisk; its presence means
1197 % that the polygon interior is filled, instead of the polygon
1198 % contour being stroked; the \meta{center} specification of the
1199 % polygon is optional; if it is omitted, the polygon center goes
1200 % to the origin of the |picture| coordinates; \meta{radius} is the
1201 % mandatory radius of the circumscribed circle, or, in other words,
1202 % the distance of each polygon vertex form the \meta{center}; the
1203 % mandatory \meta{number} is an integer that specifies the number of
1204 % polygon sides; the first vertex that is being drawn by this
1205 % command, has an angle of zero degrees with respect to the
1206 % \meta{center}; if a different initial \meta{angle} different from
1207 % zero is desired, it is specified through this optional argument;
1208 % possibly the angle bracketed optional \meta{setting} parameter
1209 % may be used to specify, for example, the line thickness for the
1210 % contour, and/or the color for the polygon contour or interior.
1211 % See the documentation \file{euclideangeometry-man.pdf} for more
1212 % information and usage examples.
1213 % \begin{macrocode}
1214 \newcount\RPI
1215 \NewDocumentCommand\RegPolygon{s D(){0,0} m m O{0} D<>{\relax} }{{%
1216 %\countdef\RPI=258
1217 \RPI=0
1218 \CopyVect#5:#3to\P
1219 \CopyVect\fpeval{360/#4}:1to\R
1220 \put(#2){#6\relax
1221 \moveto(\P)\fpdowhile{\RPI < #4}%
1222 {\MultVect\P by\R to\P
1223 \lineto(\P)\advance\RPI by 1}%
1224 \IfBooleanTF{#1}%
1225 {\fillpath}{#6\strokepath}}}\ignorespaces}
1226 %%%%%%%%%
1227 \def\DirOfVect#1to#2{\GetCoord(#1)\t@X\t@Y
1228 \ModOfVect#1to\@tempa
1229 \unless\ifdim\@tempa\p@=\z@
1230 \DividE\t@X by\@tempa to\t@X
1231 \DividE\t@Y by\@tempa to\t@Y
1232 \fi\MakeVectorFrom\t@X\t@Y to#2\ignorespaces}%
1233 % \end{macrocode}
1234 %
1235 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1236 % \subsubsection{The Steiner ellipse}
1237 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1238 % The construction of the Steiner ellipse is very peculiar; it is
1239 % almost intuitive that any triangle has infinitely many internal
1240 % tangent ellipses; therefore it is necessary to state some other
1241 % constraints to find one specific ellipse out from this unlimited set.
1242 %
1243 % One such ellipse is the Steiner one, obtained by adding the
1244 % constraint that the ellipse be tangent to the median points
1245 % of the triangle sides. But one thing is the definition, and
1246 % another totally different one is to find the parameters of
1247 % such an ellipse; and working with ruler and compass, it is
1248 % necessary to find a procedure to draw such an ellipse.
1249 %
1250 % The construction described here and implemented with the
1251 % |SteinerEllipse| macro is based on the following steps, each
1252 % one requiring the use of some of the commands and/or
1253 % transformations described in the previous sections.
1254 %\begin{enumerate}[noitemsep]
1255 %^^A
1256 %\item Given a generic triangle (the coordinates of its three
1257 % vertices) it is not necessary, but it is clearer to explain,
1258 % if the triangle is shifted and rotated so as to have one of
1259 % its sides horizontal, and the third vertex in the upper part
1260 % of the |picture| drawing. So we first perform the initial
1261 % shift and rotation and memorise the parameters of this
1262 % transformation so that, at the end of the procedure, we can
1263 % put back the triangle (and its Steiner ellipse) in its
1264 % original position. Let us call this shifted and rotated triangle
1265 % with the symbol $T_0$.
1266 %^^A
1267 %\item We transform $T_0$ with an affine shear transformation into an
1268 % isosceles triangle $T_1$ that has the same base and the same
1269 % height as $T_0$. We memorise the shear “angle” so as to proceed
1270 % to an inverse transformation when the following steps are completed:
1271 % let be $\alpha$ this shear angle; geometrically it represents the
1272 % angle of the sheared vertical coordinate lines with respect
1273 % to the original vertical position.\label{enum:shear}
1274 %^^A
1275 %\item With another affine vertical scaling transformation we transform $T_1$ into an equilateral triangle $T_2$; the ratio of the vertical
1276 % transformation equals the ratio between the $T_2$ to the
1277 % $T_1$ heights; we memorise this ratio for the reverse transformation
1278 % at the end of the procedure.\label{enum:ratio}
1279 %^^A
1280 %\item The Steiner ellipse of the equilateral triangle $T_2$ is its
1281 % incircle. We are almost done; we just have to proceed to the
1282 % inverse transformations; getting back from $T_2$ to $T_1$ first implies
1283 % transforming the incircle of $T_2$ into an ellipse with its
1284 % vertical axis scaled by the inverse ratio memorised in
1285 % step~\ref{enum:ratio}.
1286 %^^A
1287 %\item The second inverse transformation by the shear angle is easy
1288 % with the passage from $T_1$ to $T_0$, but it would be more difficult
1289 % for transforming the ellipse into the sheared ellipse. We have already
1290 % defined the |\Sellipse| and the |\XSellipse| macros that may take
1291 % care of the ellipse shear transformation; we already memorised the
1292 % shear angle in step~\ref{enum:shear}, therefore the whole procedure,
1293 % except for putting back the triangle, is almost done.
1294 %^^A
1295 %\item Eventually we perform the last shifting and rotating transformation
1296 % and the whole construction is completed.
1297 %^^A
1298 %\end{enumerate}
1299 %
1300 % The new macro Steiner ellipse has therefore the following syntax:
1301 %\begin{ttsyntax}
1302 %\cs{SteinerEllipse}\meta{$\star$}\parg{P1}\parg{P2}\parg{P3}\oarg{diameter}
1303 %\end{ttsyntax}
1304 % where \meta{P1}, \meta{P2}, \meta{P3} are the vertices of the
1305 % triangle; \meta{$\star$} is an optional asterisk; without it
1306 % the maro draws only the final result, that contains only the
1307 % given triangle and its Steiner ellipse; on the opposite, if the asterisk
1308 % is used the whole construction from $T_0$ to its Steiner ellipse
1309 % is drawn; the labelling of points is done with little dots of
1310 % the default \meta{diameter} or a specified value; by default it is a 1\,pt
1311 % diameter, but sometimes it would be better to use a slightly
1312 % larger value (remembering that 1\,mm — about three points —
1313 % is already too much).
1314 % Please refer to the documentation file \file{euclideangeometry-man.pdf}
1315 % for usage examples and suggestions.
1316 % \begin{macrocode}
1317 %
1318
1319 \NewDocumentCommand\SteinerEllipse{s d() d() d() O{1}}{\bgroup
1320 %
1321 \IfBooleanTF{#1}{}{\put(#2)}{%
1322 \CopyVect0,0to\Pu
1323 \SubVect#2from#3to\Pd
1324 \SubVect#2from#4to\Pt
1325 \ModAndAngleOfVect\Pd to\M and\Rot
1326 \MultVect\Pd by-\Rot:1 to\Pd \MultVect\Pt by-\Rot:1 to\Pt
1327 \IfBooleanTF{#1}{}{\rotatebox{\Rot}}{\makebox(0,0)[bl]{%
1328 \Pbox(\Pu)[r]{P_1}[#5]<-\Rot>\Pbox(\Pd)[t]{P_2}[#5]<-\Rot>
1329 \Pbox(\Pt)[b]{P_3}[#5]<-\Rot>%
1330 \polygon(\Pu)(\Pd)(\Pt)%
1331 \edef\B{\fpeval{\M/2}}\edef\H{\fpeval{\B*tand(60)}}
1332 \IfBooleanTF{#1}{\Pbox(\B,\H)[b]{H}[#5]
1333 \polygon(\Pu)(\B,\H)(\Pd)}{}%
1334 \edef\R{\fpeval{\B*tand(30)}}
1335 \IfBooleanTF{#1}{\Pbox(\B,\R)[bl]{C}[#5]
1336 \Circlewithcenter\B,\R radius{\R}}{}%
1337 \GetCoord(\Pt)\Xt\Yt\edef\VScale{\fpeval{\Yt/\H}}
1338 \IfBooleanTF{#1}{\polyline(\Pu)(\B,\Yt)(\Pd)
1339 \Pbox(\B,\Yt)[b]{V}[#5]}{}%
1340 \edef\Ce{\fpeval{\R*\VScale}}
1341 \IfBooleanTF{#1}{\Xellisse(\B,\Ce){\R}{\Ce}
1342 \Pbox(\B,\Ce)[r]{C_e}[#5]\Pbox(\B,0)[t]{B}[#5]}{}%
1343 \SubVect\B,0 from\Pt to\SlMedian
1344 \IfBooleanTF{#1}{\Dotline(\B,0)(\Pt){2}[1.5]}{}%
1345 \ModAndAngleOfVect\SlMedian to\Med and\Alfa
1346 \edef\Alfa{\fpeval{90-\Alfa}}
1347 \IfBooleanTF{#1}{\Dotline(\B,\Yt)(\B,0){2}[1.5]
1348 \Pbox(\fpeval{\B+\Ce*tand{\Alfa}},\Ce)[l]{C_i}[#5]
1349 \VectorArc(\B,0)(\B,15){-\Alfa}
1350 \Pbox(\fpeval{\B+2.5},14)[t]{\alpha}[0]}{}%
1351 \edef\a{\R}\edef\b{\Ce}%
1352 \CopyVect\fpeval{\B+\Ce*tand{\Alfa}},\Ce to\CI
1353 \XSellisse(\CI)<\Alfa>{\R}{\Ce}
1354 }}}%
1355 \egroup\ignorespaces}
1356 \let\EllisseSteiner\SteinerEllipse
1357 % \end{macrocode}
1358 %
1359 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1360 %\subsubsection{The ellipse that is internally tangent to a triangle while one of its foci is prescribed}
1361 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1362 % We now are going to tackle another problem. As we said before, any
1363 % triangle has an infinite set of internally tangent circles, unless
1364 % some further constraint is specified.
1365 %
1366 % Another problem of this kind is the determination and geometrical
1367 % construction of an internally tangent ellipse when one focus is
1368 % specified; of course since the whole ellipse is totally internal
1369 % to the triangle, we assume that the user has already verified
1370 % that the coordinates of the focus fall inside the triangle.
1371 % We are not going to check this feature in place of the user;
1372 % after all, if the user draws the triangle within a |picture| image,
1373 % together with the chosen focus, is suffices a glance to verify that
1374 % such focus lays within the triangle perimeter.
1375 %
1376 % The geometrical construction is quite complicated, but it is
1377 % described in a paper by Estevão V.~Candia on \TB~2019 \textbf{40}(3);
1378 % it consists of the following steps.
1379 %\begin{enumerate}[noitemsep]
1380 %^^A
1381 %\item Suppose you have specified a triangle by means of its three
1382 % vertices, and a point inside it to play the role of a focus; it
1383 % is necessary to find the other focus and the main axis length in
1384 % order to have a full description of the ellipse.
1385 %^^A
1386 %\item To do so, it is necessary to find the focus three symmetrical
1387 % points with respect to the three sides.
1388 %^^A
1389 %\item The center of the three point circle through these symmetrical
1390 % points is the second focus.
1391 %^^A
1392 %\item The lines that join the second focus to the three symmetrical
1393 % points of the first focus, intersect the triangle sides in three
1394 % points that result to be the tangency points of the ellipse to the
1395 % triangle.
1396 %^^A
1397 %\item Chosen one of these tangency points and computing the sum of its
1398 % distances from both foci, the total length of the ellipsis main axis
1399 % is found.
1400 %^^A
1401 %\item Knowing both foci, the total inter focal distance is found,
1402 % therefore equation~\eqref{equ:axes-foci} allows to find the other
1403 % axis length.
1404 %^^A
1405 %\item The inclination of the focal segment gives us the the rotation
1406 % to which the ellipse is subject, and the middle point of such
1407 % segment gives the ellipse center.
1408 %^^A
1409 %\item At this point we have all the necessary elements to draw
1410 % the ellipse.
1411 %^^A
1412 %\end{enumerate}
1413 %
1414 % We need another little macro to find the symmetrical points;
1415 % if the focus $F$ and its symmetrical point $P$ with respect
1416 % to a side/segment, the intersection of such segment $F-P$ with
1417 % the side is the segment middle point $M$; from this property
1418 % we derive the formula $P= 2M -F$. Now $M$ is also the
1419 % intersection of the line passing through $F$ and perpendicular
1420 % to the side. Therefore it is particularly simple to compute,
1421 % but its better to have available a macro that does the whole
1422 % work; here it is, but it assumes the the center of symmetry is
1423 % already known:
1424 % \begin{macrocode}
1425
1426 \def\SymmetricalPointOf#1respect#2to#3{\ScaleVect#2by2to\Segm
1427 \SubVect#1from\Segm to#3\ignorespaces}
1428 % \end{macrocode}
1429 % And its syntax is the following:
1430 %\begin{ttsyntax}
1431 %\cs{SymmetricalPointOf}\meta{focus} respect\meta{symmetry center}
1432 %\qquad to\meta{symmetrical point}
1433 %\end{ttsyntax}
1434 % where the argument names are self explanatory.
1435 %
1436 % The overall macro that executes all the passages described in
1437 % the above enumeration follows; the reader can easily recognise
1438 % the various steps, since the names of the macros are self
1439 % explanatory; the $S_i$ point names are the symmetrical ones
1440 % to the first focus $F$; the $M_i$ points are the centers of
1441 % symmetry; the $F'$ point is the second focus; the $T_i$ points
1442 % are the tangency points. The macro |\EllipseWithFOcus| has the
1443 % following syntax:
1444 %\begin{ttsyntax}
1445 %\cs{EllipseWithFocus}\meta{$\star$}\parg{P1}\parg{P2}\parg{P3}\parg{focus}
1446 %\end{ttsyntax}
1447 % where \meta{P1}, \meta{P2}, \meta{P3} are the triangle vertices
1448 % and \meta{focus} contains the first focus coordinates; the
1449 % optional asterisk, as usual, selects the construction steps
1450 % versus the final result: no asterisk, no construction steps.
1451 % \begin{macrocode}
1452
1453 \NewDocumentCommand\EllipseWithFocus{s d() d() d() d()}{\bgroup%
1454 \CopyVect#2to\Pu
1455 \CopyVect#3to\Pd
1456 \CopyVect#4to\Pt
1457 \CopyVect#5to\F
1458 \polygon(\Pu)(\Pd)(\Pt)
1459 \Pbox(\Pu)[r]{P_1}[1.5pt]\Pbox(\Pd)[t]{P_2}[1.5pt]
1460 \Pbox(\Pt)[b]{P_3}[1.5pt]\Pbox(\F)[b]{F}[1.5pt]
1461 \SegmentArg(\Pu)(\Pt)to\At
1462 \SegmentArg(\Pu)(\Pd)to\Ad
1463 \SegmentArg(\Pd)(\Pt)to\Au
1464 \IntersectionOfLines(\Pu)(\At:1)and(\F)(\fpeval{\At+90}:1)to\Mt
1465 \IntersectionOfLines(\Pd)(\Ad:1)and(\F)(\fpeval{\Ad+90}:1)to\Md
1466 \IntersectionOfLines(\Pd)(\Au:1)and(\F)(\fpeval{\Au+90}:1)to\Mu
1467 \IfBooleanTF{#1}{\Pbox(\Mt)[br]{M_3}[1.5pt]\Pbox(\Md)[t]{M_2}[1.5pt]
1468 \Pbox(\Mu)[b]{M_1}[1.5pt]}{}
1469 \SymmetricalPointOf\F respect\Mu to\Su
1470 \IfBooleanTF{#1}{\Pbox(\Su)[l]{S_1}[1.5pt]}{}
1471 \SymmetricalPointOf\F respect \Md to\Sd
1472 \IfBooleanTF{#1}{\Pbox(\Sd)[t]{S_2}[1.5pt]}{}
1473 \SymmetricalPointOf\F respect \Mt to\St
1474 \IfBooleanTF{#1}{\Pbox(\St)[r]{S_3}[1.5pt]}{}
1475 \IfBooleanTF{#1}{\ThreePointCircle*(\Su)(\Sd)(\St)}%
1476 {\ThreePointCircle(\Su)(\Sd)(\St)}
1477 \CopyVect\C to\Fp \Pbox(\Fp)[l]{F'}[1.5pt]
1478 \IfBooleanTF{#1}{%
1479 \Dotline(\F)(\St){2}[1.5pt]
1480 \Dotline(\F)(\Sd){2}[1.5pt]
1481 \Dotline(\F)(\Su){2}[1.5pt]}{}
1482 \IntersectionOfSegments(\Pu)(\Pt)and(\Fp)(\St)to\Tt
1483 \IntersectionOfSegments(\Pu)(\Pd)and(\Fp)(\Sd)to\Td
1484 \IntersectionOfSegments(\Pd)(\Pt)and(\Fp)(\Su)to\Tu
1485 \IfBooleanTF{#1}{\Pbox(\Tu)[l]{T_1}[1.5pt]
1486 \Pbox(\Td)[b]{T_2}[1.5pt]
1487 \Pbox(\Tt)[tl]{T_3}[1.5pt]
1488 \Dashline(\Fp)(\Su){1}\Dashline(\Fp)(\Sd){1}\Dashline(\Fp)(\St){1}}{}
1489 \DistanceAndDirOfVect\Fp minus\Tt to\DFp and\AFu
1490 \DistanceAndDirOfVect\F minus\Tt to\DF and\AF
1491 \SegmentCenter(\F)(\Fp)to\CE \Pbox(\CE)[b]{C}[1.5pt]
1492 \edef\a{\fpeval{(\DFp+\DF)/2}}
1493 \SegmentArg(\F)(\Fp)to\AngFocalAxis
1494 \SegmentLength(\F)(\CE)to\c
1495 \AxisFromAxisAndFocus\a and\c to\b
1496 \Xellisse(\CE)[\AngFocalAxis]{\a}{\b}[\thicklines]
1497 \VECTOR(-30,0)(120,0)\Pbox(120,0)[t]{x}[0]
1498 \VECTOR(0,-20)(0,130)\Pbox(0,130)[r]{y}[0]\Pbox(0,0)[tr]{O}[1.5pt]
1499 \egroup\ignorespaces}
1500 \let\EllisseConFuoco\EllipseWithFocus
1501 % \end{macrocode}
1502 %
1503 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1504 % \section{Comments on this package}
1505 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1506 %
1507 % In general we found very comfortable to draw ellipses and
1508 % to define macros to draw not only such shapes or filled elliptical
1509 % areas, but also to create “legends” with coloured backgrounds and
1510 % borders; such applications found their way in other works.
1511 % But here we dealt with other geometrical problems. The accompanying
1512 % document |euclideangeometry-man.pdf| describes much clearly with
1513 % examples what you can do with the macros described in this package.
1514 % In facts, this file just describes the package macros, and it gives
1515 % some ideas on how to extend the ability of |curve2e| to draw
1516 % geometrical diagrams.
1517 % The users who would like to modify or to add some functionalities
1518 % are invited to do so; I will certainly acknowledge their contributions
1519 % and even add their names to the list of authors.
1520 %
1521 % As long as I can, I enjoy playing with \LaTeX\ and its wonderful
1522 % facilities; but, taking into consideration my age, I would invite
1523 % the users to consider the possibility of assuming the maintenance
1524 % of this package.
1525 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1526 %\section{Acknowledgements}
1527 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1528 % I am very grateful to Enrico Gregorio who let me know the several
1529 % glitches I made in my first version; besides being a real \TeX wizard,
1530 % he is a wise person and suggested me several things that was important
1531 % to change, because they could offer risks of confusion with other
1532 % packages.
1533 %
1534 %\iffalse
1535 %</package>
1536 %\fi
1537 % \Finale
1538 %