From 31fa8cd73bab8480d38dae3a89ca578f337d6bbd Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Wed, 27 Mar 2024 03:02:20 +0000 Subject: CTAN sync 202403270302 --- .../tkz/tkz-elements/latex/tkz-elements.sty | 32 +- .../tkz/tkz-elements/latex/tkz_elements_circle.lua | 13 +- .../tkz/tkz-elements/latex/tkz_elements_class.lua | 4 +- .../tkz-elements/latex/tkz_elements_ellipse.lua | 28 +- .../latex/tkz_elements_functions_circles.lua | 8 +- .../latex/tkz_elements_functions_intersections.lua | 4 +- .../latex/tkz_elements_functions_lines.lua | 16 +- .../latex/tkz_elements_functions_maths.lua | 186 +++++++++- .../latex/tkz_elements_functions_matrices.lua | 374 +++++++++++++++++++++ .../latex/tkz_elements_functions_points.lua | 4 +- .../latex/tkz_elements_functions_regular.lua | 4 +- .../latex/tkz_elements_functions_triangles.lua | 22 +- .../tkz/tkz-elements/latex/tkz_elements_line.lua | 27 +- .../tkz/tkz-elements/latex/tkz_elements_main.lua | 8 +- .../tkz-elements/latex/tkz_elements_matrices.lua | 219 ++++++++++++ .../tkz/tkz-elements/latex/tkz_elements_misc.lua | 4 +- .../latex/tkz_elements_parallelogram.lua | 4 +- .../tkz/tkz-elements/latex/tkz_elements_point.lua | 130 ++++--- .../latex/tkz_elements_quadrilateral.lua | 4 +- .../tkz-elements/latex/tkz_elements_rectangle.lua | 4 +- .../tkz-elements/latex/tkz_elements_regular.lua | 4 +- .../tkz/tkz-elements/latex/tkz_elements_square.lua | 4 +- .../tkz-elements/latex/tkz_elements_triangle.lua | 41 ++- .../tkz/tkz-elements/latex/tkz_elements_vector.lua | 32 +- 24 files changed, 1025 insertions(+), 151 deletions(-) create mode 100644 macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_matrices.lua create mode 100644 macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_matrices.lua (limited to 'macros/latex/contrib/tkz/tkz-elements/latex') diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz-elements.sty b/macros/latex/contrib/tkz/tkz-elements/latex/tkz-elements.sty index d3618f8e31..f7416d8e4f 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz-elements.sty +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz-elements.sty @@ -1,5 +1,5 @@ % encoding : utf8 -% tkz-elements.sty v2.00c +% tkz-elements.sty v2.20c % Copyright 2024 Alain Matthes % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either version 1.3 @@ -11,23 +11,27 @@ % This work has the LPPL maintenance status “maintained”. % The Current Maintainer of this work is Alain Matthes. -\ProvidesPackage{tkz-elements}[2024/02/04 v2.00c Graphic Object Library] +\ProvidesPackage{tkz-elements}[2024/03/25 v2.20c Graphic Object Library] \RequirePackage{luacode} \directlua{require "tkz_elements_main"} \newenvironment{tkzelements} { \directlua{scale=1} \directlua{tkz_epsilon=1e-8} + \directlua{tkz_dc=2} \directlua{indirect = true} - \directlua{for k,v in pairs(z) do z[k] = nil end} - \directlua{for k,v in pairs(C) do C[k] = nil end} - \directlua{for k,v in pairs(E) do E[k] = nil end} - \directlua{for k,v in pairs(L) do L[k] = nil end} - \directlua{for k,v in pairs(P) do C[k] = nil end} - \directlua{for k,v in pairs(S) do E[k] = nil end} - \directlua{for k,v in pairs(R) do C[k] = nil end} - \directlua{for k,v in pairs(Q) do T[k] = nil end} - \directlua{for k,v in pairs(T) do T[k] = nil end} + \directlua{z={} + C={} + E={} + L={} + M={} + P={} + Q={} + R={} + RP={} + S={} + T={} + V={}} \luacode} {\endluacode} @@ -53,13 +57,13 @@ end} \draw[#1](#2) ellipse [x radius=\tkzUseLua{length(z.#3,z.#2)}, y radius = \tkzUseLua{length(z.#4,z.#2)},rotate=\tkzUseLua{math.deg(slope_ (z.#3,z.#2))}]; \endgroup } -\def\tkzDN{\pgfutil@ifnextchar[{\tkz@DN}{\tkz@DN[2]}} +\def\tkzDN{\pgfutil@ifnextchar[{\tkz@DN}{\tkz@DN[2]}}% \def\tkz@DN[#1]#2{% \begingroup -\pgfkeys{/pgf/number format/.cd,std,precision=#1} +\pgfkeys{/pgf/number format/.cd,std,precision=#1}% \pgfmathprintnumber{#2} \endgroup - } +} \makeatother \endinput diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_circle.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_circle.lua index e22e3eefd0..708e7b7af3 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_circle.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_circle.lua @@ -1,6 +1,6 @@ -- tkz_elements-circles.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 @@ -82,9 +82,9 @@ end -- real -- ----------------------- function circle: power (pt) - local d + local d d = point.abs (self.center - pt) - return d * d - self.radius * self.radius + return d * d - self.radius * self.radius end ----------------------- -- points -- @@ -140,7 +140,7 @@ function circle: tangent_from (pt) t1,t2 = tangent_from_ (self.center,self.through,pt) return line :new (pt,t1),line : new (pt,t2) end - -- version 1.80 + function circle: radical_axis (C) local t1,t2 if self.radius > C.radius then @@ -151,7 +151,6 @@ function circle: tangent_from (pt) return line :new (t1,t2) end - -- version 1.80 function circle: radical_center (C1,C2) if C2 == nil then if self.radius > C1.radius then @@ -163,7 +162,7 @@ else return radical_center3 (self,C1,C2) end end - -- version 1.80 + function circle : radical_circle (C1,C2) local rc if C2 == nil then diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_class.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_class.lua index 97bdc9449d..491d237ac2 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_class.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_class.lua @@ -1,6 +1,6 @@ -- tkz_elements_class.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- from class.lua (Simple Lua Classes from Lua-users wiki) -- Compatible with Lua 5.1 (not 5.0). -- http://lua-users.org/wiki/SimpleLuaClasses DavidManura diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_ellipse.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_ellipse.lua index 98800f791e..f20b87a44f 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_ellipse.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_ellipse.lua @@ -1,6 +1,6 @@ -- tkz_elements-ellipses.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 @@ -90,18 +90,14 @@ function ellipse: tangent_at (pt) end function ellipse: tangent_from (pt) - local da,db,zx,zy,zz,u,v,L,U,V - zx = 2 * self.Rx * math.cos(self.slope) - zy = 2 * self.Rx * math.sin(self.slope) - zz = self.Fb + point(zx,zy) - s1,s2 = intersection_cc_ (pt,self.Fa,self.Fb,zz) - u,v = mediator_ (s2,self.Fa) - L = line: new (u,v) - U,U = intersection_le (L,self) + local u,v,U,V,w,s1,s2,s3,s4 + w = report_ (self.Fb,self.Fa,2 * self.Rx) + s1,s2 = intersection_cc_ (pt,self.Fa,self.Fb,w) u,v = mediator_ (s1,self.Fa) - L = line: new (pt,u) - V,V = intersection_le (L,self) - return line : new (pt,U), line : new (pt,V) + U = intersection_ll_ (u,v,self.Fb,s1) + u,v = mediator_ (s2,self.Fa) + V = intersection_ll_ (u,v,self.Fb,s2) + return line : new (pt,U) , line : new (pt,V) end function ellipse: in_out (pt) @@ -117,4 +113,10 @@ function ellipse: in_out (pt) return false end end + +function ellipse: orthoptic_circle () + local r = math.sqrt(self.Rx*self.Rx+self.Ry*self.Ry) + return circle : radius (self.center, r) +end + return ellipse \ No newline at end of file diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_circles.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_circles.lua index fe72c68c27..eacd8423a4 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_circles.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_circles.lua @@ -1,6 +1,6 @@ -- tkz_elements_functions_circles.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 @@ -44,7 +44,6 @@ function orthogonal_through_ (a,b,x,y) return circum_center_ (x,y,z) end - function inversion_ (c,p,pt) local ry = point.abs(c-p) local d = point.abs(c-pt) @@ -86,7 +85,6 @@ function radical_center_ (c1,p1,c2,p2) return h*(c2-c1)/d+c1 end --- version 1.60 center pour deux cercles ? function radical_center3 (C1,C2,C3) local t1,t2,t3,t4 t1,t2 = radical_axis_ (C1.center,C1.through,C2.center,C2.through) @@ -98,7 +96,6 @@ return intersection_ll_ (t1,t2,t3,t4) end end - function south_pole_ (c,p) local r r = point.abs (c-p) @@ -128,7 +125,6 @@ function circlepoint_ (c,t,k) return rotation_ (c,phi,t) 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.center,C1.radius,C2.center,C2.radius) diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_intersections.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_intersections.lua index 7dd2c59c32..dc44e2ae88 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_intersections.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_intersections.lua @@ -1,6 +1,6 @@ -- tkz_elements_intersections.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_lines.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_lines.lua index c9d840d89c..2dd8d6467a 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_lines.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_lines.lua @@ -1,6 +1,6 @@ -- tkz_elements_functions_lines.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 @@ -138,4 +138,16 @@ function in_segment_ (a,b,pt) else return false end +end + +function report_ (za,zb,d,pt) + local t,len + len = point.mod(zb-za) + t = d/len + if pt == nil + then + return barycenter_({za,1-t},{zb,(t)}) +else + return barycenter_({za,1-t},{zb,(t)}) +pt-za +end end \ No newline at end of file diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_maths.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_maths.lua index 63f5190f02..9b4e51d295 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_maths.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_maths.lua @@ -1,6 +1,6 @@ -- tkz_elements_functions_maths.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 @@ -126,8 +126,186 @@ function swap(a,b) b=t return a,b end +-- real func +function is_integer(x) + return x == math.round(x) +end + +function near_integer(x) + local i,r = math.modf (x) + if is_zero (r) then + return true + end + return false +end + +function residue (x) + dp,ip = math.modf (x) + return ip +end + +function is_zero (x) + return math.abs(x) < tkz_epsilon +end + +function set_zero (x) + if is_zero (x) then x=0 end + return x +end + +function math.round(num) + return math.floor(num + 0.5) +end + +function checknumber(x) + if type(x) == 'table' then + return x + else + if string.find(x, "e") then + return string.format("%.12f",x) + else + return x + end + end +end + +function decimal (x) + if string.find(x, "e") then + return string.format("%.12f",x) + else + return x + end +end -function format_number(number, decimal_places) - local format_string = string.format("%%.%df", decimal_places) +function format_number(number, dcpl) + if type(number) == 'table' then return number + else + local format_string = string.format("%%.%df", dcpl) return string.format(format_string, number) + end +end + +function get_sign(number) + local sgn + if math.abs(number) < tkz_epsilon then + sgn = "" + elseif number > 0 then + sgn = "+" + else + sgn = "-" + end + return sgn +end + +function solve_quadratic(a, b, c) + local root1, root2,delta ,sqrtdelta + if (type(a) == "number") and (type(b) == "number") and (type(c) == "number") + then + delta = b*b - 4*a*c + if delta < 0 then + root1, root2 = solve_cx_quadratic(a, b, c) + elseif delta == 0 then + root1 = -b / (2*a) + root2 = -b / (2*a) + else + sqrtdelta = math.sqrt(delta) + + root1 = (-b + sqrtdelta) / (2*a) + root2 = (-b - sqrtdelta) / (2*a) + end + else + root1, root2 = solve_cx_quadratic(a, b, c) + end + + return root1, root2 -- Two real roots +end + +function solve_cx_quadratic(a, b, c) + local d = b*b - 4*a*c + local dcx = point.sqrt(d) + local root1 = (- b + dcx) / (2*a) + local root2 = (- b - dcx) / (2*a) + return root1, root2 +end + +-- function solve_cubic(a, b, c, d) +-- local p = (3*a*c - b*b)/(3*a*a) +-- local q = (2*b*b*b - 9*a*b*c + 27*a*a*d)/(27*a*a*a) +-- local delta = q*q+4*p*p*p/27 +-- local offset = - b / (3*a) +-- if delta > tkz_epsilon then +-- local r = (- q + math.sqrt(delta))/2 +-- local s = (- q - math.sqrt(delta))/2 +-- if r > 0 then +-- u = r^(1/3) +-- else +-- u = -(-r)^(1/3) +-- end +-- if s > 0 then +-- v = s^(1/3) +-- else +-- v = -(-s)^(1/3) +-- end +-- return u + v + offset +-- end +-- if delta < 0 then +-- local u = 2 * math.sqrt( - p / 3) +-- local v = math.acos(((3*q)/(2*p)) * math.sqrt( -3 / p)) / 3 +-- local x1 = u * math.cos(v) + offset +-- local x2 = u * math.cos(v + 2 * math.pi/3) + offset +-- local x3 = u * math.cos(v - 2 * math.pi/3) + offset +-- return {x1,x2,x3} +-- end +-- if delta == 0 then +-- return {3*q/p+offset,-3*q/(2*p)+offset,-3*q/(2*p)+offset} +-- end +-- end + +function display_real (r) + local format_string,format_string + if r == nil then return "" + else + if near_integer ( r ) + then + r = math.round ( r ) + format_string = string.format("%%.%df", 0) + else + format_string = string.format("%%.%df", tkz_dc) + end + local st = string.format(format_string , r) + return st + end +end + + +function display_imag (r) + local sgn + sgn = get_sign (r) + r = math.abs(r) + if math.abs(r-1) < tkz_epsilon then + r = nil + elseif near_integer ( r ) then + r = math.abs(math.round(r)) + end + st = display_real (r) + return sgn,st +end + +function display (z) + if (type(z) == "number") then return display_real (z) else + local real, imag + real = z.re + imag = z.im + if is_zero ( imag ) then + return display_real (real) + else + str = display_real (real) + sgni,sti = display_imag (imag) + if str == "0" then + str="" + sgni = "" end + local st = str ..sgni..sti.."i" + return st + end +end end diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_matrices.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_matrices.lua new file mode 100644 index 0000000000..7d3f475570 --- /dev/null +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_matrices.lua @@ -0,0 +1,374 @@ +-- tkz_elements_functions_matrices.lua +-- date 2024/03/25 +-- version 2.20c +-- Copyright 2024 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 print_matrix(m,mstyle) + local mstyle = (mstyle or 'bmatrix') + local m = (m.type=='matrix' and m.set or m) + tex.sprint("$") + tex.sprint("\\begin{"..mstyle.."}") + for i = 1, #m do + for j = 1, #m[1] do + local x = m[i][j] + local st = display(x) + tex.sprint(st) + if j < #m[1] then tex.sprint(" & ") end + end + tex.sprint("\\\\") + end + tex.sprint("\\end{"..mstyle.."}") + tex.sprint("$") +end + +function print_array(matrix) +local mdata = (matrix.type=='matrix' and matrix.set or matrix) +tex.sprint("\\{%") + for i = 1, #mdata do + local row = mdata[i] + local row_str = "{\\{" + for j = 1, #row do + row_str = row_str .. " " .. tostring(row[j]) + if j < #row then + row_str = row_str .. " ," + end + end + if (i~=#mdata) and (j~=#row) then + if i>1 then row_str = row_str .. " \\}}," else row_str = row_str .. " \\}}," end + tex.sprint(row_str) +else + if i>1 then row_str = row_str .. " \\}}" else row_str = row_str .. " \\}}" end + tex.sprint(row_str) + end +end +tex.sprint("\\}") +end + +function mul_matrix(A, B) +local adata = (A.type=='matrix' and A.set or A) +local bdata = (B.type=='matrix' and B.set or B) +local C = {} + for i = 1, #adata do + C[i] = {} + for j = 1, #bdata[1] do + local num = adata[i][1] * bdata[1][j] + for k = 2, #adata[1] do + num = num + adata[i][k] * bdata[k][j] + end + C[i][j] = num + end + end + return matrix : new (C) +end + + +function add_matrix(A, B) +local adata = (A.type=='matrix' and A.set or A) +local bdata = (B.type=='matrix' and B.set or B) + local S = {} + for i = 1, #adata do + local T = {} + S[i] = T + for j = 1, #adata[1] do + T[j] = adata[i][j] + bdata[i][j] + end + end + return matrix : new (S) +end + +function k_mul_matrix(n, A) +local adata = (A.type=='matrix' and A.set or A) + local S = {} + for i = 1, #adata, 1 do + local T = {} + S[i] = T + for j =1, #adata[1], 1 do + T[j] = n * adata[i][j] + end + end + return matrix : new (S) +end + + +function transposeMatrix(A) +local mdata = (A.type=='matrix' and A.set or A) + local transposedMatrix = {} + for i = 1, #mdata[1] do + transposedMatrix[i] = {} + for j = 1, #mdata do + transposedMatrix[i][j] = mdata[j][i] + end + end + return matrix : new (transposedMatrix) +end + +-- Function to calculate the determinant of a square matrix +function determinant(A) + local matrix = (A.type=='matrix' and A.set or A) + if #matrix == #matrix[1] then + local n = #matrix + if n == 1 then + return matrix[1][1] -- Base case for 1x1 matrix + elseif n == 2 then + return matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1] -- Base case for 2x2 matrix + else + local det = 0 + for j = 1, n do + local minor = {} + for i = 2, n do + minor[i - 1] = {} + for k = 1, n do + if k ~= j then + minor[i - 1][#minor[i - 1] + 1] = matrix[i][k] + end + end + end + det = det + ((-1)^(j + 1)) * matrix[1][j] * determinant(minor) -- Recursive call for larger matrices + end + return det + end + else return nil end +end + +function check_square_matrix (A) + local matrix = (A.type=='matrix' and A.set or A) + if #matrix == #matrix[1] + then + return true + else + return false + end +end + + +function id_matrix (n) + local identityMatrix = {} + for i = 1, n do + identityMatrix[i] = {} + for j = 1, n do + if i == j then + identityMatrix[i][j] = 1 + else + identityMatrix[i][j] = 0 + end + end + end + return matrix : new (identityMatrix) +end + +function inverse_2x2(A) + local m = (A.type=='matrix' and A.set or A) + local a, b, c, d = m[1][1], m[1][2], m[2][1], m[2][2] + local D = A.det + if D == 0 then + return nil -- La matrice n'est pas inversible + else + local inv ={} + inv[1]={} + inv[1][1] = d / D + inv[1][2] = -b / D + inv[2]={} + inv[2][1] = -c / D + inv[2][2] = a / D + return matrix : new (inv) + end +end + +function adjugate_(A) + local m = (A.type=='matrix' and A.set or A) + if #m == 2 then + local a,b,c,d = m[2][2],-m[1][2],- m[2][1],m[1][1] + return matrix : new ({{a,b},{c,d}}) + elseif #m == 3 then + local a, b, c = m[1][1], m[1][2], m[1][3] + local d, e, f = m[2][1], m[2][2], m[2][3] + local g, h, i = m[3][1], m[3][2], m[3][3] + return transposeMatrix(matrix : new ({ + {e * i - f * h, -(d * i - f * g), d * h - e * g}, + {-(b * i - c * h), a * i - c * g, -(a * h - b * g)}, + {b * f - c * e, -(a * f - c * d), a * e - b * d} + })) + else return nil + end +end + +function inverse_3x3(A) + local D = A.det + if D == 0 then + return nil -- La matrice n'est pas inversible + else + local adj = adjugate_(A) + local m = (adj.type=='matrix' and adj.set or adj) + local inv = {} + for i = 1, 3 do + inv[i] = {} + for j = 1, 3 do + inv[i][j] = m[i][j] / D + end + end + return matrix : new (inv) + end +end + +-- inverse only for 2x2 or 3x3 matrix +function inv_matrix (A) + if A.det ==0 then tex.print("Matrix not inversible: det = 0") return nil + else + local M = (A.type=='matrix' and A.set or A) + local n = #M + if n == 2 then + local m = (A.type=='matrix' and A.set or A) + local a, b, c, d = m[1][1], m[1][2], m[2][1], m[2][2] + local D = A.det + local inv ={} + inv[1]={} + inv[1][1] = d / D + inv[1][2] = -b / D + inv[2]={} + inv[2][1] = -c / D + inv[2][2] = a / D + return matrix : new (inv) + else + local D = A.det + local adj = adjugate_(A) + local m = (adj.type=='matrix' and adj.set or adj) + local inv = {} + for i = 1, 3 do + inv[i] = {} + for j = 1, 3 do + inv[i][j] = m[i][j] / D + end + end + return matrix : new (inv) + end + end +end + +function diagonalize_ (A) + local m = (A.type=='matrix' and A.set or A) + local trace = m[1][1] + m[2][2] + local a,b = m[1][1],m[1][2] + local det = A.det + local D = trace * trace - 4 * det + if D > 0 then + local va1 = (trace + math.sqrt(D)) / 2 + local va2 = (trace - math.sqrt(D)) / 2 + return matrix : new ({{va1,0},{0,va2}}), + matrix : new ({{1,1},{ (va1 - a )/b, (va2 - a)/b}}) + else + local va1 = point (trace/2 , math.sqrt(-D)/ 2) + local va2 = point (trace/2 , - math.sqrt(-D)/ 2) + return matrix : new ({{va1,0},{0,va2}})--, + -- matrix : new ({{1,1},{ (va1 - a )/b, (va2 - a)/b}}) + end + end + + function isDiagonal_(A) + local matrix = (A.type=='matrix' and A.set or A) + if check_square_matrix (A) == true + then + for i = 1, #matrix do + for j = 1, #matrix[1] do + if i ~= j and matrix[i][j] ~= 0 then + return false + end + end + end + return true + else + return false + end + end + + function isOrthogonal_(A) + local m = (A.type=='matrix' and A.set or A) + if (check_square_matrix (A) == true) and (A.det ~=0) + then + local mT = transposeMatrix (A) + local mI = inv_matrix (A) + if mT == mI then return true else return false end + else + return false + end + end + + + function homogenization_ (A) + local m = (A.type=='matrix' and A.set or A) + if A.cols ~= 1 then + return nil + else + local a,b,c + a=m[1][1] + b=m[2][1] + c= 1 + return matrix : new ({{a},{b},{c}}) + end + end + + function get_element_( A,i,j ) + local m = (A.type=='matrix' and A.set or A) + if m[i] and m[i][j] then + return m[i][j] + end + end + + function get_htm_point(A) + local m = (A.type=='matrix' and A.set or A) + return point : new( m[1][1],m[2][1]) + end + + function htm_apply_ (A,z) + local V = homogenization_ ( 1/scale*z.mtx) + local W = A * V + return get_htm_point(W) + end + + function htm_apply_L_ (A,obj) + local x,y + x = htm_apply_ (A,obj.pa) + y = htm_apply_ (A,obj.pb) + return line : new (x,y) + end + + function htm_apply_C_ (A,obj) + local x,y + x = htm_apply_ (A,obj.center) + y = htm_apply_ (A,obj.through) + return circle : new (x,y) + end + + function htm_apply_T_ (A,obj) + local x,y,z + x = htm_apply_ (A,obj.pa) + y = htm_apply_ (A,obj.pb) + z = htm_apply_ (A,obj.pc) + return triangle : new (x,y,z) + end + + function htm_apply_Q_ (A,obj) + local x,y,z,t + x = htm_apply_ (A,obj.pa) + y = htm_apply_ (A,obj.pb) + z = htm_apply_ (A,obj.pc) + t = htm_apply_ (A,obj.pd) + if obj.type == "square" then + return square : new (x,y,z,t) + elseif obj.type == "rectangle" then + return rectangle : new (x,y,z,t) + elseif obj.type == "parallelogram" then + return parallelogram : new (x,y,z,t) + elseif obj.type == "quadrilateral" then + return quadrilateral : new (x,y,z,t) + end + end \ No newline at end of file diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_points.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_points.lua index cb91788424..ce04c2d091 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_points.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_points.lua @@ -1,6 +1,6 @@ -- tkz_elements_functions_points.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_regular.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_regular.lua index 7f71760066..bd8f7cab5b 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_regular.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_regular.lua @@ -1,6 +1,6 @@ -- tkz_elements_functions_regular.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_triangles.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_triangles.lua index d6a1cb1ecb..2e917db2f1 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_triangles.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_functions_triangles.lua @@ -1,6 +1,6 @@ -- tkz_elements_functions_triangles.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 @@ -260,6 +260,20 @@ function feuerbach_tr_ (a,b,c) intersection_cc_ (e,m,jc,hc) end -------------------- +-- ellipse -- +-------------------- +function steiner_ (a,b,c) + local g,fa,fb,delta,m,v + g = centroid_ (a,b,c) + delta = a*a+b*b+c*c -a*b-a*c-b*c + fa = (a+b+c - point.sqrt(delta))/3 + fb = (a+b+c + point.sqrt(delta))/3 + m = midpoint_(b,c) + r = (length(fa,m)+length(fb,m))/2 + v = report_ (fb,fa,r,g) + return ellipse: foci (fb,fa,v) +end +-------------------- -- miscellanous -- -------------------- @@ -274,7 +288,9 @@ function check_equilateral_ (a,b,c) C = a - b if (point.abs(A)-point.abs(B) < tkz_epsilon) and (point.abs(B)-point.abs(C) < tkz_epsilon) then - return true else return false + return true + else + return false end end diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_line.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_line.lua index d8c8944835..68a5ad843b 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_line.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_line.lua @@ -1,6 +1,6 @@ -- tkz_elements_lines.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 @@ -152,6 +152,17 @@ function line: _north_pb (d) local d = d or 1 return d/self.length *( self.north_pb - self.pb ) + self.pb end + +function line : report (d,pt) + local t + t = d/self.length + if pt == nil + then + return barycenter_({self.pa,1-t},{self.pb,(t)}) + else + return barycenter_({self.pa,1-t},{self.pb,(t)}) +pt-self.pa + end +end -------------- transformations ------------- function line: translation_pt ( pt ) return translation_ ( self.pb-self.pa,pt ) @@ -465,7 +476,7 @@ line.golden = line.sublime line.golden_gnomon = line.divine ------------------------------ --- Result -> couple of points +-- Result -> square ------------------------------ function line: square (swap) if swap == nil @@ -476,15 +487,5 @@ function line: square (swap) end end -function line : report (d,pt) - local t - t = d/self.length - if pt == nil - then - return barycenter_({self.pa,1-t},{self.pb,(t)}) -else - return barycenter_({self.pa,1-t},{self.pb,(t)}) +pt-self.pa -end -end return line \ No newline at end of file diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_main.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_main.lua index 92eab43a84..3dffb3de46 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_main.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_main.lua @@ -1,6 +1,6 @@ -- tkz_elements-main.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 @@ -16,8 +16,8 @@ C = {} E = {} L = {} - M = {} P = {} + M = {} Q = {} R = {} RP = {} @@ -47,3 +47,5 @@ require "tkz_elements_functions_lines.lua" require "tkz_elements_functions_circles.lua" require "tkz_elements_functions_triangles.lua" require "tkz_elements_functions_regular.lua" +require "tkz_elements_functions_matrices.lua" +require "tkz_elements_matrices.lua" \ No newline at end of file diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_matrices.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_matrices.lua new file mode 100644 index 0000000000..ed5fa5b1f3 --- /dev/null +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_matrices.lua @@ -0,0 +1,219 @@ +-- tkz_elements_matrices.lua +-- date 2024/03/25 +-- version 2.20c +-- Copyright 2024 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. + +-- ---------------------------------------------------------------------------- +matrix={} +function matrix: new (value) + local type = 'matrix' + local rows = #value + local cols = #value[1] + local set = value + local det = determinant(value) + local o = {set = set, + rows = rows, + cols = cols, + det = det, + type = type } + setmetatable(o, self) + self.__index = self + return o +end + +function matrix.__mul(m1,m2) + if getmetatable(m1) ~= matrix then return k_mul_matrix(m1, m2) end + if getmetatable(m2) ~= matrix then return k_mul_matrix(m2, m1) end + return mul_matrix(m1,m2) +end + +function matrix.__add(m1,m2) + return add_matrix(m1,m2) +end + +function matrix.__sub(m1,m2) + return add_matrix(m1,k_mul_matrix(-1, m2)) +end + +function matrix.__pow( m, num ) + if num =='T' then + return transposeMatrix(m) + else + if num == 0 then + return matrix:new( #m,"I" ) + end + if num < 0 then + local i; m,i = inv_matrix ( m ) + if not m then return m, i end + num = -num + end + local mt = m + for i = 2,num do + mt = mul_matrix(mt,m) + end + return mt +end +end + +function matrix.__tostring( A ) + local mt = (A.type=='matrix' and A.set or A) + local k = {} + for i = 1,#mt do + local n = {} + for j = 1,#mt[1] do + n[j] = display(mt[i][j]) + end + k[i] = table.concat(n, " ") + end + return table.concat(k) +end + +function matrix.__eq( A , B ) + local mt1 = (A.type=='matrix' and A.set or A) + local mt2 = (B.type=='matrix' and B.set or B) + if A.type ~= B.type then + return false + end + + if #mt1 ~= #mt2 or #mt1[1] ~= #mt2[1] then + return false + end + + for i = 1,#mt1 do + for j = 1,#mt1[1] do + if mt1[i][j] ~= mt2[i][j] then + return false + end + end + end + return true +end + +function matrix : square(n,...) + local m = {} + local t = table.pack(...) + if n*n == #t then + for i = 1, n do + m[i] = {} + for j = 1, n do + m[i][j] = t[n*(i-1)+j] + end + end + return matrix : new (m) + else + return nil + end +end + +function matrix: vector (...) + local m = {} + local t = table.pack(...) + for i = 1, #t do + m[i] = {} + m[i][1] = t[i] + end + return matrix : new (m) +end + +function matrix : homogenization () + return homogenization_ (self) +end + +function matrix : htm_apply (...) + local obj,nb,t + local tp = table.pack(...) + obj = tp[1] + nb = tp.n + if nb == 1 then + if obj.type == "point" then + return htm_apply_ ( self,obj ) + elseif obj.type == "line" then + return htm_apply_L_ (self,obj) + elseif obj.type == "triangle" then + return htm_apply_T_ (self,obj) + elseif obj.type == "circle" then + return htm_apply_C (self,obj) + elseif obj.type == "square" + or obj.type == "rectangle" + or obj.type == "quadrilateral" + or obj.type == "parallelogram" then + return htm_apply_Q (self,obj) + end + else + t = {} + for i=1,tp.n do + table.insert(t , htm_apply_ ( self , tp[i])) + end + return table.unpack ( t ) + end +end + +function matrix: k_mul (n) + return k_mul_matrix(n, self) +end + +function matrix : get (i,j) + return get_element_( self,i,j ) +end + +function matrix: inverse () + return inv_matrix (self) +end + +function matrix: adjugate () + return adjugate_ (self) +end + +function matrix: transpose () + return transposeMatrix (self) +end + +function matrix: is_diagonal () + return isDiagonal_ (self) +end + +function matrix: is_orthogonal () + return isOrthogonal_ (self) +end + +function matrix: diagonalize () -- return two matrices D and P + return diagonalize_ (self) +end + +function matrix: print (style,fmt) + local style = (style or 'bmatrix') + local fmt = (fmt or 0) + return print_matrix (self,style,fmt) +end + +function matrix: identity (n) + return id_matrix (n) +end + +------------------------- +-- homogeneous transformation matrix +function matrix : htm (phi,a,b,sx,sy) + local tx = (a or 0) + local ty = (b or 0) + local sx = (sx or 1) + local sy = (sy or 1) + local phi = (phi or 0) + return matrix : square (3,sx*math.cos(phi),-math.sin(phi),tx,math.sin(phi),sy*math.cos(phi),ty,0,0,1) +end +------------------------- + +function matrix: is_orthogonal () + return isOrthogonal_ (self) +end + +return matrix + diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_misc.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_misc.lua index f95877a844..6bf04756a6 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_misc.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_misc.lua @@ -1,6 +1,6 @@ -- tkz_elements_functions_maths.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_parallelogram.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_parallelogram.lua index 5ce1d2a9a4..99c4344543 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_parallelogram.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_parallelogram.lua @@ -1,6 +1,6 @@ -- tkz_elements_parallelogram.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_point.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_point.lua index 8837299966..5e9d4fcd00 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_point.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_point.lua @@ -1,6 +1,6 @@ -- tkz_elements_point.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 @@ -26,6 +26,7 @@ point = class(function(p,re,im) p.type = 'point' p.argument = math.atan(p.im, p.re) p.modulus = math.sqrt(p.re * p.re + p.im * p.im) + p.mtx = matrix : new {{p.re},{p.im}} end) local sqrt = math.sqrt @@ -94,46 +95,62 @@ function point.__div(x,y) end function point.__tostring(z) - if (z.re == 0) then - if (z.im == 0) then + local real = z.re + local imag = z.im + if (real == 0) then + if (imag == 0) then return "0" else - if (z.im ==1) then + if (imag == 1) then return "" .. "i" - else - if (z.im ==-1) then - return "" .. "-i" - else - return "" .. z.im .. "i" + else + if (imag == -1) then + return "" .. "-i" + else + local imag = string.format( "%."..tkz_dc.."f",imag) + return "" .. imag .. "i" end end end else - if (z.im > 0) then - if (z.im ==1) then - return "" .. z.re .. "+" .. "i" - else - return "" .. z.re .. "+" .. z.im .. "i" + if (imag > 0) then + if (imag ==1) then + if is_integer (real) then real = math.round(real) else + real = string.format( "%."..tkz_dc.."f",real) end + return "" .. real .. "+" .. "i" + else + if is_integer (real) then real = math.round(real) else + real = string.format( "%."..tkz_dc.."f",real) end + imag = string.format( "%."..tkz_dc.."f",imag) + return "" .. real .. "+" .. imag .. "i" end - elseif (z.im < 0) then - if (z.im ==-1) then - return "" .. z.re .. "-" .. "i" - else - return "" .. z.re .. z.im .. "i" - end + elseif (imag < 0) then + if (imag == -1) then + if is_integer (real) then real = math.round(real) else + real = string.format( "%."..tkz_dc.."f",real) end + imag = string.format( "%."..tkz_dc.."f",imag) + return "" .. real .. "-" .. "i" + else + if is_integer (real) then real = math.round(real) else + real = string.format( "%."..tkz_dc.."f",real) end + imag = string.format( "%."..tkz_dc.."f",imag) + return "" .. real .. imag .. "i" + end else - return "" .. z.re - + if is_integer (real) then real = math.round(real) else + real = string.format( "%."..tkz_dc.."f",real) end + return "" .. real + end end end function point.__tonumber(z) - if (z.im == 0) then - return z.re - else - return nil - end + if (z.im == 0) then + return z.re + else + return nil + end end function point.__eq(z1,z2) @@ -148,46 +165,61 @@ local function pyth(a, b) end function point.conj(z) - return point(z.re,-z.im) + local cx = topoint(z) + return point(cx.re,-cx.im) end function point.mod(z) - local function sqr(x) return x*x end - return pyth (z.re,z.im) + local cx = topoint(z) + local function sqr(x) return x*x end + return pyth (cx.re,cx.im) end function point.abs (z) + local cx = topoint(z) local function sqr(x) return x*x end - return sqrt(sqr(z.re) + sqr(z.im)) + return sqrt(sqr(cx.re) + sqr(cx.im)) end function point.norm (z) - local function sqr(x) return x*x end - return (sqr(z.re) + sqr(z.im)) + local cx = topoint(z) + local function sqr(x) return x*x end + return (sqr(cx.re) + sqr(cx.im)) +end + +function point.power (z,n) + if type(z) == number then return z^n + else + local m = (z.modulus)^n + local a = angle_normalize((z.argument)*n) + return scale * polar_ (m,a) + end end function point.arg (z) - return math.atan(z.im, z.re) + cx = topoint(z) + return math.atan(cx.im, cx.re) end function point.get(z) return z.re, z.im end -function point: sqrt() - local y = sqrt((point.mod(self)-self.re)/2) - local x = self.im/(2*y) - return point(x,y) +function point.sqrt(z) + local cx = topoint(z) + local len = math.sqrt( (cx.re)^2+(cx.im)^2 ) + local sign = (cx.im < 0 and -1 ) or 1 + return point(math.sqrt((cx.re+len)/2), sign*math.sqrt((len-cx.re)/2) ) end -- methods --- function point: new ( a,b ) - return scale * point (a,b ) + return scale * point (a,b ) end function point: polar ( radius, phi ) - return point: new (radius * math.cos(phi), radius * math.sin(phi)) + return point: new (radius * math.cos(phi), radius * math.sin(phi)) end function point: polar_deg ( radius, phi ) @@ -195,18 +227,18 @@ function point: polar_deg ( radius, phi ) end function point: north(d) - local d = d or 1 + local d = d or 1 return self+ polar_ ( d , math.pi/2 ) end function point: south(d) - local d = d or 1 - return self + polar_ ( d , 3 * math.pi/2 ) - end + local d = d or 1 + return self + polar_ ( d , 3 * math.pi/2 ) +end function point: east(d) - local d = d or 1 - return self+ polar_( d , 0 ) + local d = d or 1 + return self+ polar_( d , 0 ) end function point: west(d) @@ -325,4 +357,8 @@ end function point : at (z) return point(self.re+z.re,self.im+z.im) +end + +function point : print () + tex.print(tostring(self)) end \ No newline at end of file diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_quadrilateral.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_quadrilateral.lua index e1882c67cb..f02c977e08 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_quadrilateral.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_quadrilateral.lua @@ -1,6 +1,6 @@ -- tkz_elements_quadrilateral.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_rectangle.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_rectangle.lua index 7c4f8f75ed..7add1b244d 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_rectangle.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_rectangle.lua @@ -1,6 +1,6 @@ -- tkz_elements-rectangle.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_regular.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_regular.lua index 2e00ab9598..cc7a24ff06 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_regular.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_regular.lua @@ -1,6 +1,6 @@ -- tkz_elements_regular.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_square.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_square.lua index fe7b7a150b..7373886efc 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_square.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_square.lua @@ -1,6 +1,6 @@ -- tkz_elements-square.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_triangle.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_triangle.lua index 0d2699ac55..d3a80bd777 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_triangle.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_triangle.lua @@ -1,6 +1,6 @@ -- tkz_elements_triangles.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 @@ -56,7 +56,6 @@ end ----------------------- -- points -- ----------------------- --- version 1.80 function triangle: trilinear (a,b,c) return barycenter_ ( {self.pa,a*self.a },{self.pb,b*self.b},{self.pc,c*self.c} ) end @@ -146,7 +145,10 @@ end ------------------- -- N,H,G,O -- check_equilateral_ (a,b,c) function triangle: euler_line () - return line : new (self.orthocenter,self.circumcenter) + if not check_equilateral_(self.pa,self.pb,self.pc) + then + return line : new (self.orthocenter,self.circumcenter) + end end function triangle: symmedian_line (n) @@ -359,7 +361,28 @@ end function triangle: euler () return triangle : new (euler_points_ (self.pa,self.pb,self.pc) ) end +------------------- +-- Result -> ellipse +------------------- +function triangle: steiner_inellipse () + return steiner_ (self.pa,self.pb,self.pc) +end + +function triangle: steiner_circumellipse () + local e + e = steiner_ (self.pa,self.pb,self.pc) + return ellipse: radii (e.center,2*e.Rx,2*e.Ry,e.slope ) +end +function triangle: euler_ellipse () + if self : check_acutangle () + then + local a,b + a,b = intersection_lc_ (self.orthocenter,self.circumcenter, + self.eulercenter,self.ab.mid) + return ellipse: foci (self.orthocenter,self.circumcenter,a) + end +end ------------------- -- Result -> miscellaneous ------------------- @@ -406,6 +429,16 @@ function triangle: check_equilateral () return check_equilateral_ (self.pa,self.pb,self.pc) end +function triangle: check_acutangle() + local asq = self.a * self.a + local bsq = self.b * self.b + local csq = self.c * self.c + if asq + bsq > csq and bsq + csq > asq and csq + asq > bsq then + return true + else + return false + end +end return triangle \ No newline at end of file diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_vector.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_vector.lua index 310b522788..f3f93a0f53 100644 --- a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_vector.lua +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_vector.lua @@ -1,6 +1,6 @@ -- tkz_elements_vectors.lua --- date 2024/02/04 --- version 2.00c +-- date 2024/03/25 +-- version 2.20c -- Copyright 2024 Alain Matthes -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 @@ -17,10 +17,12 @@ vector = {} function vector: new(za, zb) local type = 'vector' local slope = angle_normalize_(point.arg(zb-za)) - local norm = point.mod(zb-za) - local o = {t = za, - h = zb, - norm = norm, + local norm = point.mod(zb-za) + local mtx = matrix : new {{za},{zb}} + local o = {tail = za, + head = zb, + norm = norm, + mtx = mtx, slope = slope, type = type } setmetatable(o, self) @@ -46,35 +48,35 @@ function vector.__mul(r,v) end function vector: normalize () - local z = self.h-self.t + local z = self.head-self.tail local d = point.abs(z) local nz = point(z.re/d,z.im/d) - return vector : new (self.t,nz + self.t) + return vector : new (self.tail,nz + self.tail) end function vector: add (ve) - return vector :new (self.t,self.h+ve.h-ve.t) + return vector :new (self.tail,self.head+ve.head-ve.tail) end function vector: orthogonal (d) local z if d == nil then - return vector : new (self.t, rotation_(self.t,math.pi/2,self.h)) + return vector : new (self.tail, rotation_(self.tail,math.pi/2,self.head)) else - z = self.t+ point (d*math.cos(self.slope),d*math.sin(self.slope)) - return vector : new (self.t, rotation_(self.t,math.pi/2,z)) + z = self.tail+ point (d*math.cos(self.slope),d*math.sin(self.slope)) + return vector : new (self.tail, rotation_(self.tail,math.pi/2,z)) end end function vector: scale (d) local l,z l = self.norm - z = self.t+ point (d*l*math.cos(self.slope),d*l*math.sin(self.slope)) - return vector : new (self.t,z ) + z = self.tail+ point (d*l*math.cos(self.slope),d*l*math.sin(self.slope)) + return vector : new (self.tail,z ) end function vector: at (zc) - return vector :new (zc,zc+self.h-self.t) + return vector :new (zc,zc+self.head-self.tail) end return vector -- cgit v1.2.3