| 1 |
-- File: tkz_elements_occs.lua |
| 2 |
-- Copyright (c) 2026 Alain Matthes |
| 3 |
-- SPDX-License-Identifier: LPPL-1.3c |
| 4 |
-- Maintainer: Alain Matthes |
| 5 |
|
| 6 |
occs = {} |
| 7 |
occs.__index = occs |
| 8 |
function occs:new(L, zO) |
| 9 |
local type = "occs" |
| 10 |
local origin = zO |
| 11 |
local y = report_(L.pa, L.pb, 1, zO) |
| 12 |
local x = rotation_(zO, -math.pi / 2, y) |
| 13 |
local abscissa = line:new(zO, x) |
| 14 |
local ordinate = line:new(zO, y) |
| 15 |
local o = { origin = origin, x = x, y = y, abscissa = abscissa, ordinate = ordinate, type = type } |
| 16 |
setmetatable(o, self) |
| 17 |
return o |
| 18 |
end |
| 19 |
|
| 20 |
setmetatable(occs, { |
| 21 |
__call = function(cls, ...) |
| 22 |
return cls:new(...) |
| 23 |
end, |
| 24 |
}) |
| 25 |
----------------------- |
| 26 |
function occs:coordinates(pt) |
| 27 |
local O = self.origin |
| 28 |
|
| 29 |
local dx = pt.re - O.re |
| 30 |
local dy = pt.im - O.im |
| 31 |
|
| 32 |
-- axes directeurs |
| 33 |
local ux = self.x - O |
| 34 |
local vx = self.y - O |
| 35 |
|
| 36 |
-- normes (évite division par 0) |
| 37 |
local nu = point.abs(ux) |
| 38 |
local nv = point.abs(vx) |
| 39 |
local eps = tkz.epsilon or 1e-9 |
| 40 |
|
| 41 |
if nu <= eps or nv <= eps then |
| 42 |
tex.error("Degenerate occs: axis length too small.") |
| 43 |
return |
| 44 |
end |
| 45 |
|
| 46 |
-- coordonnées projetées, corrigées par l'échelle des axes |
| 47 |
local u = (ux.re * dx + ux.im * dy) / nu |
| 48 |
local v = (vx.re * dx + vx.im * dy) / nv |
| 49 |
|
| 50 |
return u, v |
| 51 |
end |
| 52 |
|
| 53 |
|
| 54 |
return occs |