Debian Codegraph @

texmf-dist/tex/latex/tkz-elements/tkz_elements_regular_polygon.lua

raw
1 -- File: tkz_elements_regular_polygon.lua
2 -- Copyright (c) 2026 Alain Matthes
3 -- SPDX-License-Identifier: LPPL-1.3c
4 -- Maintainer: Alain Matthes
5
6
7 regular_polygon = {}
8 regular_polygon.__index = regular_polygon
9 function regular_polygon:new(za, zb, nb)
10 if nb < 3 then
11 tex.error("Regular polygon: nb must be >= 3")
12 return
13 end -- za = center zb a vertex
14 local type = "regular_polygon"
15 local vertices = regular_(za, zb, nb)
16 local center = za
17 local through = zb
18 local angle = tkz.tau / nb
19 local circumradius = point.abs(zb - za)
20 local circle = circle:new(za, zb)
21 local inradius = circumradius * math.cos(math.pi / nb)
22 local side = 2 * circumradius * math.sin(math.pi / nb)
23 local apothem_foot = projection_(vertices[1], vertices[2], za)
24 local perimeter = nb * side
25 local area = (perimeter * inradius) / 2
26 local regular = {
27 type = type,
28 center = center,
29 through = through,
30 circumradius = circumradius,
31 inradius = inradius,
32 apothem = inradius,
33 vertices = vertices,
34 circle = circle,
35 nb = nb,
36 angle = angle,
37 side = side,
38 apothem_foot = apothem_foot,
39 perimeter = perimeter,
40 area = area,
41 }
42 setmetatable(regular, self)
43 return regular
44 end
45
46 setmetatable(regular_polygon, {
47 __call = function(cls, ...)
48 return cls:new(...)
49 end,
50 })
51 function regular_polygon:get(i)
52 if i == nil then
53 return self.vertices -- retourne toute la matrice
54 else
55 if i <= self.nb then
56 return self.vertices[i]
57 else
58 tex.error("Bad argument")
59 end
60 end
61 end
62
63 function regular_polygon:incircle()
64 return circle:new(self.center, projection_(self.vertices[1], self.vertices[2], self.center))
65 end
66
67 function regular_polygon:name(nm)
68 for k, v in ipairs(self.vertices) do
69 z[nm .. k] = v
70 end
71 end
72
73 return regular_polygon