[latex3-commits] [git/LaTeX3-latex3-latex3] master: l3draw: Intersection of circles (f0b8488)

Joseph Wright joseph.wright at morningstar2.co.uk
Fri Feb 9 09:03:39 CET 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/f0b84886b462baea85b91392f98a53d4230bb838

>---------------------------------------------------------------

commit f0b84886b462baea85b91392f98a53d4230bb838
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Fri Feb 9 08:03:39 2018 +0000

    l3draw: Intersection of circles
    
    A 'stress test' for working expandably.


>---------------------------------------------------------------

f0b84886b462baea85b91392f98a53d4230bb838
 l3trial/l3draw/l3draw-points.dtx |  154 ++++++++++++++++++++++++++++++++++++++
 l3trial/l3draw/l3draw.dtx        |   10 ++-
 2 files changed, 163 insertions(+), 1 deletion(-)

diff --git a/l3trial/l3draw/l3draw-points.dtx b/l3trial/l3draw/l3draw-points.dtx
index ee2ee3a..2a85aa4 100644
--- a/l3trial/l3draw/l3draw-points.dtx
+++ b/l3trial/l3draw/l3draw-points.dtx
@@ -295,6 +295,160 @@
 % \end{macro}
 % \end{macro}
 %
+% \begin{macro}[EXP]{\draw_point_intersect_circles:nnnnn}
+% \begin{macro}[EXP]{\@@_point_intersect_circles_auxi:nnnnnnn}
+% \begin{macro}[EXP]
+%   {
+%     \@@_point_intersect_circles_auxii:nnnnnnn,
+%     \@@_point_intersect_circles_auxii:ffnnnnn,
+%     \@@_point_intersect_circles_auxiii:nnnnnnn,
+%     \@@_point_intersect_circles_auxiii:ffnnnnn
+%   }
+%  \begin{macro}[EXP]
+%    {
+%      \@@_point_intersect_circles_auxiv:nnnnnnnn,
+%      \@@_point_intersect_circles_auxiv:fnnnnnnn
+%    }
+%  \begin{macro}[EXP]
+%    {
+%      \@@_point_intersect_circles_auxv:nnnnnnnnn,
+%      \@@_point_intersect_circles_auxv:ffnnnnnnn
+%    }
+%  \begin{macro}[EXP]
+%    {
+%      \@@_point_intersect_circles_auxvi:nnnnnnnn,
+%      \@@_point_intersect_circles_auxvi:fnnnnnnn
+%    }
+% \begin{macro}[EXP]
+%   {
+%     \@@_point_intersect_circles_auxvii:nnnnnnn,
+%     \@@_point_intersect_circles_auxvii:fffnnnn
+%   }
+%   Another long expansion chain to get the values in the right places.
+%   We have two circles, the first with center $(a, b)$ and radius~$r$,
+%   the second with center $(c, d)$ and radius~$s$. We use the intermediate
+%   values
+%   \begin{align*}
+%     e &= c - a \\
+%     f &= d - b \\
+%     p &= \sqrt{e^{2} + f^{2}} \\
+%     k &= \frac{p^{2} + r^{2} - s^{2}}{2p}
+%   \end{align*}
+%   in either
+%   \begin{align*}
+%     P_{x} &= a + \frac{ek}{p} + \frac{f}{p}\sqrt{r^{2} - k^{2}} \\
+%     P_{y} &= b + \frac{fk}{p} - \frac{e}{p}\sqrt{r^{2} - k^{2}}
+%   \end{align*}
+%   or
+%   \begin{align*}
+%     P_{x} &= a + \frac{ek}{p} - \frac{f}{p}\sqrt{r^{2} - k^{2}} \\
+%     P_{y} &= b + \frac{fk}{p} + \frac{e}{p}\sqrt{r^{2} - k^{2}}
+%   \end{align*}
+%   depending on which solution is required. The rest of the work is simply
+%   forcing the appropriate expansion and shuffling arguments.
+%    \begin{macrocode}
+\cs_new:Npn \draw_point_intersect_circles:nnnnn #1#2#3#4#5
+  {
+    \@@_point_expand:nnN {#1} {#3}
+      \@@_point_intersect_circles_auxi:nnnnnnn
+      {#2} {#4} {#5}
+  }
+\cs_new:Npn \@@_point_intersect_circles_auxi:nnnnnnn #1#2#3#4#5#6#7
+  {
+    \@@_point_intersect_circles_auxii:ffnnnnn
+      { \fp_eval:n {#5} } { \fp_eval:n {#6} } {#1} {#2} {#3} {#4} {#7}
+  }
+%    \end{macrocode}
+%   At this stage we have all of the information we need, fully expanded:
+%   \begin{enumerate}[label = \#\arabic*, font = \ttfamily]
+%     \item $r$
+%     \item $s$
+%     \item $a$
+%     \item $b$
+%     \item $c$
+%     \item $d$
+%     \item $n$
+%   \end{enumerate}
+%   Once we evaluate $e$ and $f$, the co-ordinate $(c,d)$ is no longer
+%   required: handy as we will need various intermediate values in the
+%   following.
+%    \begin{macrocode}
+\cs_new:Npn \@@_point_intersect_circles_auxii:nnnnnnn #1#2#3#4#5#6#7
+  {
+    \@@_point_intersect_circles_auxiii:ffnnnnn
+      { \fp_eval:n { #5 - #3 } }
+      { \fp_eval:n { #6 - #4 } }
+      {#1} {#2} {#3} {#4} {#7}
+  }
+\cs_generate_variant:Nn \@@_point_intersect_circles_auxii:nnnnnnn { ff }
+\cs_new:Npn \@@_point_intersect_circles_auxiii:nnnnnnn #1#2#3#4#5#6#7
+  {
+    \@@_point_intersect_circles_auxiv:fnnnnnnn
+      { \fp_eval:n { sqrt( #1 ^ 2 + #2 ^ 2 ) } }
+      {#1} {#2} {#3} {#4} {#5} {#6} {#7}
+  }
+\cs_generate_variant:Nn \@@_point_intersect_circles_auxiii:nnnnnnn { ff }
+%    \end{macrocode}
+%   We now have $p$: we pre-calculate $1/p$ as it is needed a few times and
+%   is relatively expensive. We also need $r^{2}$ twice so deal with that
+%   here too.
+%    \begin{macrocode}
+\cs_new:Npn \@@_point_intersect_circles_auxiv:nnnnnnnn #1#2#3#4#5#6#7#8
+  {
+    \@@_point_intersect_circles_auxv:ffnnnnnnn
+      { \fp_eval:n { 1 / #1 } }
+      { \fp_eval:n { #4 ^ 2 } }
+      {#1} {#2} {#3} {#5} {#6} {#7} {#8}
+  }
+\cs_generate_variant:Nn \@@_point_intersect_circles_auxiv:nnnnnnnn { f }
+\cs_new:Npn \@@_point_intersect_circles_auxv:nnnnnnnnn #1#2#3#4#5#6#7#8#9
+  {
+    \@@_point_intersect_circles_auxvi:fnnnnnnn
+      { \fp_eval:n { 0.5 * #1 * ( #2 + #3 * #3 - #6 * #6 ) } }
+      {#1} {#2} {#4} {#5} {#7} {#8} {#9}
+  }
+\cs_generate_variant:Nn \@@_point_intersect_circles_auxv:nnnnnnnnn { ff }
+%    \end{macrocode}
+%   We now have all of the intermediate values we require, with one division
+%   carried out up-front to avoid doing this expensive step twice:
+%   \begin{enumerate}[label = \#\arabic*, font = \ttfamily]
+%     \item $k$
+%     \item $1/p$
+%     \item $r^{2}$
+%     \item $e$
+%     \item $f$
+%     \item $a$
+%     \item $b$
+%     \item $n$
+%   \end{enumerate}
+%   There are some final pre-calculations, $k/p$,
+%   $\frac{\sqrt{r^{2} - k^{2}}}{p}$ and the usage of $n$, then we
+%   can yield a result.
+%    \begin{macrocode}
+\cs_new:Npn \@@_point_intersect_circles_auxvi:nnnnnnnn #1#2#3#4#5#6#7#8
+  {
+    \@@_point_intersect_circles_auxvii:fffnnnn
+      { \fp_eval:n { #1 * #2 } }
+      { \int_if_odd:nTF {#8} { 1 } { -1 } }
+      { \fp_eval:n { sqrt( #3 - #1 ^ 2 ) * #2 } }
+      {#4} {#5} {#6} {#7}
+  }
+\cs_generate_variant:Nn \@@_point_intersect_circles_auxvi:nnnnnnnn { f }
+\cs_new:Npn \@@_point_intersect_circles_auxvii:nnnnnnn #1#2#3#4#5#6#7
+  {
+    { \fp_to_dim:n { #6 + #4 * #1 +      #2 * #3 * #5 } }
+    { \fp_to_dim:n { #7 + #5 * #1 + -1 * #2 * #3 * #4 } }
+  }
+\cs_generate_variant:Nn \@@_point_intersect_circles_auxvii:nnnnnnn { fff }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
 % \subsection{Vector support}
 %
 % As well as co-ordinates relative to the drawing 
diff --git a/l3trial/l3draw/l3draw.dtx b/l3trial/l3draw/l3draw.dtx
index 61853f9..575627c 100644
--- a/l3trial/l3draw/l3draw.dtx
+++ b/l3trial/l3draw/l3draw.dtx
@@ -118,10 +118,18 @@
 %
 % \begin{function}[EXP]{\draw_point_intersect_lines:nnnn}
 %   \begin{syntax}
-%     \cs{draw_point_intersect_lines:nn} \marg{P1} \marg{P2} \marg{P3} \marg{P4}
+%     \cs{draw_point_intersect_lines:nnnn} \marg{P1} \marg{P2} \marg{P3} \marg{P4}
 %   \end{syntax}
 % \end{function}
 %
+% \begin{function}[EXP]{\draw_point_intersect_circles:nnnn}
+%   \begin{syntax}
+%     \cs{draw_point_intersect_circles:nnnnn}
+%       \marg{center1} \marg{radius1} \marg{center2} \marg{radius2} \marg{root}
+%   \end{syntax}
+%   % Note interface, cf. pgf
+% \end{function}
+%
 % \end{documentation}
 %
 % \begin{implementation}





More information about the latex3-commits mailing list