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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
-- tkz_elements-circles.lua
-- date 23/12/24
-- version 1.72c
-- 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.
---------------------------------------------------------------------------
-- circles
---------------------------------------------------------------------------
circle = {}
function circle: new (c, t) -- c --> center t --> through
local type = 'circle'
local ra = line :new (c,t)
local anti = antipode_ (c,t)
local di = line : new (anti, t)
local radius = point.abs ( c - t )
local south = c - point (0,radius)
local east = c + point (radius,0)
local north = c + point (0,radius)
local west = c - point (radius,0)
local o = { center = c,
through = t,
ra = ra,
di = di,
radius = radius,
south = south,
east = east,
north = north,
west = west,
type = type}
setmetatable(o, self)
self.__index = self
return o
end
-- other definition
function circle: radius (center, radius) -- c --> center r --> radius
return circle : new (center, center + point( radius, 0 ) )
end
function circle: diameter (za, zb)
local c = midpoint_(za,zb)
return circle : new (c, zb )
end
-----------------------
-- boolean --
-----------------------
function circle: in_out (pt)
local d,epsilon
epsilon = 10^(-12)
d = point.abs (pt - self.center)
if math.abs(d-self.radius) < epsilon
then
return true
else
return false
end
end
function circle: in_out_disk (pt)
local d
d = point.abs (pt - self.center)
if d <= self.radius
then
return true
else
return false
end
end
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
-----------------------
-- real --
-----------------------
function circle: power (pt)
local d
d = point.abs (self.center - pt)
return d * d - self.radius * self.radius
end
-----------------------
-- points --
-----------------------
function circle: antipode (pt)
return 2 * self.center - pt
end
function circle: set_inversion (...)
local tp = table.pack(...)
local i
local t = {}
for i=1,tp.n do
table.insert( t , inversion_ ( self.center,self.through, tp[i] ) )
end
return table.unpack ( t )
end
function circle: midarc (z1,z2)
local phi = 0.5 * get_angle (self.center,z1,z2 )
return rotation_ (self.center,phi,z1)
end
function circle: point (t)
local phi = 2*t* math.pi
return rotation_ (self.center,phi,self.through)
end
function circle: random_pt(lower, upper)
local t
math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)) )
phi = lower + math.random() * (upper - lower)
return point (self.center.re+self.radius*math.cos(phi),self.center.im+self.radius*math.sin(phi) )
end
function circle: internal_similitude (C)
return internal_similitude_ (self.center,self.radius,C.center,C.radius)
end
function circle: external_similitude (C)
return external_similitude_ (self.center,self.radius,C.center,C.radius)
end
-----------------------
-- lines --
-----------------------
function circle: tangent_at (pt)
return line : new ( rotation_ (pt,math.pi/2,self.center),rotation_ (pt,-math.pi/2,self.center))
end
function circle: tangent_from (pt)
local t1,t2
t1,t2 = tangent_from_ (self.center,self.through,pt)
return line :new (pt,t1),line : new (pt,t2)
end
function circle: radical_axis (C)
local t1,t2
t1,t2 = radical_axis_ (self.center,self.through,C.center,C.through)
return line : new (t1,t2)
end
-- version 1.60 new
function circle : external_tangent(C)
local i,t1,t2,k,T1,T2
i = barycenter_ ({C.center,self.radius},{self.center,-C.radius})
t1,t2 = tangent_from_ (self.center,self.through,i)
k = point.mod((C.center-i)/(self.center-i))
T1 = homothety_(i,k,t1)
T2 = homothety_(i,k,t2)
return line : new (t1,T1),line : new (t2,T2)
end
-- version 1.60 new
function circle : internal_tangent(C)
local i,t1,t2,k,T1,T2
i = barycenter_ ({C.center,self.radius},{self.center,C.radius})
t1,t2 = tangent_from_ (self.center,self.through,i)
k = -point.mod((C.center-i)/(self.center-i))
T1 = homothety_(i,k,t1)
T2 = homothety_(i,k,t2)
return line : new (t1,T1),line : new (t2,T2)
end
-----------------------
-- circles --
-----------------------
function circle: orthogonal_from (pt)
local t1,t2
t1,t2 = tangent_from_ (self.center,self.through,pt)
return circle : new (pt,t1)
end
function circle: orthogonal_through (pta,ptb)
return circle : new (orthogonal_through_ (self.center,self.through,pta,ptb),pta)
end
function circle: inversion_L (L)
local p,q
if L: in_out (self.center) then
return L
else
p = L: projection (self.center)
q = inversion_ (self.center,self.through,p)
return circle: new (midpoint_(self.center,q),q)
end
end
function circle: inversion_C (C)
local p,q,x,y
if C: in_out (self.center) then
p = C : antipode (self.center)
q = inversion_ (self.center,self.through,p)
x = ortho_from_ ( q , self.center , p )
y = ortho_from_ ( q , p, self.center)
return line : new (x,y)
else
x,y = intersection_lc_ (self.center,C.center,C.center,C.through)
X = inversion_ (self.center,self.through,x)
Y = inversion_ (self.center,self.through,y)
return circle : new (midpoint_(X,Y),X)
end
end
function circle: inversion (...)
local obj,nb,t
local tp = table.pack(...)
obj = tp[1]
nb = tp.n
if nb == 1 then
if obj.type == "point" then
return inversion_ (self.center,self.through,obj)
elseif obj.type == "line" then
return self: inversion_L (obj)
else
return self: inversion_C (obj)
end
else
t = {}
for i=1,tp.n do
table.insert( t , inversion_ (self.center,self.through , tp[i]) )
end
return table.unpack ( t )
end
end
function circle: draw ()
local x,y
x, y = self.center: get ()
local r = self.radius
local frmt = '\\draw (%0.3f,%0.3f) circle [radius=%0.3f];'
tex.sprint(string.format(frmt, x,y,r))
end
function circle: midcircle(C)
return midcircle_ (self,C)
end
return circle
|