summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_misc.lua
blob: 834317aae4f4825a1a58427f9492db8bbd02f850 (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
-- tkz_elements_functions_maths.lua
-- date 23/12/14
-- version 1.60c
-- Copyright 2023  Alain Matthes
-- This work may be distributed and/or modified under the
-- conditions of the LaTeX Project Public License, either version 1.3
-- of this license or (at your option) any later version.
-- The latest version of this license is in
--   http://www.latex-project.org/lppl.txt
-- and version 1.3 or later is part of all distributions of LaTeX
-- version 2005/12/01 or later.
-- This work has the LPPL maintenance status “maintained”.
-- The Current Maintainer of this work is Alain Matthes.
-- ----------------------------------------------------------------
-- 
-- ----------------------------------------------------------------
function get_points (obj)
if obj.type == 'line' then return   obj.pa,obj.pb
 elseif
  obj.type  == 'triangle' then return   obj.pa,obj.pb,obj.pc
  elseif 
  obj.type == 'circle' then   return obj.center,obj.through
  elseif 
  obj.type == 'ellipse' then   return obj.pc,obj.pa,obj.pb
  elseif 
  obj.type == 'square' or obj.type == 'rectangle' or obj.type == 'quadrilateral' or obj.type == 'parallelogram'
  then   return obj.pa,obj.pb,obj.pc,obj.pd
end
end

function set_lua_to_tex (t)
   for k,v in pairs(t) do
    token.set_macro(v,_ENV[v],'global')
   end
end  
-- version 1.60 center pour deux cercles ?
function radical_center (C1,C2,C3)
   local t1,t2,t3,t4
   t1,t2 = radical_axis_ (C1.center,C1.through,C2.center,C2.through)
   if C3 == nil then
    return  intersection_ll_ (t1,t2,C1.center,C2.center)
   else
   t3,t4 = radical_axis_ (C3.center,C3.through,C2.center,C2.through)
return intersection_ll_ (t1,t2,t3,t4)
end
end
-- version 1.60 modif case 2 circles
function  radical_circle (C1,C2,C3)
   local rc
    if C3 == nil then
       rc = radical_center (C1,C2)
       return C1 : orthogonal_from (rc)
    else
   rc = radical_center (C1,C2,C3)
 return C1 : orthogonal_from (rc)
end
end
-- version 1.60 new
function circles_position(C1,C2)
   local d,max,min
   d = point.mod(C1.center-C2.center)
   max = C1.radius + C2.radius
   min = math.abs ( C1.radius - C2.radius)
   if d > max then return "outside"
      elseif d == max then return "outside tangent" -- epsilon
      elseif d == min then return "inside tangent" -- epsilon
      elseif d < min then return "inside"
      else return "intersect"
   end
end
-- version 1.60 new
function midcircle_(C1,C2)
   local state,r,s,t1,t2,T1,T2,p,a,b,c,d,Cx,Cy,i,j
   state = circles_position(C1,C2)
   i = barycenter_ ({C2.center,C1.radius},{C1.center,-C2.radius})
   j = barycenter_ ({C2.center,C1.radius},{C1.center,C2.radius})
   t1,t2 = tangent_from_ (C1.center,C1.through,i)
   T1,T2 = tangent_from_ (C2.center,C2.through,i)
      
   if (state == 'outside') or (state == 'outside tangent')then
         p = math.sqrt(point.mod(i-t1)*point.mod(i-T1))
   return circle  : radius (i,p)
   elseif state == 'intersect' then
        r,s = intersection (C1,C2)
   return circle  : radius (i,point.mod(r-i)) , circle  : radius (j,point.mod(r-j))
   elseif (state == 'inside') or (state == 'inside tangent') then
      a,b = intersection_lc_ (C1.center,C2.center,C1.center,C1.through)
      c,d = intersection_lc_ (C1.center,C2.center,C2.center,C2.through)
       
      if C1.radius < C2.radius then 
         z.u, z.v, z.r, z.s = a, b, c, d
      else
         z.u, z.v, z.r, z.s = c, d, a, b
      end
      
      if  (in_segment_ (z.s,z.v,z.u) == true) 
      then 
      Cx = circle  :  diameter (z.r,z.v)
      Cy = circle  :  diameter (z.u,z.s)
      else
      Cx = circle  :  diameter (z.s,z.v)
      Cy = circle  :  diameter (z.u,z.r)
      end
      if (Cx.radius) < (Cy.radius) then
         return Cy : orthogonal_from (j) 
      else
         return Cx : orthogonal_from (j)
 end
 end
end