/usr/lib/ipe/7.1.10/ipelets/euclid.lua is in ipe 7.1.10-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | ----------------------------------------------------------------------
-- Euclid ipelet
----------------------------------------------------------------------
--[[
This file is part of the extensible drawing editor Ipe.
Copyright (C) 1993-2015 Otfried Cheong
Ipe is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
As a special exception, you have permission to link Ipe with the
CGAL library and distribute executables, as long as you follow the
requirements of the Gnu General Public License in regard to all of
the software in the executable aside from CGAL.
Ipe is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with Ipe; if not, you can find it at
"http://www.gnu.org/copyleft/gpl.html", or write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--]]
label = "Euclidean Geometry"
about = [[
Create the incircle or the three excircles of a triangle.
Original Ipe 6 version by Jari Lappalainen, this ipelet is now part of
Ipe.
]]
function incorrect(model)
model:warning("Primary selection is not a triangle")
end
function collect_vertices(model)
local p = model:page()
local prim = p:primarySelection()
if not prim then model.ui:explain("no selection") return end
local obj = p[prim]
if obj:type() ~= "path" then incorrect(model) return end
local shape = obj:shape()
if (#shape ~= 1 or shape[1].type ~= "curve" or #shape[1] ~= 2
or shape[1][1].type ~= "segment" or shape[1][2].type ~= "segment")
then
incorrect(model)
return
end
local m = obj:matrix()
local a = m * shape[1][1][1]
local b = m * shape[1][1][2]
local c = m * shape[1][2][2]
return a, b, c
end
function angle_bisector(origin, dir1, dir2)
assert(dir1:sqLen() > 0)
assert(dir2:sqLen() > 0)
local bisector = dir1:normalized() + dir2:normalized()
if bisector:sqLen() == 0 then bisector = dir1:orthogonal() end
return ipe.LineThrough(origin, origin + bisector)
end
function create_circle(model, center, radius)
local shape = { type="ellipse";
ipe.Matrix(radius, 0, 0, radius, center.x, center.y) }
return ipe.Path(model.attributes, { shape } )
end
function incircle(model, a, b, c)
local b1 = angle_bisector(a, b - a, c - a)
local b2 = angle_bisector(b, c - b, a - b)
local center = b1:intersects(b2)
if (center) then
local AB = ipe.LineThrough(a, b)
local radius = AB:distance(center)
return create_circle(model, center, radius)
end
end
function excircle(model, a, b, c)
local b1 = angle_bisector(a, b - a, c - a)
local b2 = angle_bisector(b, c - b, a - b)
local n1 = b1:normal()
local n2 = b2:normal()
local nl1 = ipe.LineThrough(a, a + n1)
local nl2 = ipe.LineThrough(b, b + n2)
local center = nl1:intersects(nl2)
if center then
local AB = ipe.LineThrough(a, b)
local radius = AB:distance(center)
return create_circle(model, center, radius)
end
end
function create_incircle(model)
local a, b, c = collect_vertices(model)
if not a then return end
local obj = incircle(model, a, b, c)
if obj then
model:creation("create incircle of triangle", obj)
end
end
function create_excircles(model)
local a, b, c = collect_vertices(model)
if not a then return end
local circles = {}
local obj = excircle(model, a, b, c)
if obj then circles[#circles + 1] = obj end
obj = excircle(model, b, c, a)
if obj then circles[#circles + 1] = obj end
obj = excircle(model, c, a, b)
if obj then circles[#circles + 1] = obj end
local group = ipe.Group(circles)
model:creation("create excircles of triangles", group)
end
methods = {
{ label="Incircle of triangle", run = create_incircle },
{ label="Excircles of triangle", run = create_excircles },
}
----------------------------------------------------------------------
|