| 1 |
-- File: tkz_elements_triangle.lua |
| 2 |
-- Copyright (c) 2026 Alain Matthes |
| 3 |
-- SPDX-License-Identifier: LPPL-1.3c |
| 4 |
-- Maintainer: Alain Matthes |
| 5 |
|
| 6 |
triangle = {} |
| 7 |
triangle.__index = triangle |
| 8 |
|
| 9 |
|
| 10 |
function triangle:new(za, zb, zc) |
| 11 |
local eps = tkz.epsilon |
| 12 |
-- ===== Guardrails against degeneration ===== |
| 13 |
-- sall vertices combined |
| 14 |
if point.abs(za - zb) <= eps or point.abs(zb - zc) <= eps or point.abs(zc - za) <= eps then |
| 15 |
tex.error("Degenerate triangle: two vertices coincide.") |
| 16 |
return |
| 17 |
end |
| 18 |
-- aligned vertices |
| 19 |
if tkz.is_linear(za, zb, zc) then |
| 20 |
tex.error("Degenerate triangle: vertices aligned.") |
| 21 |
return |
| 22 |
end |
| 23 |
|
| 24 |
-- ===== Side lengths ===== |
| 25 |
local c = point.abs(zb - za) |
| 26 |
local a = point.abs(zc - zb) |
| 27 |
local b = point.abs(za - zc) |
| 28 |
|
| 29 |
-- ===== Line objects ===== |
| 30 |
local ab = line:new(za, zb) |
| 31 |
local bc = line:new(zb, zc) |
| 32 |
local ca = line:new(zc, za) |
| 33 |
|
| 34 |
-- ===== Angles ===== |
| 35 |
local alpha = math.abs(get_angle_(za, zb, zc)) |
| 36 |
local beta = math.abs(get_angle_(zb, zc, za)) |
| 37 |
local gamma = math.abs(get_angle_(zc, za, zb)) |
| 38 |
|
| 39 |
local alpha_ = angle:new(za, zb, zc) |
| 40 |
local beta_ = angle:new(zb, zc, za) |
| 41 |
local gamma_ = angle:new(zc, za, zb) |
| 42 |
|
| 43 |
local type = "triangle" |
| 44 |
local circumcenter = circum_center_(za, zb, zc) |
| 45 |
local centroid = barycenter_({ za, 1 }, { zb, 1 }, { zc, 1 }) |
| 46 |
local incenter = in_center_(za, zb, zc) |
| 47 |
local orthocenter = ortho_center_(za, zb, zc) |
| 48 |
local eulercenter = euler_center_(za, zb, zc) |
| 49 |
local spiekercenter = spieker_center_(za, zb, zc) |
| 50 |
local orientation = find_orientation_(za, zb, zc) |
| 51 |
|
| 52 |
local semiperimeter = (a + b + c) / 2 |
| 53 |
local cross = (zb - za) ^ (zc - za) |
| 54 |
local area = 0.5 * math.abs((zb - za) ^ (zc - za)) |
| 55 |
local inradius = area / semiperimeter |
| 56 |
local circumradius = (a * b * c) / (4 * area) |
| 57 |
local ma = midpoint_(zb, zc) |
| 58 |
local mb = midpoint_(zc, za) |
| 59 |
local mc = midpoint_(za, zb) |
| 60 |
local ha = projection_(zb, zc, za) |
| 61 |
local hb = projection_(zc, za, zb) |
| 62 |
local hc = projection_(za, zb, zc) |
| 63 |
local ia = find_foot_bisector_(za, zb, zc) |
| 64 |
local ib = find_foot_bisector_(zb, zc, za) |
| 65 |
local ic = find_foot_bisector_(zc, za, zb) |
| 66 |
local tr = { |
| 67 |
pa = za, |
| 68 |
pb = zb, |
| 69 |
pc = zc, |
| 70 |
type = type, |
| 71 |
circumcenter = circumcenter, |
| 72 |
centroid = centroid, |
| 73 |
incenter = incenter, |
| 74 |
eulercenter = eulercenter, |
| 75 |
orthocenter = orthocenter, |
| 76 |
spiekercenter = spiekercenter, |
| 77 |
a = a, |
| 78 |
b = b, |
| 79 |
c = c, |
| 80 |
ab = ab, |
| 81 |
ca = ca, |
| 82 |
bc = bc, |
| 83 |
ma = ma, |
| 84 |
mb = mb, |
| 85 |
mc = mc, |
| 86 |
ha = ha, |
| 87 |
hb = hb, |
| 88 |
hc = hc, |
| 89 |
ia = ia, |
| 90 |
ib = ib, |
| 91 |
ic = ic, |
| 92 |
alpha = alpha, |
| 93 |
beta = beta, |
| 94 |
gamma = gamma, |
| 95 |
alpha_ = alpha_, |
| 96 |
beta_ = beta_, |
| 97 |
gamma_ = gamma_, |
| 98 |
cross = cross, |
| 99 |
semiperimeter = semiperimeter, |
| 100 |
area = area, |
| 101 |
inradius = inradius, |
| 102 |
circumradius = circumradius, |
| 103 |
orientation = orientation, |
| 104 |
} |
| 105 |
setmetatable(tr, self) |
| 106 |
return tr |
| 107 |
end |
| 108 |
|
| 109 |
setmetatable(triangle, { |
| 110 |
__call = function(cls, ...) |
| 111 |
return cls:new(...) |
| 112 |
end, |
| 113 |
}) |
| 114 |
|
| 115 |
function triangle:get(i) |
| 116 |
if i == nil then |
| 117 |
return self.pa, self.pb, self.pc |
| 118 |
elseif i == 1 then |
| 119 |
return self.pa |
| 120 |
elseif i == 2 then |
| 121 |
return self.pb |
| 122 |
elseif i == 3 then |
| 123 |
return self.pc |
| 124 |
else |
| 125 |
return nil |
| 126 |
end |
| 127 |
end |
| 128 |
|
| 129 |
----------------------- |
| 130 |
-- Result -> boolean |
| 131 |
----------------------- |
| 132 |
-- added strict |
| 133 |
function triangle:position(p, EPS) |
| 134 |
EPS = EPS or tkz.epsilon |
| 135 |
local x, y, z = barycentric_coordinates_(self.pa, self.pb, self.pc, p) |
| 136 |
|
| 137 |
local in_ = (x > EPS and y > EPS and z > EPS) |
| 138 |
local out_ = (x < -EPS or y < -EPS or z < -EPS) |
| 139 |
|
| 140 |
if in_ then |
| 141 |
return "IN" |
| 142 |
elseif out_ then |
| 143 |
return "OUT" |
| 144 |
else |
| 145 |
return "ON" -- zone de bord (tolérance) |
| 146 |
end |
| 147 |
end |
| 148 |
|
| 149 |
|
| 150 |
function triangle:in_out(pt, strict) |
| 151 |
-- ne change pas → tous les anciens documents restent valides |
| 152 |
return in_out_(self.pa, self.pb, self.pc, pt, strict) |
| 153 |
end |
| 154 |
|
| 155 |
function triangle:on_triangle(pt, EPS) |
| 156 |
EPS = EPS or tkz.epsilon |
| 157 |
local a, b, c = self.pa, self.pb, self.pc |
| 158 |
local x, y, z = barycentric_coordinates_(a, b, c, pt) |
| 159 |
-- boundary cases |
| 160 |
local onx = math.abs(x) <= EPS |
| 161 |
local ony = math.abs(y) <= EPS |
| 162 |
local onz = math.abs(z) <= EPS |
| 163 |
|
| 164 |
if onx or ony or onz then |
| 165 |
return true |
| 166 |
end |
| 167 |
|
| 168 |
return false |
| 169 |
end |
| 170 |
|
| 171 |
function triangle:check_equilateral(EPS) |
| 172 |
return check_equilateral_(self.pa, self.pb, self.pc, EPS) |
| 173 |
end |
| 174 |
triangle.is_equilateral = triangle.check_equilateral |
| 175 |
|
| 176 |
function triangle:check_acutangle(EPS) |
| 177 |
return check_acutangle_(self.pa, self.pb, self.pc, EPS) |
| 178 |
end |
| 179 |
triangle.is_acute = triangle.check_acutangle |
| 180 |
|
| 181 |
function triangle:check_isosceles(EPS) |
| 182 |
return check_isosceles_(self.pa, self.pb, self.pc, EPS) |
| 183 |
end |
| 184 |
|
| 185 |
triangle.is_isosceles = triangle.check_isosceles |
| 186 |
|
| 187 |
----------------------- |
| 188 |
-- Result -> real |
| 189 |
----------------------- |
| 190 |
|
| 191 |
function triangle:area() -- obsolete |
| 192 |
return area_(self.pa, self.pb, self.pc) |
| 193 |
end |
| 194 |
|
| 195 |
|
| 196 |
function triangle:barycentric_coordinates(pt) |
| 197 |
local xA, yA = self.pa:get() |
| 198 |
local xB, yB = self.pb:get() |
| 199 |
local xC, yC = self.pc:get() |
| 200 |
local xP, yP = pt:get() |
| 201 |
local orient2d_ABC = oriented_area2_(xA, yA, xB, yB, xC, yC) |
| 202 |
local l_A = oriented_area2_(xP, yP, xB, yB, xC, yC) / orient2d_ABC |
| 203 |
local l_B = oriented_area2_(xA, yA, xP, yP, xC, yC) / orient2d_ABC |
| 204 |
local l_C = oriented_area2_(xA, yA, xB, yB, xP, yP) / orient2d_ABC |
| 205 |
return l_A, l_B, l_C |
| 206 |
end |
| 207 |
|
| 208 |
function triangle:trilinear_coordinates(pt) |
| 209 |
local la, lb, lc = self:barycentric_coordinates(pt) |
| 210 |
local ta, tb, tc = la / self.a, lb / self.b, lc / self.c |
| 211 |
-- normalize |
| 212 |
local N = ta + tb + tc |
| 213 |
return ta / N, tb / N, tc / N |
| 214 |
end |
| 215 |
|
| 216 |
function triangle:trilinear_to_d(x, y, z) |
| 217 |
return trilinear_to_d_(x, y, z, self.a, self.b, self.c) |
| 218 |
end |
| 219 |
|
| 220 |
function triangle:get_angle(arg) |
| 221 |
local i = resolve_triangle_index(self, arg) -- 0,1,2 |
| 222 |
if i < 0 or i > 2 then |
| 223 |
tex.error("triangle:get_angle -> invalid argument (use 0/1/2, 'a'/'b'/'c', or a vertex point)") |
| 224 |
return nil |
| 225 |
end |
| 226 |
|
| 227 |
if i == 0 then return self.alpha end -- angle en B dans ton alpha = angle(za,zb,zc) |
| 228 |
if i == 1 then return self.beta end |
| 229 |
return self.gamma |
| 230 |
end |
| 231 |
|
| 232 |
|
| 233 |
function triangle:parameter(p) |
| 234 |
local a, b, c = self.a, self.b, self.c -- a=BC, b=CA, c=AB |
| 235 |
local A, B, C = self.pa, self.pb, self.pc |
| 236 |
local AB, BC, CA = self.ab, self.bc, self.ca |
| 237 |
local ptotal = a + b + c |
| 238 |
|
| 239 |
if AB:on_segment(p) then |
| 240 |
return length_(A, p) / ptotal |
| 241 |
elseif BC:on_segment(p) then |
| 242 |
return (c + length_(B, p)) / ptotal |
| 243 |
elseif CA:on_segment(p) then |
| 244 |
return (c + a + length_(C, p)) / ptotal |
| 245 |
else |
| 246 |
tex.error("The point is not on the boundary of the triangle.") |
| 247 |
end |
| 248 |
end |
| 249 |
|
| 250 |
----------------------- |
| 251 |
-- Result -> point |
| 252 |
----------------------- |
| 253 |
function triangle:barycenter(ka, kb, kc) |
| 254 |
return barycenter_({ self.pa, ka }, { self.pb, kb }, { self.pc, kc }) |
| 255 |
end |
| 256 |
triangle.barycentric = triangle.barycenter |
| 257 |
|
| 258 |
function triangle:base(u, v) -- (ab,ac) base coord u,v |
| 259 |
return barycenter_({ self.pa, (1 - u - v) }, { self.pb, u }, { self.pc, v }) |
| 260 |
end |
| 261 |
|
| 262 |
function triangle:point(t) |
| 263 |
local p = self.a + self.b + self.c -- périmètre |
| 264 |
local t1 = self.c / p -- fin de AB |
| 265 |
local t2 = (self.c + self.a) / p -- fin de AB + BC |
| 266 |
|
| 267 |
if t <= t1 then |
| 268 |
return self.ab:point(t / t1) |
| 269 |
elseif t <= t2 then |
| 270 |
return self.bc:point((t - t1) / (t2 - t1)) |
| 271 |
else |
| 272 |
return self.ca:point((t - t2) / (1 - t2)) |
| 273 |
end |
| 274 |
end |
| 275 |
|
| 276 |
function triangle:random(inside) |
| 277 |
inside = (inside == "inside") |
| 278 |
if inside then |
| 279 |
local x = self.bc:random() |
| 280 |
local L = line:new(self.pa, x) |
| 281 |
return L:random() |
| 282 |
else |
| 283 |
return self:point(math.random()) |
| 284 |
end |
| 285 |
end |
| 286 |
|
| 287 |
function triangle:trilinear(a, b, c) |
| 288 |
return barycenter_({ self.pa, a * self.a }, { self.pb, b * self.b }, { self.pc, c * self.c }) |
| 289 |
end |
| 290 |
|
| 291 |
function triangle:kimberling(n) |
| 292 |
local cos, sin, tan, pi = math.cos, math.sin, math.tan, math.pi |
| 293 |
local A, B, C = self.alpha, self.beta, self.gamma |
| 294 |
local a, b, c = self.a, self.b, self.c |
| 295 |
local pi = math.pi |
| 296 |
if n == 1 then |
| 297 |
return self:trilinear(1, 1, 1) -- incenter |
| 298 |
elseif n == 2 then |
| 299 |
return self:barycentric(1, 1, 1) -- centroid |
| 300 |
elseif n == 3 then |
| 301 |
return self:trilinear(cos(A), cos(B), cos(C)) --circumcenter |
| 302 |
elseif n == 4 then |
| 303 |
return self:barycentric(tan(A), tan(B), tan(C)) -- orthocenter |
| 304 |
elseif n == 5 then |
| 305 |
return self:trilinear(cos(B - C), cos(C - A), cos(A - B)) --nine |
| 306 |
elseif n == 6 then |
| 307 |
return self:trilinear(a, b, c) -- lemoine |
| 308 |
elseif n == 7 then |
| 309 |
return self:barycentric(1 / (b + c - a), 1 / (a + c - b), 1 / (a + b - c)) -- gergonne |
| 310 |
elseif n == 8 then |
| 311 |
return self:barycentric(b + c - a, a + c - b, a + b - c) -- nagel |
| 312 |
elseif n == 9 then |
| 313 |
return self:barycentric(a * (b + c - a), b * (a + c - b), c * (a + b - c)) -- mittenpunkt |
| 314 |
elseif n == 10 then |
| 315 |
return self:barycentric(b + c, a + c, a + b) -- spieker |
| 316 |
elseif n == 11 then |
| 317 |
return self:trilinear(1 - cos(B - C), 1 - cos(C - A), 1 - cos(A - B)) -- feuerbach |
| 318 |
elseif n == 13 then |
| 319 |
return self:trilinear(1 / sin(A + pi / 3), 1 / sin(B + pi / 3), 1 / sin(C + pi / 3)) -- first fermat |
| 320 |
elseif n == 14 then |
| 321 |
return self:trilinear(1 / sin(A - pi / 3), 1 / sin(B - pi / 3), 1 / sin(C - pi / 3)) -- second fermat |
| 322 |
elseif n == 19 then |
| 323 |
return self:trilinear(tan(A), tan(B), tan(C)) -- clawson |
| 324 |
elseif n == 20 then |
| 325 |
return self:barycentric(tan(B) + tan(C) - tan(A), tan(A) + tan(C) - tan(B), tan(A) + tan(B) - tan(C)) --de Longchamps |
| 326 |
elseif n == 39 then |
| 327 |
return self:trilinear(a * (b ^ 2 + c ^ 2), b * (c ^ 2 + a ^ 2), c * (a ^ 2 + b ^ 2)) --brocard midpoint |
| 328 |
elseif n == 55 then |
| 329 |
return self:trilinear(a * (b + c - a), b * (c + a - b), c * (a + b - c)) |
| 330 |
elseif n == 56 then |
| 331 |
return self:trilinear(a / (b + c - a), b / (c + a - b), c / (a + b - c)) |
| 332 |
elseif n == 110 then |
| 333 |
return self:trilinear(a / (b ^ 2 - c ^ 2), b / (c ^ 2 - a ^ 2), c / (a ^ 2 - b ^ 2)) -- kiepert parabola |
| 334 |
elseif n == 115 then |
| 335 |
return self:barycentric((b ^ 2 - c ^ 2) ^ 2, (c ^ 2 - a ^ 2) ^ 2, (a ^ 2 - b ^ 2) ^ 2) -- kiepert hyperbola |
| 336 |
elseif n == 175 then |
| 337 |
local ra, rb, rc = radius_excircle_(self.pa, self.pb, self.pc) |
| 338 |
return self:barycentric(a - ra, b - rb, c - rc) |
| 339 |
elseif n == 176 then |
| 340 |
ra, rb, rc = radius_excircle_(self.pa, self.pb, self.pc) |
| 341 |
return self:barycentric(a + ra, b + rb, c + rc) |
| 342 |
elseif n == 181 then |
| 343 |
return self:trilinear((a * (b + c) ^ 2) / (b + c - a), (b * (c + a) ^ 2) / (c + a - b), (c * (a + b) ^ 2) / (a + b - c))--apollonius point |
| 344 |
elseif n == 213 then |
| 345 |
return self:trilinear((b + c) * a ^ 2, (c + a) * b ^ 2, (a + b) * c ^ 2) |
| 346 |
elseif n == 264 then |
| 347 |
return self:barycentric(1 / sin(2 * A), 1 / sin(2 * B), 1 / sin(2 * C)) |
| 348 |
elseif n == 371 then |
| 349 |
return self:trilinear(cos(A - pi / 4), cos(B - pi / 4), cos(C - pi / 4)) |
| 350 |
elseif n == 598 then |
| 351 |
return self:trilinear( |
| 352 |
b * c / (a ^ 2 - 2 * b ^ 2 - 2 * c ^ 2), |
| 353 |
c * a / (b ^ 2 - 2 * c ^ 2 - 2 * a ^ 2), |
| 354 |
a * b / (c ^ 2 - 2 * a ^ 2 - 2 * b ^ 2) |
| 355 |
) -- to get lemoine triangle |
| 356 |
else |
| 357 |
tex.error({ " Your number is not yet in the list" }) |
| 358 |
end |
| 359 |
end |
| 360 |
|
| 361 |
function triangle:isogonal(pt) |
| 362 |
local pa = self.bc:reflection(pt) |
| 363 |
local pb = self.ca:reflection(pt) |
| 364 |
local pc = self.ab:reflection(pt) |
| 365 |
return circum_center_(pa, pb, pc) |
| 366 |
end |
| 367 |
|
| 368 |
function triangle:excenter(pt) |
| 369 |
if pt == self.pa then |
| 370 |
return self:trilinear(-1, 1, 1) |
| 371 |
elseif pt == self.pb then |
| 372 |
return self:trilinear(1, -1, 1) |
| 373 |
elseif pt == self.pc then |
| 374 |
return self:trilinear(1, 1, -1) |
| 375 |
else |
| 376 |
tex.error("The argument must be a vertex of the triangle") |
| 377 |
end |
| 378 |
end |
| 379 |
|
| 380 |
function triangle:projections(p) |
| 381 |
local p1 = projection_(self.pb, self.pc, p) |
| 382 |
local p2 = projection_(self.pa, self.pc, p) |
| 383 |
local p3 = projection_(self.pa, self.pb, p) |
| 384 |
return p1, p2, p3 |
| 385 |
end |
| 386 |
|
| 387 |
|
| 388 |
function triangle:reflections(p) |
| 389 |
local p1 = symmetry_axial_(self.pa, self.pb, p) |
| 390 |
local p2 = symmetry_axial_(self.pb, self.pc, p) |
| 391 |
local p3 = symmetry_axial_(self.pc, self.pa, p) |
| 392 |
return p2, p3, p1 |
| 393 |
end |
| 394 |
|
| 395 |
function triangle:parallelogram() |
| 396 |
local x = self.pc + self.pa - self.pb |
| 397 |
return x |
| 398 |
end |
| 399 |
|
| 400 |
function triangle:bevan_point() |
| 401 |
return circum_center_(excentral_tr_(self.pa, self.pb, self.pc)) |
| 402 |
end |
| 403 |
|
| 404 |
function triangle:mittenpunkt_point() |
| 405 |
return lemoine_point_(excentral_tr_(self.pa, self.pb, self.pc)) |
| 406 |
end |
| 407 |
|
| 408 |
function triangle:gergonne_point() |
| 409 |
return gergonne_point_(self.pa, self.pb, self.pc) |
| 410 |
end |
| 411 |
|
| 412 |
function triangle:nagel_point() |
| 413 |
return nagel_point_(self.pa, self.pb, self.pc) |
| 414 |
end |
| 415 |
|
| 416 |
function triangle:feuerbach_point() |
| 417 |
return feuerbach_point_(self.pa, self.pb, self.pc) |
| 418 |
end |
| 419 |
|
| 420 |
function triangle:symmedian_point() |
| 421 |
return lemoine_point_(self.pa, self.pb, self.pc) |
| 422 |
end |
| 423 |
|
| 424 |
triangle.lemoine_point = triangle.symmedian_point |
| 425 |
triangle.grebe_point = triangle.symmedian_point |
| 426 |
|
| 427 |
function triangle:spieker_center() |
| 428 |
return spieker_center_(self.pa, self.pb, self.pc) |
| 429 |
end |
| 430 |
|
| 431 |
function triangle:euler_points() |
| 432 |
local H = self.orthocenter |
| 433 |
return midpoint_(H, self.pa), midpoint_(H, self.pb), midpoint_(H, self.pc) |
| 434 |
end |
| 435 |
|
| 436 |
function triangle:orthic_points() |
| 437 |
return orthic_tr_(self.pa, self.pb, self.pc) |
| 438 |
end |
| 439 |
|
| 440 |
function triangle:medial_points() |
| 441 |
return medial_tr_(self.pa, self.pb, self.pc) |
| 442 |
end |
| 443 |
|
| 444 |
function triangle:tangential_points() |
| 445 |
return tangential_tr_(self.pa, self.pb, self.pc) |
| 446 |
end |
| 447 |
|
| 448 |
function triangle:nine_points() |
| 449 |
local ma, mb, mc, ha, hb, hc |
| 450 |
-- Calculate the medial triangle |
| 451 |
ma, mb, mc = medial_tr_(self.pa, self.pb, self.pc) |
| 452 |
-- Calculate the orthic triangle |
| 453 |
ha, hb, hc = orthic_tr_(self.pa, self.pb, self.pc) |
| 454 |
-- Calculate the orthocenter |
| 455 |
local H = self.orthocenter |
| 456 |
-- Return the points of the nine-point circle |
| 457 |
return ma, mb, mc, ha, hb, hc, midpoint_(H, self.pa), midpoint_(H, self.pb), midpoint_(H, self.pc) |
| 458 |
end |
| 459 |
|
| 460 |
function triangle:first_lemoine_points() |
| 461 |
local lc = self:lemoine_point() |
| 462 |
local p1 = intersection_ll_(lc, ll_from_(lc, self.pa, self.pb), self.pa, self.pc) |
| 463 |
local p2 = intersection_ll_(lc, ll_from_(lc, self.pb, self.pc), self.pb, self.pa) |
| 464 |
local p3 = intersection_ll_(lc, ll_from_(lc, self.pc, self.pa), self.pc, self.pb) |
| 465 |
local p5 = intersection_ll_(lc, ll_from_(lc, self.pa, self.pb), self.pb, self.pc) |
| 466 |
local p6 = intersection_ll_(lc, ll_from_(lc, self.pb, self.pc), self.pa, self.pc) |
| 467 |
local p4 = intersection_ll_(lc, ll_from_(lc, self.pc, self.pa), self.pa, self.pb) |
| 468 |
return p1, p2, p3, p4, p5, p6 |
| 469 |
end |
| 470 |
|
| 471 |
function triangle:second_lemoine_points() |
| 472 |
local lc = self:lemoine_point() |
| 473 |
local ha, hb, hc = orthic_tr_(self.pa, self.pb, self.pc) |
| 474 |
local p1 = intersection_ll_(lc, ll_from_(lc, ha, hb), self.pa, self.pc) |
| 475 |
local p2 = intersection_ll_(lc, ll_from_(lc, hb, hc), self.pb, self.pa) |
| 476 |
local p3 = intersection_ll_(lc, ll_from_(lc, hc, ha), self.pc, self.pb) |
| 477 |
local p5 = intersection_ll_(lc, ll_from_(lc, ha, hb), self.pb, self.pc) |
| 478 |
local p6 = intersection_ll_(lc, ll_from_(lc, hb, hc), self.pa, self.pc) |
| 479 |
local p4 = intersection_ll_(lc, ll_from_(lc, hc, ha), self.pa, self.pb) |
| 480 |
return p1, p2, p3, p4, p5, p6 |
| 481 |
end |
| 482 |
|
| 483 |
function triangle:soddy_points() |
| 484 |
return soddy_center_(self.pa, self.pb, self.pc) |
| 485 |
end |
| 486 |
|
| 487 |
-- soddy centers |
| 488 |
function triangle:soddy_center(outer) |
| 489 |
outer = (outer == "outer") |
| 490 |
local index = outer and 175 or 176 |
| 491 |
return self:kimberling(index) |
| 492 |
end |
| 493 |
|
| 494 |
function triangle:conway_points() |
| 495 |
local a1 = report_(self.pb, self.pa, length_(self.pb, self.pc), self.pa) |
| 496 |
local a2 = report_(self.pc, self.pa, length_(self.pb, self.pc), self.pa) |
| 497 |
local b1 = report_(self.pa, self.pb, length_(self.pa, self.pc), self.pb) |
| 498 |
local b2 = report_(self.pc, self.pb, length_(self.pa, self.pc), self.pb) |
| 499 |
local c1 = report_(self.pb, self.pc, length_(self.pb, self.pa), self.pc) |
| 500 |
local c2 = report_(self.pa, self.pc, length_(self.pb, self.pa), self.pc) |
| 501 |
return a1, a2, b1, b2, c1, c2 |
| 502 |
end |
| 503 |
|
| 504 |
function triangle:conway_center() |
| 505 |
return self.incenter |
| 506 |
end |
| 507 |
|
| 508 |
function triangle:first_fermat_point() |
| 509 |
local x = equilateral_tr_(self.pb, self.pa) |
| 510 |
local y = equilateral_tr_(self.pa, self.pc) |
| 511 |
return intersection_ll_(x, self.pc, y, self.pb) |
| 512 |
end |
| 513 |
|
| 514 |
function triangle:second_fermat_point() |
| 515 |
local x = equilateral_tr_(self.pa, self.pb) |
| 516 |
local y = equilateral_tr_(self.pc, self.pa) |
| 517 |
return intersection_ll_(x, self.pc, y, self.pb) |
| 518 |
end |
| 519 |
|
| 520 |
function triangle:orthic_axis_points() |
| 521 |
return orthic_axis_(self.pa, self.pb, self.pc) |
| 522 |
end |
| 523 |
|
| 524 |
function triangle:kenmotu_point() |
| 525 |
return self:kimberling(371) |
| 526 |
end |
| 527 |
|
| 528 |
function triangle:kenmotu_points() |
| 529 |
local ck = self:kenmotu_circle() |
| 530 |
local p1, p2 = intersection_lc_(self.pa, self.pb, ck.center, ck.through) |
| 531 |
local p3, p4 = intersection_lc_(self.pb, self.pc, ck.center, ck.through) |
| 532 |
local p5, p6 = intersection_lc_(self.pc, self.pa, ck.center, ck.through) |
| 533 |
return p1, p2, p3, p4, p5, p6 |
| 534 |
end |
| 535 |
|
| 536 |
function triangle:taylor_points() |
| 537 |
local a, b, c = orthic_tr_(self.pa, self.pb, self.pc) |
| 538 |
return projection_(self.pa, self.pc, a), |
| 539 |
projection_(self.pa, self.pb, a), |
| 540 |
projection_(self.pb, self.pa, b), |
| 541 |
projection_(self.pb, self.pc, b), |
| 542 |
projection_(self.pc, self.pb, c), |
| 543 |
projection_(self.pc, self.pa, c) |
| 544 |
end |
| 545 |
|
| 546 |
function triangle:adams_points() |
| 547 |
local i = self:kimberling(1) |
| 548 |
local g = self:kimberling(7) |
| 549 |
local l = projection_(self.pa, self.pc, i) |
| 550 |
local n = projection_(self.pa, self.pb, i) |
| 551 |
local m = projection_(self.pb, self.pc, i) |
| 552 |
local x = ll_from_(g, m, n) |
| 553 |
local y = ll_from_(g, n, l) |
| 554 |
local z = ll_from_(g, m, l) |
| 555 |
local t1 = intersection_ll_(x, g, self.pa, self.pb) |
| 556 |
local t4 = intersection_ll_(x, g, self.pb, self.pc) |
| 557 |
local t2 = intersection_ll_(y, g, self.pa, self.pb) |
| 558 |
local t5 = intersection_ll_(y, g, self.pa, self.pc) |
| 559 |
local t3 = intersection_ll_(z, g, self.pb, self.pc) |
| 560 |
local t6 = intersection_ll_(z, g, self.pa, self.pc) |
| 561 |
return t1, t2, t3, t4, t5, t6 |
| 562 |
end |
| 563 |
|
| 564 |
function triangle:lamoen_points() |
| 565 |
local ma, mb, mc = medial_tr_(self.pa, self.pb, self.pc) |
| 566 |
local g = centroid_(self.pa, self.pb, self.pc) |
| 567 |
local p1 = circum_center_(self.pa, mc, g) |
| 568 |
local p2 = circum_center_(self.pb, ma, g) |
| 569 |
local p3 = circum_center_(self.pb, mc, g) |
| 570 |
local p4 = circum_center_(self.pc, mb, g) |
| 571 |
local p5 = circum_center_(self.pc, ma, g) |
| 572 |
local p6 = circum_center_(self.pa, mb, g) |
| 573 |
return p1, p2, p3, p4, p5, p6 |
| 574 |
end |
| 575 |
|
| 576 |
function triangle:yiu_centers() |
| 577 |
local ap = symmetry_axial_(self.pb, self.pc, self.pa) |
| 578 |
local bp = symmetry_axial_(self.pa, self.pc, self.pb) |
| 579 |
local cp = symmetry_axial_(self.pa, self.pb, self.pc) |
| 580 |
local oa = circum_center_(self.pa, bp, cp) |
| 581 |
local ob = circum_center_(self.pb, ap, cp) |
| 582 |
local oc = circum_center_(self.pc, bp, ap) |
| 583 |
return oa, ob, oc |
| 584 |
end |
| 585 |
|
| 586 |
function triangle:first_brocard_point() |
| 587 |
return self:trilinear(self.c / self.b, self.a / self.c, self.b / self.a) |
| 588 |
end |
| 589 |
|
| 590 |
function triangle:second_brocard_point() |
| 591 |
return self:trilinear(self.b / self.c, self.c / self.a, self.a / self.b) |
| 592 |
end |
| 593 |
|
| 594 |
function triangle:brocard_midpoint() |
| 595 |
return self:kimberling(39) |
| 596 |
end |
| 597 |
|
| 598 |
function triangle:macbeath_point() |
| 599 |
return self:kimberling(264) |
| 600 |
end |
| 601 |
|
| 602 |
function triangle:poncelet_point(pt) |
| 603 |
local A, B, C, D = self.pa, self.pb, self.pc, pt |
| 604 |
local e1 = euler_center_(A, B, C) |
| 605 |
local e2 = euler_center_(A, C, D) |
| 606 |
local m = midpoint_(A, C) |
| 607 |
local x, y = intersection_cc_(e1, m, e2, m) |
| 608 |
|
| 609 |
if not x or not y then |
| 610 |
tex.error("Poncelet construction failed: no intersection.") |
| 611 |
end |
| 612 |
|
| 613 |
if x == m then |
| 614 |
return y |
| 615 |
else |
| 616 |
return x |
| 617 |
end |
| 618 |
end |
| 619 |
|
| 620 |
function triangle:orthopole(l, EPS) |
| 621 |
EPS = EPS or tkz.epsilon |
| 622 |
|
| 623 |
-- garde-fous |
| 624 |
if tkz.is_linear(self.pa, self.pb, self.pc) then |
| 625 |
tex.error("orthopole: degenerate triangle") |
| 626 |
return |
| 627 |
end |
| 628 |
|
| 629 |
local p, q = l:get() |
| 630 |
if point.abs(p - q) <= EPS then |
| 631 |
tex.error("orthopole: degenerate line") |
| 632 |
return |
| 633 |
end |
| 634 |
|
| 635 |
-- projections de A,B sur l (on n'a pas besoin de C ici) |
| 636 |
local ap = projection_(p, q, self.pa) |
| 637 |
local bp = projection_(p, q, self.pb) |
| 638 |
|
| 639 |
-- pieds sur les côtés CA et BC |
| 640 |
local a1, a2 = self.bc:get() -- droite (BC) |
| 641 |
local c1, c2 = self.ca:get() -- droite (CA) |
| 642 |
|
| 643 |
if point.abs(a2 - a1) <= EPS or point.abs(c2 - c1) <= EPS then |
| 644 |
tex.error("orthopole: degenerate triangle side") |
| 645 |
return |
| 646 |
end |
| 647 |
|
| 648 |
local app = projection_(a1, a2, ap) -- pied de ap sur (BC) |
| 649 |
local bpp = projection_(c1, c2, bp) -- pied de bp sur (CA) |
| 650 |
|
| 651 |
-- orthopole = intersection des droites (ap, app) et (bp, bpp) |
| 652 |
return intersection(line:new(ap, app), line:new(bp, bpp)) |
| 653 |
end |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
function triangle:isodynamic_points() |
| 658 |
-- Cas particulier : triangle équilatéral |
| 659 |
if self:is_equilateral() then |
| 660 |
-- On prend le centre de gravité G = (A + B + C)/3 |
| 661 |
local A, B, C = self.pa, self.pb, self.pc |
| 662 |
local G = (A + B + C) / 3 |
| 663 |
-- On renvoie deux fois le même point pour garder la même signature |
| 664 |
return G, G |
| 665 |
end |
| 666 |
|
| 667 |
-- Cas général |
| 668 |
local a, b, c = self.a, self.b, self.c |
| 669 |
local ab, bc = self.ab, self.bc, self.ca -- self.ca est inutile ici mais cohérent |
| 670 |
|
| 671 |
-- Cercles d’Apollonius associés aux rapports b/a sur AB et c/b sur BC |
| 672 |
local Cab = ab:apollonius(b / a) |
| 673 |
local Cbc = bc:apollonius(c / b) |
| 674 |
|
| 675 |
-- L’intersection donne les deux points isodynamiques |
| 676 |
return intersection(Cab, Cbc) |
| 677 |
end |
| 678 |
|
| 679 |
triangle.neuberg_points = triangle.isodynamic_points |
| 680 |
|
| 681 |
-- Points d’intersection du cercle d’Apollonius (b/a, côté AB) |
| 682 |
-- avec la droite (AB), en mettant en premier le point sur le segment [AB]. |
| 683 |
|
| 684 |
function triangle:apollonius_points(side, EPS) |
| 685 |
EPS = EPS or tkz.epsilon |
| 686 |
|
| 687 |
local a, b, c = self.a, self.b, self.c -- a = BC, b = CA |
| 688 |
local A, B, C = self.pa, self.pb, self.pc |
| 689 |
local ab, bc, ca = self.ab, self.bc, self.ca |
| 690 |
local x, y, X, Y, L, k |
| 691 |
if side == "ab" then |
| 692 |
L = self.ab |
| 693 |
k = b / a |
| 694 |
x, y = a, b |
| 695 |
X, Y = A, B -- AC / BC |
| 696 |
elseif side == "bc" then |
| 697 |
L = self.bc |
| 698 |
k = c / b |
| 699 |
x, y = b, c |
| 700 |
X, Y = B, C -- AB / CA |
| 701 |
elseif side == "ca" then |
| 702 |
L = self.ca |
| 703 |
k = a / c |
| 704 |
x, y = c, a |
| 705 |
X, Y = C, A -- BC / AB |
| 706 |
else |
| 707 |
tex.error("triangle:apollonius_circle -> invalid side: use 'ab', 'bc', or 'ca'") |
| 708 |
return |
| 709 |
end |
| 710 |
|
| 711 |
if math.abs(x - y) <= EPS then |
| 712 |
local M = (X + Y) / 2 |
| 713 |
return M, M |
| 714 |
end |
| 715 |
|
| 716 |
return L:harmonic(k) |
| 717 |
end |
| 718 |
|
| 719 |
-- Ancien nom si tu veux conserver la compatibilité : |
| 720 |
-- triangle.bisector_points = triangle.apollonius_points |
| 721 |
|
| 722 |
function triangle:the_apollonius_center() |
| 723 |
local lbrocard = self:brocard_axis() |
| 724 |
local n = self.eulercenter |
| 725 |
local s = self.spiekercenter |
| 726 |
local lns = line(n,s) |
| 727 |
return intersection(lbrocard, lns) |
| 728 |
end |
| 729 |
|
| 730 |
function triangle:apollonius_point() |
| 731 |
return kimberling(181) |
| 732 |
end |
| 733 |
|
| 734 |
function triangle:isotomic(p) |
| 735 |
local pta, ptb, ptc = cevian_(self.pa, self.pb, self.pc, p) |
| 736 |
|
| 737 |
local pta_s = 2*self.ma - pta |
| 738 |
local ptb_s = 2*self.mb - ptb |
| 739 |
|
| 740 |
return intersection_ll_(self.pa,pta_s,self.pb,ptb_s) |
| 741 |
end |
| 742 |
|
| 743 |
function triangle:anticomplement(p) |
| 744 |
return self.centroid:homothety(-2,p) |
| 745 |
end |
| 746 |
|
| 747 |
function triangle:complement(p) |
| 748 |
return self.centroid:homothety(-1/2,p) |
| 749 |
end |
| 750 |
------------------- |
| 751 |
-- Result -> line |
| 752 |
------------------- |
| 753 |
|
| 754 |
function triangle:symmedian_line(arg) |
| 755 |
local pts = { self.pa, self.pb, self.pc } |
| 756 |
local i = resolve_triangle_index(self, arg) |
| 757 |
if i < 0 or i > 2 then |
| 758 |
return nil |
| 759 |
end |
| 760 |
|
| 761 |
local A = pts[i + 1] |
| 762 |
local B = pts[(i + 1) % 3 + 1] |
| 763 |
local C = pts[(i + 2) % 3 + 1] |
| 764 |
local L = self:lemoine_point() |
| 765 |
|
| 766 |
local P = intersection_ll_(A, L, B, C) |
| 767 |
return line:new(A, P) |
| 768 |
end |
| 769 |
|
| 770 |
|
| 771 |
function triangle:altitude(arg) |
| 772 |
local pts = { self.pa, self.pb, self.pc } |
| 773 |
local i = resolve_triangle_index(self, arg) |
| 774 |
if i < 0 or i > 2 then |
| 775 |
return nil |
| 776 |
end |
| 777 |
|
| 778 |
local A = pts[i + 1] |
| 779 |
local B = pts[(i + 1) % 3 + 1] |
| 780 |
local C = pts[(i + 2) % 3 + 1] |
| 781 |
|
| 782 |
return line:new(A, projection_(B, C, A)) |
| 783 |
end |
| 784 |
|
| 785 |
|
| 786 |
function triangle:bisector(arg) |
| 787 |
local i = resolve_triangle_index(self, arg) |
| 788 |
if i < 0 or i > 2 then |
| 789 |
return nil |
| 790 |
end |
| 791 |
|
| 792 |
local pts = { self.pa, self.pb, self.pc } |
| 793 |
local I = self.incenter |
| 794 |
|
| 795 |
local A = pts[i + 1] |
| 796 |
local B = pts[(i + 1) % 3 + 1] |
| 797 |
local C = pts[(i + 2) % 3 + 1] |
| 798 |
|
| 799 |
local P = intersection_ll_(A, I, B, C) |
| 800 |
return line:new(A, P) |
| 801 |
end |
| 802 |
|
| 803 |
|
| 804 |
function triangle:bisector_ext(arg) |
| 805 |
local i = resolve_triangle_index(self, arg) |
| 806 |
if i < 0 or i > 2 then |
| 807 |
return nil |
| 808 |
end |
| 809 |
|
| 810 |
local pts = { self.pa, self.pb, self.pc } |
| 811 |
local A = pts[i + 1] |
| 812 |
local B = pts[(i + 1) % 3 + 1] |
| 813 |
local C = pts[(i + 2) % 3 + 1] |
| 814 |
|
| 815 |
return line:new(A, bisector_ext_(A, B, C)) |
| 816 |
end |
| 817 |
|
| 818 |
|
| 819 |
function triangle:mediator(arg) |
| 820 |
local i = resolve_triangle_index(self, arg) |
| 821 |
if i < 0 or i > 2 then |
| 822 |
return nil |
| 823 |
end |
| 824 |
|
| 825 |
local pts = { self.pa, self.pb, self.pc } |
| 826 |
local B = pts[(i + 1) % 3 + 1] |
| 827 |
local C = pts[(i + 2) % 3 + 1] |
| 828 |
|
| 829 |
return line:new(B, C):mediator() |
| 830 |
end |
| 831 |
|
| 832 |
|
| 833 |
function triangle:trisector(arg) |
| 834 |
local pts = { self.pa, self.pb, self.pc } |
| 835 |
local i = resolve_triangle_index(self, arg) |
| 836 |
if i < 0 or i > 2 then |
| 837 |
return nil |
| 838 |
end |
| 839 |
|
| 840 |
local A = pts[i + 1] |
| 841 |
local B = pts[(i + 1) % 3 + 1] |
| 842 |
local C = pts[(i + 2) % 3 + 1] |
| 843 |
|
| 844 |
local an = get_angle_(A, B, C) |
| 845 |
local pti = report_(A, B, 1) |
| 846 |
local ptj = rotation_(A, an / 3, pti) |
| 847 |
local ptk = rotation_(A, an / 3, ptj) |
| 848 |
|
| 849 |
return line(A, ptj), line(A, ptk) |
| 850 |
end |
| 851 |
|
| 852 |
function triangle:antiparallel(pt, arg) |
| 853 |
local a, b, c = self.pa, self.pb, self.pc |
| 854 |
local I = self.incenter |
| 855 |
local i = resolve_triangle_index(self, arg) |
| 856 |
|
| 857 |
local S = { a, b, c } |
| 858 |
local A = S[i + 1] -- sommet de départ |
| 859 |
local B = S[(i + 1) % 3 + 1] -- premier sommet adjacent |
| 860 |
local C = S[(i + 2) % 3 + 1] -- second sommet adjacent |
| 861 |
|
| 862 |
-- u, v sont les symétriques de B et C par rapport à la bissectrice en I |
| 863 |
local u = symmetry_axial_(A, I, B) |
| 864 |
local v = symmetry_axial_(A, I, C) |
| 865 |
local w = ll_from_(pt, u, v) |
| 866 |
|
| 867 |
return line:new(intersection_ll_(pt, w, B, A), intersection_ll_(pt, w, C, A)) |
| 868 |
end |
| 869 |
|
| 870 |
function triangle:orthic_axis() |
| 871 |
local x, y, z = orthic_axis_(self.pa, self.pb, self.pc) |
| 872 |
return line:new(x, z) |
| 873 |
end |
| 874 |
|
| 875 |
-- N,H,G,O -- check_equilateral_ (a,b,c) |
| 876 |
function triangle:euler_line() |
| 877 |
if check_equilateral_(self.pa, self.pb, self.pc) then |
| 878 |
tex.error("An error has occurred", { "No euler line with equilateral triangle" }) |
| 879 |
else |
| 880 |
local a, b, c = orthic_axis_(self.pa, self.pb, self.pc) |
| 881 |
local x = projection_(a, c, self.eulercenter) |
| 882 |
return line:new(self.eulercenter, x) |
| 883 |
end |
| 884 |
end |
| 885 |
|
| 886 |
-- with pt on the circumcircle |
| 887 |
function triangle:steiner_line(pt) |
| 888 |
local u = symmetry_axial_(self.pa, self.pb, pt) |
| 889 |
local v = symmetry_axial_(self.pa, self.pc, pt) |
| 890 |
return line:new(u, v) |
| 891 |
end |
| 892 |
|
| 893 |
function triangle:lemoine_axis() -- revoir car problème |
| 894 |
local C = self:circum_circle() |
| 895 |
local pl = self:lemoine_point() |
| 896 |
return C:polar(pl) |
| 897 |
end |
| 898 |
|
| 899 |
function triangle:fermat_axis() |
| 900 |
local x = self:first_fermat_point() |
| 901 |
local y = self:second_fermat_point() |
| 902 |
return line:new(x, y) |
| 903 |
end |
| 904 |
|
| 905 |
function triangle:brocard_axis() |
| 906 |
return line:new(self.circumcenter, self:lemoine_point()) |
| 907 |
end |
| 908 |
|
| 909 |
function triangle:simson_line(pt) -- pt on circumcircle |
| 910 |
local x = self.ab:projection(pt) |
| 911 |
local y = self.bc:projection(pt) |
| 912 |
return line:new(x, y) |
| 913 |
end |
| 914 |
|
| 915 |
function triangle:soddy_line() |
| 916 |
return line:new(self:soddy_center(), self:soddy_center("outer")) |
| 917 |
end |
| 918 |
|
| 919 |
----------------------- |
| 920 |
--- Result -> circles -- |
| 921 |
----------------------- |
| 922 |
|
| 923 |
|
| 924 |
function triangle:apollonius_circle(side, EPS) |
| 925 |
EPS = EPS or tkz.epsilon |
| 926 |
-- lengths |
| 927 |
local a, b, c = self.a, self.b, self.c |
| 928 |
local L, k |
| 929 |
|
| 930 |
if side == "ab" then |
| 931 |
L = self.ab |
| 932 |
k = b / a -- AC / BC |
| 933 |
elseif side == "bc" then |
| 934 |
L = self.bc |
| 935 |
k = c / b -- AB / CA |
| 936 |
elseif side == "ca" then |
| 937 |
L = self.ca |
| 938 |
k = a / c -- BC / AB |
| 939 |
else |
| 940 |
tex.error("triangle:apollonius_circle -> invalid side: use 'ab', 'bc', or 'ca'") |
| 941 |
return |
| 942 |
end |
| 943 |
|
| 944 |
-- cas k ≈ 1 : volontairement traité |
| 945 |
if math.abs(k - 1) <= EPS then |
| 946 |
return L:bisector() |
| 947 |
else |
| 948 |
return L:apollonius(k) |
| 949 |
end |
| 950 |
end |
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
function triangle:three_apollonius_circles() |
| 955 |
local a, b, c = self.a, self.b, self.c |
| 956 |
local ab, bc, ca = self.ab, self.bc, self.ca |
| 957 |
local Cab = ab:apollonius(b / a) |
| 958 |
local Cbc = bc:apollonius(c / b) |
| 959 |
local Cca = ca:apollonius(a / c) |
| 960 |
return Cab, Cbc, Cca |
| 961 |
end |
| 962 |
|
| 963 |
|
| 964 |
function triangle:three_tangent_circles() |
| 965 |
local i = self.incenter |
| 966 |
local a, b, c = self:projection(i) |
| 967 |
return circle:new(self.pa, c), circle:new(self.pb, a), circle:new(self.pc, b) |
| 968 |
end |
| 969 |
|
| 970 |
|
| 971 |
function triangle:euler_circle() |
| 972 |
return circle:new(euler_center_(self.pa, self.pb, self.pc), midpoint_(self.pb, self.pc)) |
| 973 |
end |
| 974 |
|
| 975 |
--aliase |
| 976 |
triangle.feuerbach = triangle.euler_circle |
| 977 |
|
| 978 |
function triangle:circum_circle() |
| 979 |
return circle:new(circum_center_(self.pa, self.pb, self.pc),self.pa) |
| 980 |
end |
| 981 |
|
| 982 |
function triangle:in_circle() |
| 983 |
return circle:new(self.incenter, projection_(self.pb, self.pc, self.incenter)) |
| 984 |
end |
| 985 |
-- see excenter ?? |
| 986 |
|
| 987 |
function triangle:ex_circle(arg) |
| 988 |
local pts = { self.pa, self.pb, self.pc } |
| 989 |
local i = resolve_triangle_index(self, arg) |
| 990 |
if i < 0 or i > 2 then return nil end |
| 991 |
|
| 992 |
local A = pts[i + 1] |
| 993 |
local B = pts[(i + 1) % 3 + 1] |
| 994 |
local C = pts[(i + 2) % 3 + 1] |
| 995 |
|
| 996 |
local O = ex_center_(A, B, C) -- excentre opposé à A |
| 997 |
local T = projection_(B, C, O) -- point de tangence sur (BC) |
| 998 |
|
| 999 |
return circle:new(O, T) |
| 1000 |
end |
| 1001 |
|
| 1002 |
function triangle:radical_circle() |
| 1003 |
local Ca, Cb, Cc |
| 1004 |
Ca = self:ex_circle(self.pa) |
| 1005 |
Cb = self:ex_circle(self.pb) |
| 1006 |
Cc = self:ex_circle(self.pc) |
| 1007 |
return Ca:radical_circle(Cb, Cc) |
| 1008 |
end |
| 1009 |
|
| 1010 |
function triangle:spieker_circle() |
| 1011 |
local ma, mb, mc, sp |
| 1012 |
ma, mb, mc = medial_tr_(self.pa, self.pb, self.pc) |
| 1013 |
sp = in_center_(ma, mb, mc) |
| 1014 |
return circle:new(sp, projection_(ma, mb, sp)) |
| 1015 |
end |
| 1016 |
|
| 1017 |
function triangle:cevian_circle(p) |
| 1018 |
local pta, ptb, ptc = cevian_(self.pa, self.pb, self.pc, p) |
| 1019 |
return circle:new(circum_center_(pta, ptb, ptc), pta) |
| 1020 |
end |
| 1021 |
|
| 1022 |
function triangle:symmedial_circle() |
| 1023 |
local pta, ptb, ptc, p |
| 1024 |
p = lemoine_point_(self.pa, self.pb, self.pc) |
| 1025 |
pta, ptb, ptc = cevian_(self.pa, self.pb, self.pc, p) |
| 1026 |
return circle:new(circum_center_(pta, ptb, ptc), pta) |
| 1027 |
end |
| 1028 |
|
| 1029 |
function triangle:conway_circle() |
| 1030 |
local t |
| 1031 |
t = report_(self.pb, self.pa, length_(self.pb, self.pc), self.pa) |
| 1032 |
return circle:new(self.incenter, t) |
| 1033 |
end |
| 1034 |
|
| 1035 |
function triangle:pedal_circle(pt) |
| 1036 |
local x, y, z, c |
| 1037 |
x = projection_(self.pb, self.pc, pt) |
| 1038 |
y = projection_(self.pa, self.pc, pt) |
| 1039 |
z = projection_(self.pa, self.pb, pt) |
| 1040 |
c = circum_center_(x, y, z) |
| 1041 |
return circle:new(c, x) |
| 1042 |
end |
| 1043 |
|
| 1044 |
function triangle:first_lemoine_circle() |
| 1045 |
local lc, oc |
| 1046 |
lc = self:lemoine_point() |
| 1047 |
oc = self.circumcenter |
| 1048 |
return circle:new(midpoint_(lc, oc), intersection_ll_(lc, ll_from_(lc, self.pa, self.pb), self.pa, self.pc)) |
| 1049 |
end |
| 1050 |
|
| 1051 |
function triangle:second_lemoine_circle() |
| 1052 |
local lc, a, b, c, r, th |
| 1053 |
lc = self:lemoine_point() |
| 1054 |
a = point.abs(self.pc - self.pb) |
| 1055 |
b = point.abs(self.pa - self.pc) |
| 1056 |
c = point.abs(self.pb - self.pa) |
| 1057 |
r = (a * b * c) / (a * a + b * b + c * c) |
| 1058 |
th = lc + point(r, 0) |
| 1059 |
return circle:new(lc, th) |
| 1060 |
end |
| 1061 |
|
| 1062 |
function triangle:bevan_circle() |
| 1063 |
local o, r, s, t |
| 1064 |
o = circum_center_(excentral_tr_(self.pa, self.pb, self.pc)) |
| 1065 |
r, s, t = excentral_tr_(self.pa, self.pb, self.pc) |
| 1066 |
return circle:new(o, r) |
| 1067 |
end |
| 1068 |
|
| 1069 |
function triangle:taylor_circle() |
| 1070 |
local a, b, c = orthic_tr_(self.pa, self.pb, self.pc) |
| 1071 |
local d = projection_(self.pa, self.pb, a) |
| 1072 |
local e = projection_(self.pb, self.pc, b) |
| 1073 |
local f = projection_(self.pc, self.pa, c) |
| 1074 |
return circle:new(circum_center_(d, e, f), d) |
| 1075 |
end |
| 1076 |
|
| 1077 |
function triangle:adams_circle() |
| 1078 |
local i = self:kimberling(1) |
| 1079 |
local g = self:kimberling(7) |
| 1080 |
local m = projection_(self.pb, self.pc, i) |
| 1081 |
local n = projection_(self.pa, self.pb, i) |
| 1082 |
local x = ll_from_(g, m, n) |
| 1083 |
local t = intersection_ll_(x, g, self.pa, self.pb) |
| 1084 |
return circle:new(i, t) |
| 1085 |
end |
| 1086 |
|
| 1087 |
function triangle:lamoen_circle() |
| 1088 |
local ma, mb, mc = medial_tr_(self.pa, self.pb, self.pc) |
| 1089 |
local g = centroid_(self.pa, self.pb, self.pc) |
| 1090 |
local p1 = circum_center_(self.pa, mb, g) |
| 1091 |
local p2 = circum_center_(self.pb, ma, g) |
| 1092 |
local p3 = circum_center_(self.pc, ma, g) |
| 1093 |
local c = circum_center_(p1, p2, p3) |
| 1094 |
return circle:new(c, p1) |
| 1095 |
end |
| 1096 |
|
| 1097 |
-- soddy circles |
| 1098 |
function triangle:soddy_circle(outer) |
| 1099 |
outer = (outer == "outer") |
| 1100 |
local index = outer and 175 or 176 |
| 1101 |
local c = self:kimberling(index) |
| 1102 |
local ra = (self.b + self.c - self.a) / 2 |
| 1103 |
local ta = report_(self.pa, self.pb, ra, self.pa) |
| 1104 |
local x, y = intersection_lc_(self.pa, c, self.pa, ta) |
| 1105 |
local t |
| 1106 |
if outer then |
| 1107 |
t = (length_(x, c) > length_(y, c)) and x or y |
| 1108 |
else |
| 1109 |
t = (length_(x, c) < length_(y, c)) and x or y |
| 1110 |
end |
| 1111 |
return circle:new(c, t) |
| 1112 |
end |
| 1113 |
|
| 1114 |
function triangle:yiu_circles() |
| 1115 |
local x, y, z = self:yiu_centers() |
| 1116 |
return circle:new(x, self.pa), circle:new(y, self.pb), circle:new(z, self.pc) |
| 1117 |
end |
| 1118 |
|
| 1119 |
function triangle:kenmotu_circle() |
| 1120 |
local a, b, c = self.a, self.b, self.c |
| 1121 |
local area = self.area |
| 1122 |
local rho = (math.sqrt(2) * a * b * c) / (4 * area + (a ^ 2 + b ^ 2 + c ^ 2)) |
| 1123 |
local center = self:kimberling(371) |
| 1124 |
return circle:new(through(center, rho)) |
| 1125 |
end |
| 1126 |
|
| 1127 |
|
| 1128 |
-- Circle tangent to the sides originating from p and to the circle passing through the other two vertices. |
| 1129 |
-- argument the vertex of the chosen triangle, the center of the circle passing through the other two vertices. |
| 1130 |
|
| 1131 |
function triangle:c_c(p, C) |
| 1132 |
local a, b, c |
| 1133 |
local i = resolve_triangle_index(self, p) |
| 1134 |
if i == 0 then |
| 1135 |
a, b, c = self.pa, self.pb, self.pc |
| 1136 |
elseif i == 1 then |
| 1137 |
a, b, c = self.pb, self.pc, self.pa |
| 1138 |
elseif i == 2 then |
| 1139 |
a, b, c = self.pc, self.pa, self.pb |
| 1140 |
end |
| 1141 |
local Lm = self:mediator(p) |
| 1142 |
local n = intersection(Lm, C, {near = p}) |
| 1143 |
local i = self.incenter |
| 1144 |
local q = line:new(c, i):reflection(n) |
| 1145 |
local L = line:new(c, q):parallel_from(i) |
| 1146 |
local Lac = line:new(a, c) |
| 1147 |
local e = intersection(L, Lac) |
| 1148 |
local Lia = line:new(i, a) |
| 1149 |
local Le = Lac:orthogonal_from(e) |
| 1150 |
return circle(intersection(Lia, Le), e) |
| 1151 |
end |
| 1152 |
triangle.thebault = triangle.c_c |
| 1153 |
|
| 1154 |
function triangle:thebault_circles(p) |
| 1155 |
local pa, pb, pc = self.pa, self.pb, self.pc |
| 1156 |
local a, b, c -- sommets réordonnés |
| 1157 |
local side -- côté sur lequel se trouve p (objet line) |
| 1158 |
|
| 1159 |
-------------------------------------------------- |
| 1160 |
-- 1. Déterminer le côté contenant p et (a,b,c) |
| 1161 |
-- a = sommet opposé au côté portant p |
| 1162 |
-------------------------------------------------- |
| 1163 |
if self.bc:on_segment(p) then |
| 1164 |
-- p sur BC -> sommet opposé A |
| 1165 |
a, b, c = pa, pb, pc |
| 1166 |
side = self.bc |
| 1167 |
|
| 1168 |
elseif self.ca:on_segment(p) then |
| 1169 |
-- p sur CA -> sommet opposé B |
| 1170 |
a, b, c = pb, pc, pa |
| 1171 |
side = self.ca |
| 1172 |
|
| 1173 |
elseif self.ab:on_segment(p) then |
| 1174 |
-- p sur AB -> sommet opposé C |
| 1175 |
a, b, c = pc, pa, pb |
| 1176 |
side = self.ab |
| 1177 |
|
| 1178 |
else |
| 1179 |
tex.error("thebault_circles: point is not on any side of the triangle.") |
| 1180 |
return |
| 1181 |
end |
| 1182 |
|
| 1183 |
-------------------------------------------------- |
| 1184 |
-- 2. Construction des centres (comme dans ta version) |
| 1185 |
-------------------------------------------------- |
| 1186 |
local i = self.incenter -- incenter du triangle ABC |
| 1187 |
local ic = in_center_(p, a, c) -- incenter du triangle (p,a,c) |
| 1188 |
local ib = in_center_(p, a, b) -- incenter du triangle (p,a,b) |
| 1189 |
|
| 1190 |
-- projections de p sur (ic i) et (ib i) |
| 1191 |
local pc_ = projection_(p, ic, i) |
| 1192 |
local pb_ = projection_(p, ib, i) |
| 1193 |
|
| 1194 |
-- intersections avec (b c) |
| 1195 |
local tc = intersection_ll_(i, pc_, b, c) |
| 1196 |
local tb = intersection_ll_(i, pb_, b, c) |
| 1197 |
|
| 1198 |
-- perpendiculaires à (b c) par tc et tb |
| 1199 |
local xc = ortho_from_(tc, b, c) |
| 1200 |
local xb = ortho_from_(tb, b, c) |
| 1201 |
|
| 1202 |
-- centres des deux cercles |
| 1203 |
local center_c = intersection_ll_(p, ic, tc, xc) |
| 1204 |
local center_b = intersection_ll_(p, ib, tb, xb) |
| 1205 |
|
| 1206 |
if not center_b or not center_c then |
| 1207 |
tex.error("thebault_circles: failed to construct circle centers.") |
| 1208 |
return |
| 1209 |
end |
| 1210 |
|
| 1211 |
-------------------------------------------------- |
| 1212 |
-- 3. Points de tangence sur le côté et cercles |
| 1213 |
-------------------------------------------------- |
| 1214 |
-- side:projection(pt1, pt2) renvoie les projections |
| 1215 |
local tb_tan, tc_tan = side:projection(center_b, center_c) |
| 1216 |
|
| 1217 |
local Cb = circle:new(center_b, tb_tan) |
| 1218 |
local Cc = circle:new(center_c, tc_tan) |
| 1219 |
|
| 1220 |
return Cb, Cc |
| 1221 |
end |
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
function triangle:mixtilinear_incircle(arg) |
| 1226 |
local i = resolve_triangle_index(self, arg) |
| 1227 |
|
| 1228 |
local incenter = self.incenter |
| 1229 |
local pts = { self.pa, self.pb, self.pc } |
| 1230 |
local segs = { self.ab, self.bc, self.ca } |
| 1231 |
|
| 1232 |
local A = pts[i + 1] |
| 1233 |
local B = pts[(i + 1) % 3 + 1] |
| 1234 |
local C = pts[(i + 2) % 3 + 1] |
| 1235 |
|
| 1236 |
local AB = segs[i + 1] |
| 1237 |
local BC = segs[(i + 1) % 3 + 1] |
| 1238 |
local CA = segs[(i + 2) % 3 + 1] |
| 1239 |
|
| 1240 |
local l = line:new(A, incenter) |
| 1241 |
local lp = l:orthogonal_from(incenter) |
| 1242 |
local P1 = intersection(lp, CA) |
| 1243 |
local P2 = intersection(lp, AB) |
| 1244 |
local l1 = CA:orthogonal_from(P1) |
| 1245 |
local l2 = AB:orthogonal_from(P2) |
| 1246 |
local W = intersection(l1, l2) |
| 1247 |
|
| 1248 |
return circle(W, P1) |
| 1249 |
end |
| 1250 |
|
| 1251 |
function triangle:feuerbach_apollonius(EPS) |
| 1252 |
EPS = EPS or tkz.epsilon |
| 1253 |
-- 1. Points de Feuerbach |
| 1254 |
local Ea, Eb, Ec = self:feuerbach():get() |
| 1255 |
-- -- 2. Excentre Ja |
| 1256 |
local C_JaEa = self:ex_circle() |
| 1257 |
-- 4. Spieker center |
| 1258 |
local S = self.spiekercenter |
| 1259 |
-- 5. Cercle orthogonal |
| 1260 |
local Cortho = C_JaEa:orthogonal_from(S) |
| 1261 |
-- 6. Cercle d'Euler |
| 1262 |
local Ceuler = self:euler_circle() |
| 1263 |
-- 7. Inversion du cercle |
| 1264 |
local InvEuler = Cortho:inversion(Ceuler) |
| 1265 |
local O = InvEuler.center |
| 1266 |
-- 8. Points inversés |
| 1267 |
local xa, xb, xc = Cortho:inversion(Ea, Eb, Ec) |
| 1268 |
return circle:new(O, xa) |
| 1269 |
end |
| 1270 |
|
| 1271 |
function triangle:feuerbach_apollonius_k181(EPS) |
| 1272 |
EPS = EPS or tkz.epsilon |
| 1273 |
local Ea, Eb, Ec = self:feuerbach():get() --Feuerbach points |
| 1274 |
local A = self:kimberling(181)-- Apollonius point |
| 1275 |
local S = self.spiekercenter |
| 1276 |
local xa = intersection_ll_(self.pa,A,S,Ea) |
| 1277 |
local xb = intersection_ll_(self.pb,A,S,Eb) |
| 1278 |
local xc = intersection_ll_(self.pc,A,S,Ec) |
| 1279 |
return circle:new(circum_circle_(xa, xb, xc)) |
| 1280 |
end |
| 1281 |
|
| 1282 |
function triangle:the_apollonius_circle() |
| 1283 |
local ce = self:the_apollonius_center() |
| 1284 |
local apo = self:kimberling(181) |
| 1285 |
local ll = line(apo, self.pa) |
| 1286 |
local cxa = self:ex_circle() |
| 1287 |
local u,v = intersection(ll, cxa,{near = self.pa}) |
| 1288 |
return circle:new(ce, v) |
| 1289 |
end |
| 1290 |
|
| 1291 |
------------------- |
| 1292 |
-- Result -> triangle |
| 1293 |
------------------- |
| 1294 |
function triangle:orthic() |
| 1295 |
return triangle:new(orthic_tr_(self.pa, self.pb, self.pc)) |
| 1296 |
end |
| 1297 |
|
| 1298 |
function triangle:medial() |
| 1299 |
return triangle:new(medial_tr_(self.pa, self.pb, self.pc)) |
| 1300 |
end |
| 1301 |
|
| 1302 |
function triangle:incentral() |
| 1303 |
return triangle:new(incentral_tr_(self.pa, self.pb, self.pc)) |
| 1304 |
end |
| 1305 |
|
| 1306 |
function triangle:excentral() |
| 1307 |
return triangle:new(excentral_tr_(self.pa, self.pb, self.pc)) |
| 1308 |
end |
| 1309 |
|
| 1310 |
function triangle:intouch() |
| 1311 |
return triangle:new(intouch_tr_(self.pa, self.pb, self.pc)) |
| 1312 |
end |
| 1313 |
|
| 1314 |
function triangle:contact() |
| 1315 |
return triangle:new(intouch_tr_(self.pa, self.pb, self.pc)) |
| 1316 |
end |
| 1317 |
triangle.contact = triangle.intouch |
| 1318 |
triangle.gergonne = triangle.intouch |
| 1319 |
|
| 1320 |
function triangle:extouch() |
| 1321 |
return triangle:new(extouch_tr_(self.pa, self.pb, self.pc)) |
| 1322 |
end |
| 1323 |
triangle.nagel = triangle.extouch |
| 1324 |
|
| 1325 |
function triangle:feuerbach() |
| 1326 |
return triangle:new(feuerbach_tr_(self.pa, self.pb, self.pc)) |
| 1327 |
end |
| 1328 |
|
| 1329 |
function triangle:anti() |
| 1330 |
return triangle:new(anti_tr_(self.pa, self.pb, self.pc)) |
| 1331 |
end |
| 1332 |
|
| 1333 |
triangle.anticomplementary = triangle.anti |
| 1334 |
triangle.similar = triangle.anti |
| 1335 |
|
| 1336 |
function triangle:tangential() |
| 1337 |
return triangle:new(tangential_tr_(self.pa, self.pb, self.pc)) |
| 1338 |
end |
| 1339 |
|
| 1340 |
function triangle:cevian(p) |
| 1341 |
return triangle:new(cevian_(self.pa, self.pb, self.pc, p)) |
| 1342 |
end |
| 1343 |
|
| 1344 |
function triangle:symmedian() |
| 1345 |
local p = lemoine_point_(self.pa, self.pb, self.pc) |
| 1346 |
return triangle:new(cevian_(self.pa, self.pb, self.pc, p)) |
| 1347 |
end |
| 1348 |
triangle.symmedial = triangle.symmedian |
| 1349 |
|
| 1350 |
function triangle:lemoine() |
| 1351 |
local X = self:kimberling(598) |
| 1352 |
return triangle:new(cevian_(self.pa, self.pb, self.pc, X)) |
| 1353 |
end |
| 1354 |
|
| 1355 |
function triangle:macbeath() |
| 1356 |
local X = self:kimberling(264) |
| 1357 |
return triangle:new(cevian_(self.pa, self.pb, self.pc, X)) |
| 1358 |
end |
| 1359 |
|
| 1360 |
function triangle:euler() |
| 1361 |
return triangle:new(euler_points_(self.pa, self.pb, self.pc)) |
| 1362 |
end |
| 1363 |
|
| 1364 |
function triangle:pedal(pt) |
| 1365 |
return triangle:new(self:projections(pt)) |
| 1366 |
end |
| 1367 |
|
| 1368 |
function triangle:yiu() |
| 1369 |
return triangle:new(self:yiu_centers()) |
| 1370 |
end |
| 1371 |
|
| 1372 |
|
| 1373 |
function triangle:reflection() |
| 1374 |
return triangle:new( |
| 1375 |
symmetry_axial_(self.pb, self.pc, self.pa), |
| 1376 |
symmetry_axial_(self.pa, self.pc, self.pb), |
| 1377 |
symmetry_axial_(self.pa, self.pb, self.pc) |
| 1378 |
) |
| 1379 |
end |
| 1380 |
|
| 1381 |
function triangle:projection() |
| 1382 |
return triangle:new( |
| 1383 |
projection_(self.pb, self.pc, self.pa), |
| 1384 |
projection_(self.pa, self.pc, self.pb), |
| 1385 |
projection_(self.pa, self.pb, self.pc) |
| 1386 |
) |
| 1387 |
end |
| 1388 |
|
| 1389 |
function triangle:circumcevian(pt) |
| 1390 |
local circum = self:circum_circle() |
| 1391 |
local x = intersection_lc_(self.pa, pt, circum.center, circum.through) |
| 1392 |
local y = intersection_lc_(self.pb, pt, circum.center, circum.through) |
| 1393 |
local z = intersection_lc_(self.pc, pt, circum.center, circum.through) |
| 1394 |
return triangle:new(x, y, z) |
| 1395 |
end |
| 1396 |
|
| 1397 |
|
| 1398 |
function triangle:morley() |
| 1399 |
local la1, la2 = self:trisector(self.pa) |
| 1400 |
local lb1, lb2 = self:trisector(self.pb) |
| 1401 |
local lc1, lc2 = self:trisector(self.pc) |
| 1402 |
local D = intersection(la1, lb2) |
| 1403 |
local E = intersection(lb1, lc2) |
| 1404 |
local F = intersection(lc1, la2) |
| 1405 |
return triangle:new(D, E, F) |
| 1406 |
end |
| 1407 |
|
| 1408 |
|
| 1409 |
function triangle:napoleon(swap) |
| 1410 |
swap = (swap == "swap") |
| 1411 |
if swap then |
| 1412 |
local a = self.ab:equilateral().centroid |
| 1413 |
local b = self.bc:equilateral().centroid |
| 1414 |
local c = self.ca:equilateral().centroid |
| 1415 |
return triangle:new(a, b, c) |
| 1416 |
else |
| 1417 |
local a = self.ab:equilateral("swap").centroid |
| 1418 |
local b = self.bc:equilateral("swap").centroid |
| 1419 |
local c = self.ca:equilateral("swap").centroid |
| 1420 |
return triangle:new(a, b, c) |
| 1421 |
end |
| 1422 |
end |
| 1423 |
|
| 1424 |
|
| 1425 |
function triangle:soddy(outer) |
| 1426 |
local ci = self:soddy_circle(outer) |
| 1427 |
local a, b, c = self.pa, self.pb, self.pc |
| 1428 |
outer = (outer == "outer") |
| 1429 |
|
| 1430 |
local ce = ci.center |
| 1431 |
local ti = ci.through |
| 1432 |
local sa = intersection_lc_(ce, a, ce, ti) |
| 1433 |
local sb = intersection_lc_(ce, b, ce, ti) |
| 1434 |
local sc = intersection_lc_(ce, c, ce, ti) |
| 1435 |
return triangle:new(sa, sb, sc) |
| 1436 |
end |
| 1437 |
|
| 1438 |
------------------- |
| 1439 |
-- Result -> square |
| 1440 |
------------------- |
| 1441 |
|
| 1442 |
-- Method for inscribing a square in a triangle with vertex rotation |
| 1443 |
function triangle:square_inscribed(permutation) |
| 1444 |
-- Set a default value for rotation if not supplied |
| 1445 |
permutation = permutation or 0 |
| 1446 |
permutation = permutation + 1 |
| 1447 |
local vertices = { self.pa, self.pb, self.pc } |
| 1448 |
local i = (permutation - 1) % 3 + 1 |
| 1449 |
local j = i % 3 + 1 |
| 1450 |
local k = j % 3 + 1 |
| 1451 |
local a = vertices[i] |
| 1452 |
local b = vertices[j] |
| 1453 |
local c = vertices[k] |
| 1454 |
return square:new(square_inscribed_(a, b, c)) |
| 1455 |
end |
| 1456 |
------------------- |
| 1457 |
-- Result -> conic |
| 1458 |
------------------- |
| 1459 |
function triangle:steiner_inellipse() |
| 1460 |
return steiner_(self.pa, self.pb, self.pc) |
| 1461 |
end |
| 1462 |
|
| 1463 |
function triangle:steiner_circumellipse() |
| 1464 |
local e = steiner_(self.pa, self.pb, self.pc) |
| 1465 |
local v = report_(e.center, e.vertex, e.a, e.vertex) |
| 1466 |
local cv = report_(e.center, e.covertex, e.b, e.covertex) |
| 1467 |
return conic:new(EL_points(e.center, v, cv)) |
| 1468 |
end |
| 1469 |
|
| 1470 |
function triangle:euler_ellipse() |
| 1471 |
if self:check_acutangle() then |
| 1472 |
local x, y = intersection_lc_(self.orthocenter, self.circumcenter, self.eulercenter, self.ab.mid) |
| 1473 |
local a = 0.5 * length_(x, y) |
| 1474 |
return conic:new(EL_bifocal(self.orthocenter, self.circumcenter, a)) |
| 1475 |
end |
| 1476 |
end |
| 1477 |
|
| 1478 |
-- kiepert hyperbola |
| 1479 |
function triangle:kiepert_hyperbola() |
| 1480 |
-- center |
| 1481 |
local center = self:kimberling(115) |
| 1482 |
local O = self.circumcenter |
| 1483 |
local G = self.centroid |
| 1484 |
-- Brocard axis |
| 1485 |
local L = self:brocard_axis() |
| 1486 |
local M, N = intersection_lc_(L.pa, L.pb, O, self.pa) |
| 1487 |
-- simson lines |
| 1488 |
local Lsa = self:simson_line(M) |
| 1489 |
local Lsb = self:simson_line(N) |
| 1490 |
local axis = tkz.bisector(center, Lsa.pa, Lsb.pa) |
| 1491 |
-- new frame system |
| 1492 |
local minor = axis:ortho_from(center) |
| 1493 |
local sys = occs:new(minor, center) |
| 1494 |
local x, y = sys:coordinates(self.pa) |
| 1495 |
local a = math.sqrt(x ^ 2 - y ^ 2) |
| 1496 |
local c = math.sqrt(2) * a |
| 1497 |
local Fa = report_(center, axis.pb, -c, center) |
| 1498 |
local Fb = report_(center, axis.pb, c, center) |
| 1499 |
local K = report_(center, axis.pb, -a ^ 2 / c, center) |
| 1500 |
local directrix = axis:ortho_from(K) |
| 1501 |
return conic:new(Fa, directrix, math.sqrt(2)) |
| 1502 |
end |
| 1503 |
|
| 1504 |
-- kiepert parabola |
| 1505 |
function triangle:kiepert_parabola() |
| 1506 |
if (self.a == self.b) or (self.a == self.c) or (self.c == self.b) then |
| 1507 |
tex.error("An error has occurred", { "No X(110)" }) |
| 1508 |
else |
| 1509 |
L = self:euler_line() |
| 1510 |
F = self:kimberling(110) |
| 1511 |
return conic:new(F, L, 1) |
| 1512 |
end |
| 1513 |
end |
| 1514 |
|
| 1515 |
--lemoine inellipse |
| 1516 |
-- bifocal a besoin des deux foyers et d'un point sur l'ellipse ou bien de a |
| 1517 |
function triangle:lemoine_inellipse() |
| 1518 |
local G = self.centroid |
| 1519 |
local L = self:lemoine_point() |
| 1520 |
local Xa = self:lemoine().pa |
| 1521 |
return conic:new(EL_bifocal(G, L, Xa)) |
| 1522 |
end |
| 1523 |
|
| 1524 |
--brocard inellipse |
| 1525 |
function triangle:brocard_inellipse() |
| 1526 |
local B1 = self:first_brocard_point() |
| 1527 |
local B2 = self:second_brocard_point() |
| 1528 |
local Ka = self:symmedian().pa |
| 1529 |
return conic:new(EL_bifocal(B2, B1, Ka)) |
| 1530 |
end |
| 1531 |
|
| 1532 |
-- orthic inellipse |
| 1533 |
function triangle:macbeath_inellipse() |
| 1534 |
if self:check_acutangle() then |
| 1535 |
local O = self.circumcenter |
| 1536 |
local H = self.orthocenter |
| 1537 |
local Xa = self:macbeath().pa |
| 1538 |
return conic:new(EL_bifocal(O, H, Xa)) |
| 1539 |
else |
| 1540 |
tex.error("This function is only valid if none of the angles is obtuse.") |
| 1541 |
end |
| 1542 |
end |
| 1543 |
|
| 1544 |
function triangle:mandart_inellipse() |
| 1545 |
local T = self |
| 1546 |
local M = T:mittenpunkt_point() |
| 1547 |
local Xa, Yb, Zc = T:extouch():get() |
| 1548 |
local X, Y = M:symmetry(Xa, Yb) |
| 1549 |
local coefficients = search_ellipse_(X, Y, Xa, Yb, Zc) |
| 1550 |
local center, ra, rb, angle = ellipse_axes_angle(coefficients) |
| 1551 |
return conic:new(EL_radii(center, ra, rb, angle)) |
| 1552 |
end |
| 1553 |
|
| 1554 |
function triangle:orthic_inellipse() |
| 1555 |
if self:check_acutangle() then |
| 1556 |
local T = self |
| 1557 |
local K = T:symmedian_point() |
| 1558 |
local Ha, Hb, Hc = T:orthic():get() |
| 1559 |
local Sa, Sb = K:symmetry(Ha, Hb) |
| 1560 |
local coefficients = search_ellipse_(Ha, Hb, Hc, Sa, Sb) |
| 1561 |
local center, ra, rb, angle = ellipse_axes_angle(coefficients) |
| 1562 |
return conic:new(EL_radii(center, ra, rb, angle)) |
| 1563 |
else |
| 1564 |
tex.error("This function is only valid if none of the angles is obtuse.") |
| 1565 |
end |
| 1566 |
end |
| 1567 |
|
| 1568 |
function triangle:path(p1, p2) |
| 1569 |
local list = {} |
| 1570 |
|
| 1571 |
-- Liste des côtés et sommets |
| 1572 |
local sides = { |
| 1573 |
{ seg = self.ab, A = self.pa, B = self.pb }, |
| 1574 |
{ seg = self.bc, A = self.pb, B = self.pc }, |
| 1575 |
{ seg = self.ca, A = self.pc, B = self.pa }, |
| 1576 |
} |
| 1577 |
|
| 1578 |
-- Trouver les indices des segments contenant p1 et p2 |
| 1579 |
local function locate(p) |
| 1580 |
for i, s in ipairs(sides) do |
| 1581 |
if s.seg:on_segment(p) then |
| 1582 |
return i |
| 1583 |
end |
| 1584 |
end |
| 1585 |
tex.error("Point not on triangle boundary.") |
| 1586 |
end |
| 1587 |
|
| 1588 |
local i1 = locate(p1) |
| 1589 |
local i2 = locate(p2) |
| 1590 |
|
| 1591 |
-- Cas simple : même segment |
| 1592 |
if i1 == i2 then |
| 1593 |
table.insert(list, "(" .. checknumber_(p1.re) .. "," .. checknumber_(p1.im) .. ")") |
| 1594 |
table.insert(list, "(" .. checknumber_(p2.re) .. "," .. checknumber_(p2.im) .. ")") |
| 1595 |
return path:new(list) |
| 1596 |
end |
| 1597 |
|
| 1598 |
-- Sinon, commencer par p1 |
| 1599 |
table.insert(list, "(" .. checknumber_(p1.re) .. "," .. checknumber_(p1.im) .. ")") |
| 1600 |
|
| 1601 |
-- Parcourir les sommets intermédiaires dans l’ordre trigonométrique |
| 1602 |
local i = i1 |
| 1603 |
repeat |
| 1604 |
local s = sides[i] |
| 1605 |
table.insert(list, "(" .. checknumber_(s.B.re) .. "," .. checknumber_(s.B.im) .. ")") |
| 1606 |
i = i % 3 + 1 |
| 1607 |
until i == i2 |
| 1608 |
|
| 1609 |
-- Terminer par p2 |
| 1610 |
table.insert(list, "(" .. checknumber_(p2.re) .. "," .. checknumber_(p2.im) .. ")") |
| 1611 |
|
| 1612 |
return path:new(list) |
| 1613 |
end |
| 1614 |
|
| 1615 |
--- CONTACT PROBLEM APOLLONIUS |
| 1616 |
|
| 1617 |
-- Circle tangent to the three lines of the triangle: |
| 1618 |
-- returns (in this order): incircle, excircle at pa, excircle at pb, excircle at pc. |
| 1619 |
-- Optionnel: which ∈ { nil/"all", "in", "pa", "pb", "pc", "ex_a", "ex_b", "ex_c" } |
| 1620 |
function triangle:LLL(which) |
| 1621 |
which = which or "all" |
| 1622 |
-- --- sélecteur |
| 1623 |
local C_in = self:in_circle() |
| 1624 |
local C_ea = self:ex_circle(0) -- pa |
| 1625 |
local C_eb = self:ex_circle(1) -- pb |
| 1626 |
local C_ec = self:ex_circle(2) -- pc |
| 1627 |
if which == "all" or which == nil then |
| 1628 |
return C_in, C_ea, C_eb, C_ec |
| 1629 |
end |
| 1630 |
|
| 1631 |
-- alias pratiques |
| 1632 |
if which == "in" then return C_in end |
| 1633 |
if which == "pa" or which == "ex_a" then return C_ea end |
| 1634 |
if which == "pb" or which == "ex_b" then return C_eb end |
| 1635 |
if which == "pc" or which == "ex_c" then return C_ec end |
| 1636 |
|
| 1637 |
tex.error("Unknown selector for triangle:c_lll: "..tostring(which)) |
| 1638 |
|
| 1639 |
end |
| 1640 |
triangle.c_lll = triangle.LLL |
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
-- code for an inellipse in a triangle |
| 1645 |
local function side_of_point_(pa, pb, pc, pt, eps) |
| 1646 |
eps = eps or tkz.epsilon |
| 1647 |
|
| 1648 |
if line_on_(pa, pb, pt, eps) then return "ab" end |
| 1649 |
if line_on_(pb, pc, pt, eps) then return "bc" end |
| 1650 |
if line_on_(pc, pa, pt, eps) then return "ca" end |
| 1651 |
|
| 1652 |
return nil |
| 1653 |
end |
| 1654 |
|
| 1655 |
function triangle:cevian_point(p, q, eps) |
| 1656 |
eps = eps or tkz.epsilon |
| 1657 |
|
| 1658 |
local sp = side_of_point_(self.pa, self.pb, self.pc, p, eps) |
| 1659 |
local sq = side_of_point_(self.pa, self.pb, self.pc, q, eps) |
| 1660 |
|
| 1661 |
if not sp or not sq or sp == sq then |
| 1662 |
tex.error("cevian_point: points must lie on two distinct sides of the triangle.") |
| 1663 |
return nil |
| 1664 |
end |
| 1665 |
|
| 1666 |
local br |
| 1667 |
if (sp == "ab" and sq == "ca") or (sp == "ca" and sq == "ab") then |
| 1668 |
br = intersection(line(self.pc, p), line(self.pb, q)) |
| 1669 |
elseif (sp == "ab" and sq == "bc") or (sp == "bc" and sq == "ab") then |
| 1670 |
br = intersection(line(self.pc, p), line(self.pa, q)) |
| 1671 |
else |
| 1672 |
br = intersection(line(self.pb, p), line(self.pa, q)) |
| 1673 |
end |
| 1674 |
|
| 1675 |
if br == nil then |
| 1676 |
tex.error("cevian_point: unable to construct the cevian point.") |
| 1677 |
return nil |
| 1678 |
end |
| 1679 |
|
| 1680 |
local x, y, z = cevian_(self.pa, self.pb, self.pc, br) |
| 1681 |
return br, x, y, z |
| 1682 |
end |
| 1683 |
|
| 1684 |
|
| 1685 |
local function ellipse_from_brianchon_(T, br, eps) |
| 1686 |
eps = eps or tkz.epsilon |
| 1687 |
|
| 1688 |
if br == nil then |
| 1689 |
tex.error("ellipse_inscribed: Brianchon's point is required.") |
| 1690 |
return nil |
| 1691 |
end |
| 1692 |
|
| 1693 |
local a, b, c = cevian_(T.pa, T.pb, T.pc, br) |
| 1694 |
local k = T:isotomic(br) |
| 1695 |
local o = T:complement(k) |
| 1696 |
local u, v = o:symmetry(a, b) |
| 1697 |
|
| 1698 |
return conic:new(EL_five_points(a, b, c, u, v)) |
| 1699 |
end |
| 1700 |
|
| 1701 |
|
| 1702 |
function triangle:ellipse_inscribed(spec, eps) |
| 1703 |
eps = eps or tkz.epsilon |
| 1704 |
|
| 1705 |
if type(spec) ~= "table" then |
| 1706 |
tex.error("ellipse_inscribed: a specification table is expected.") |
| 1707 |
return nil |
| 1708 |
end |
| 1709 |
|
| 1710 |
if spec.brianchon ~= nil then |
| 1711 |
return ellipse_from_brianchon_(self, spec.brianchon, eps) |
| 1712 |
end |
| 1713 |
|
| 1714 |
if spec.center ~= nil then |
| 1715 |
local o = spec.center |
| 1716 |
local k = self:anticomplement(o) |
| 1717 |
local br = self:isotomic(k) |
| 1718 |
return ellipse_from_brianchon_(self, br, eps) |
| 1719 |
end |
| 1720 |
|
| 1721 |
if spec.focus ~= nil then |
| 1722 |
local f1 = spec.focus |
| 1723 |
local f2 = self:isogonal(f1) |
| 1724 |
local o = midpoint_(f1, f2) |
| 1725 |
local k = self:anticomplement(o) |
| 1726 |
local br = self:isotomic(k) |
| 1727 |
return ellipse_from_brianchon_(self, br, eps) |
| 1728 |
end |
| 1729 |
|
| 1730 |
tex.error("ellipse_inscribed: expected brianchon, center, or focus.") |
| 1731 |
return nil |
| 1732 |
end |
| 1733 |
|
| 1734 |
|
| 1735 |
return triangle |