summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tkz-base/tkz-tools-math.tex
blob: f42d57397bc02866138b75875e90acd9c28fa9ea (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
% tkz-tools-math.tex
% Copyright 2020 by Alain Matthes
% This file may be distributed and/or modified
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
\def\fileversion{3.02c}
\def\filedate{2020/01/24} 
\typeout{2020/01/24 3.02c  tkz-tools-math.tex}     
\makeatletter
%<-------------------------------------------------------------------------->
%  \tkzpointnormalised    normalise un point A-->A' tq ||v(OA')=1||
% équivalent de \pgfpointnormalised avec fp
% example
% \tkzpointnormalised{%
% \pgfpointdiff{\pgfpointanchor{A}{center}}
%              {\pgfpointanchor{B}{center}}}

% or
% \pgf@x=1 cm
% \pgf@y=12 cm 
% \tkzpointnormalised{}
%<--------------------------------------------------------------------------
\def\tkzpointnormalised#1{%
\pgf@process{#1}%
\edef\tkz@den{\fpeval{sqrt((\pgf@x)^2+(\pgf@y)^2)}}
\edef\tkz@coordx{\fpeval{\pgf@x/\tkz@den}}
\edef\tkz@coordx{\fpeval{round(\tkz@coordx,5)}}
\edef\tkz@coordy{\fpeval{\pgf@y/\tkz@den}}
\edef\tkz@coordy{\fpeval{round(\tkz@coordy,5)}}
\pgf@x = \tkz@coordx pt
\pgf@y = \tkz@coordy pt
}
%<-------------------------------------------------------------------------->
% restaure and save length
\def\tkz@save@length{%
\global\let\tkz@temp@length\tkzLengthResult}%
\def\tkz@restore@length{%
 \global\let\tkzLengthResult\tkz@temp@length }% 
%<-------------------------------------------------------------------------->
%    \tkzCalcLength      Distance entre deux points en pt ou en cm  avec xfp 
% \veclen mais avec fp 
%  option cm le résultat est en cm sinon en pt
%<-------------------------------------------------------------------------->
\pgfkeys{tkzcalclen/.cd,
       cm/.is if         = tkzLengthIncm,
       cm/.default       = true}   

\def\tkzCalcLength{\pgfutil@ifnextchar[{\tkz@CalcLength}{\tkz@CalcLength[]}}  
\def\tkz@CalcLength[#1](#2,#3){%
\pgfkeys{tkzcalclen/.cd, cm = false}
\pgfqkeys{/tkzcalclen}{#1}%   
\begingroup
\tkz@@CalcLength(#2,#3){tkzLengthResult}
\iftkzLengthIncm 
   \pgfmathparse{\tkz@xfpMathLen pt/1cm}
	\edef\tkz@xfpMathLen{\fpeval{round(\pgfmathresult,5)}}
   \global\let\tkzLengthResult\tkz@xfpMathLen  
\fi 
\endgroup
}%
\def\tkz@@CalcLength(#1,#2)#3{%
\pgfpointdiff{\pgfpointanchor{#1}{center}}%
             {\pgfpointanchor{#2}{center}}%
\edef\tkz@xfpMathLen{\fpeval{sqrt((\pgf@x)^2+(\pgf@y)^2)}}
\edef\tkz@xfpMathLen{\fpeval{round(\tkz@xfpMathLen,5)}}
\global\expandafter\edef\csname #3\endcsname{\tkz@xfpMathLen}
}
%<-------------------------------------------------------------------------->
\def\tkzGetLength#1{%
\global\expandafter\edef\csname #1\endcsname{\tkzLengthResult}}  
%<-------------------------------------------------------------------------->
%     \tkzpttocm  passage de pt   cm div par 28.45274
%<-------------------------------------------------------------------------->
\def\tkzpttocm(#1)#2{%
\begingroup  
  \pgfmathparse{#1/1cm}
  \edef\tkz@mathresult{\fpeval{round(\pgfmathresult,5)}}
  \global\let\tkz@mathresult\tkz@mathresult
  \global\expandafter\edef\csname #2\endcsname{\tkz@mathresult}% 
\endgroup
}%
%<-------------------------------------------------------------------------->
%     \tkzcmtopt  passage de cm   pt mul par 28.45274
%<--------------------------------------------------------------------------
\def\tkzcmtopt(#1)#2{%
\begingroup 
   \pgfmathparse{#1/1pt}
  \edef\tkz@mathresult{\fpeval{round(\pgfmathresult,5)}}
  \global\let\tkz@mathresult\tkz@mathresult
  \global\expandafter\edef\csname #2\endcsname{\tkz@mathresult}% 
\endgroup  
}% 
%<-------------------------------------------------------------------------->
%                          Slope
%<-------------------------------------------------------------------------->
\def\tkzFindSlope{\tkz@FindSlope}
\def\tkz@FindSlope(#1,#2)#3{%
\begingroup
   \tkzpointnormalised{\pgfpointdiff{\pgfpointanchor{#1}{center}}%
                                    {\pgfpointanchor{#2}{center}}}
     \edef\tkz@Slope{\fpeval{\pgfmath@tonumber{\pgf@y}/\pgfmath@tonumber{\pgf@x}}}
     \edef\tkz@Slope{\fpeval{round(\tkz@Slope,5)}}
    \global\expandafter\edef\csname #3\endcsname{\tkz@Slope}%  
\endgroup
}
%  Schrodinger's cat idea 03/01/20
\tikzset{xfp/.code={%
\pgfmathdeclarefunction*{veclen}{2}{%
\begingroup%
    \pgfmath@x##1pt\relax%
    \pgfmath@y##2pt\relax%
    \edef\tkz@xfpMathLen{\fpeval{sqrt((\pgf@x)^2+(\pgf@y)^2)}}
    \pgfmath@returnone\tkz@xfpMathLen pt%
\endgroup%
}}}
 \makeatother 
\endinput