summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_line.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_line.lua')
-rw-r--r--Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_line.lua578
1 files changed, 380 insertions, 198 deletions
diff --git a/Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_line.lua b/Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_line.lua
index 4d24d9d229c..2b4b320e19a 100644
--- a/Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_line.lua
+++ b/Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_line.lua
@@ -1,6 +1,6 @@
-- tkz_elements_lines.lua
--- date 2024/07/16
--- version 3.00
+-- date 2025/01/06
+-- version 3.10
-- Copyright 2024 Alain Matthes
-- This work may be distributed and/or modified under the
-- conditions of the LaTeX Project Public License, either version 1.3
@@ -16,7 +16,7 @@
-- Lines
-- -------------------------------------------------------------------------
line = {}
-function line: new(za, zb)
+function line:new(za, zb)
local type = 'line'
local mid = (za+zb)/2
local north_pa = rotation_ (za,math.pi/2,zb)
@@ -49,122 +49,119 @@ end
-------------------
-- Result -> real
-------------------
-function line: distance (pt)
+function line:distance(pt)
return point.mod(projection(self,pt)-pt)
end
-function length(a,b)
- return point.abs (a-b)
-end
-
-function line: slope ()
+function line:slope()
return slope_(self.pa,self.pb)
end
-------------------
-- Result -> boolean
-------------------
-function line: in_out (pt)
- local sc
- sc = math.abs ((pt-self.pa)^(pt-self.pb))
- if sc <= tkz_epsilon
- then
- return true
- else
- return false
- end
+function line:in_out(pt)
+ return math.abs((pt - self.pa) ^ (pt - self.pb)) <= tkz_epsilon
end
-function line: in_out_segment (pt)
- local sc
- sc = point.mod (pt-self.pa) + point.mod (pt-self.pb) - point.mod(self.pb-self.pa)
- if sc <= tkz_epsilon
- then
- return true
- else
- return false
- end
+function line:in_out_segment(pt)
+ return point.mod(pt - self.pa) + point.mod(pt - self.pb) - point.mod(self.pb - self.pa) <= tkz_epsilon
+end
+
+function line:is_parallel(L)
+ return math.abs(self.slope - L.slope) < tkz_epsilon
+end
+
+function line:is_orthogonal(L)
+ return math.abs(self.slope * L.slope + 1) < tkz_epsilon
+end
+
+function line:is_equidistant(p)
+ return math.abs( (point.mod(self.pa-p)-(point.mod(self.pb-p)))) < tkz_epsilon
end
-------------------
-- Result -> point
-------------------
-function line: barycenter (ka,kb)
+function line:barycenter(ka,kb)
return barycenter_({self.pa,ka},{self.pb,kb})
end
-function line: point (t) -- t=o A t=1 B t = AM / AB
+function line:point(t) -- t=o A t=1 B t = AM / AB
return barycenter_({self.pa,1-t},{self.pb,(t)})
end
-function line: midpoint ()
+function line:midpoint()
return (self.pa+self.pb)/2
end
-function line: harmonic_int (pt)
+function line:harmonic_int(pt)
return div_harmonic_int_(self.pa,self.pb,pt)
end
-function line: harmonic_ext (pt)
+function line:harmonic_ext(pt)
return div_harmonic_ext_(self.pa,self.pb,pt)
end
-function line: harmonic_both (k)
+function line:harmonic_both(k)
return div_harmonic_both_(self.pa,self.pb,k)
end
-function line: gold_ratio()
+function line:gold_ratio()
return self.pa + (self.pb-self.pa)*tkzinvphi
end
-function line: normalize ()
+function line:normalize()
return self.pa+(self.pb-self.pa)/point.mod(self.pb-self.pa)
end
-function line: normalize_inv ()
+function line:normalize_inv()
return normalize_ (self.pb,self.pa)
end
-function line: _east (d)
+function line:_east(d)
local d = d or 1
return self.pb+ d/self.length * (self.pb-self.pa)
end
-function line: _west (d)
+function line:_west(d)
local d = d or 1
return self.pa+ d/self.length * (self.pa-self.pb)
end
-function line: _north_pa (d)
+function line:_north_pa(d)
local d = d or 1
return d/self.length * ( self.north_pa - self.pa ) + self.pa
end
-function line: _south_pa (d)
+function line:_south_pa(d)
local d = d or 1
return d/self.length *( self.south_pa - self.pa ) + self.pa
end
-function line: _south_pb (d)
+function line:_south_pb(d)
local d = d or 1
return d/self.length *( self.south_pb - self.pb ) + self.pb
end
-function line: _north_pb (d)
+function line:_north_pb(d)
local d = d or 1
return d/self.length *( self.north_pb - self.pb ) + self.pb
end
-function line : report (d,pt)
- local t
- t = d/self.length
- if pt == nil
- then
- return barycenter_({self.pa,1-t},{self.pb,(t)})
- else
- return barycenter_({self.pa,1-t},{self.pb,(t)}) +pt-self.pa
- end
+function line:report(d, pt)
+ if not self.length or self.length == 0 then
+ error("self.length must be non-zero")
+ end
+ local t = d / self.length
+ local result = barycenter_({self.pa, 1 - t}, {self.pb, t})
+ if pt then
+ return result + pt - self.pa
+ else
+ return result
+ end
end
-function line : colinear_at (pt,k)
+
+function line:colinear_at (pt,k)
if k == nil
then
return colinear_at_ (self.pa,self.pb,pt,1)
@@ -173,28 +170,28 @@ function line : colinear_at (pt,k)
end
end
-------------- transformations -------------
-function line: translation_pt ( pt )
+function line:translation_pt( pt )
return translation_ ( self.pb-self.pa,pt )
end
-function line: translation_C ( obj )
+function line:translation_C( obj )
local pa,pb,x,y
pa = obj.center
pb = obj.through
- x,y = set_translation_ ( self.pb-self.pa,pa,pb )
+ x,y = set_translation_( self.pb-self.pa,pa,pb )
return circle : new (x,y)
end
-function line: translation_T ( obj )
+function line: translation_T( obj )
local pa,pb,pc,x,y,z
pa = obj.pa
pb = obj.pb
pc = obj.pc
- x,y,z = set_translation_ ( self.pb-self.pa,pa,pb,pc )
+ x,y,z = set_translation_( self.pb-self.pa,pa,pb,pc )
return triangle : new (x,y,z)
end
-function line: translation_L ( obj )
+function line: translation_L( obj )
local pa,pb,x,y
pa = obj.pa
pb = obj.pb
@@ -202,35 +199,42 @@ function line: translation_L ( obj )
return line : new (x,y)
end
-function line: translation (...)
- local obj,nb,t
+function line:translation(...)
+ local obj, nb, t
local tp = table.pack(...)
obj = tp[1]
nb = tp.n
- if nb == 1 then
- if obj.type == "point" then
- return translation_ ( self.pb-self.pa,obj )
- elseif obj.type == "line" then
- return self: translation_L (obj)
- elseif obj.type == "triangle" then
- return self: translation_T (obj)
- else
- return self: translation_C (obj)
- end
- else
+
+ -- If only one object is passed
+ if nb == 1 then
+ if obj.type == "point" then
+ return translation_(self.pb - self.pa, obj) -- Translate point
+ elseif obj.type == "line" then
+ return self:translation_L(obj) -- Translate line
+ elseif obj.type == "triangle" then
+ return self:translation_T(obj) -- Translate triangle
+ elseif obj.type == "circle" then
+ return self:translation_C(obj) -- Translate circle
+ else
+ error("Unsupported object type for translation")
+ end
+ else
+ -- If multiple objects are passed, translate each one
t = {}
- for i=1,tp.n do
- table.insert(t , translation_ ( self.pb-self.pa , tp[i]))
- end
- return table.unpack ( t )
- end
+ for i = 1, nb do
+ -- Translate each object using the translation vector
+ table.insert(t, translation_(self.pb - self.pa, tp[i]))
+ end
+ return table.unpack(t) -- Return the translated objects
+ end
end
+
function line: set_translation ( ...)
return set_translation_ ( self.pb-self.pa,... )
end
-function line: projection (...)
+function line:projection(...)
local obj,nb,t
local tp = table.pack(...)
obj = tp[1]
@@ -246,7 +250,7 @@ function line: projection (...)
end
end
-function line: set_projection (...)
+function line:set_projection(...)
local tp = table.pack(...)
local i
local t = {}
@@ -256,31 +260,31 @@ function line: set_projection (...)
return table.unpack ( t )
end
-function line: symmetry_axial_L ( obj )
+function line:symmetry_axial_L( obj )
local pa,pb,x,y
pa = obj.pa
pb = obj.pb
- x,y = self:set_reflection ( pa,pb )
+ x,y = self:set_reflection(pa, pb)
return line : new (x,y)
end
-function line: symmetry_axial_T ( obj )
+function line:symmetry_axial_T( obj )
local pa,pb,pc,x,y,z
pa = obj.pa
pb = obj.pb
pc = obj.pc
- x,y,z = self:set_reflection ( pa,pb,pc )
+ x,y,z = self:set_reflection (pa, pb, pc)
return triangle : new (x,y,z)
end
-function line: symmetry_axial_C ( obj )
+function line:symmetry_axial_C( obj )
local pa,pb,x,y
pa = obj.center
pb = obj.through
- x,y = self:set_reflection ( pa,pb )
+ x,y = self:set_reflection( pa,pb )
return circle : new (x,y)
end
-function line: reflection (...)
+function line:reflection(...)
local obj,nb,t
local tp = table.pack(...)
obj = tp[1]
@@ -304,203 +308,379 @@ function line: reflection (...)
end
end
-function line: set_reflection (...)
+function line:set_reflection (...)
return set_symmetry_axial_ ( self.pb,self.pa,... )
end
-------------------
-- Result -> line
-------------------
-function line: ll_from ( pt )
+function line:ll_from( pt )
return line : new (pt,pt+self.pb-self.pa)
end
-function line: ortho_from ( pt )
+function line:ortho_from( pt )
return line : new (pt+(self.pb-self.pa)*point(0,-1),pt+(self.pb-self.pa)*point(0,1))
end
-function line: mediator ()
- local m
- m = midpoint_ (self.pa,self.pb)
+function line:mediator()
+ local m = midpoint_ (self.pa,self.pb)
return line : new (rotation_ (m,-math.pi/2,self.pb),rotation_ (m,math.pi/2,self.pb))
end
-function line : perpendicular_bisector ()
- local m
- m = midpoint_ (self.pa,self.pb)
+function line:perpendicular_bisector ()
+ local m = midpoint_ (self.pa,self.pb)
return line : new (rotation_ (m,-math.pi/2,self.pb),rotation_ (m,math.pi/2,self.pb))
end
-------------------
-- Result -> circle
-------------------
-function line: circle (swap)
- if swap == nil then
- swap = false
- end
+function line:circle(swap)
+ swap = swap or false
if swap then
- return circle : new (self.pb,self.pa)
+ return circle:new(self.pb,self.pa)
else
- return circle : new (self.pa,self.pb)
+ return circle:new(self.pa,self.pb)
end
end
-function line: circle_swap ()
+function line:circle_swap()
return circle : new (self.pb,self.pa)
end
-function line : diameter ()
- local c = midpoint_ (self.pa,self.pb)
- return circle : new (c,self.pb)
+function line:diameter()
+ local c = midpoint_(self.pa,self.pb)
+ return circle:new (c,self.pb)
end
-function line : apollonius (k)
+function line:apollonius(k)
local z1,z2,c
- z1 = barycenter_ ({self.pa,1},{self.pb,k})
- z2 = barycenter_ ({self.pa,1},{self.pb,-k})
- c = midpoint_ (z1,z2)
+ z1 = barycenter_({self.pa,1},{self.pb,k})
+ z2 = barycenter_({self.pa,1},{self.pb,-k})
+ c = midpoint_ (z1,z2)
return circle : new (c,z2)
end
+function line:test(x,y)
+
+end
+
+
+-- Circle tangent to a line passing through two points
+-- In general, there are two solutions
+function line:c_l_pp(a, b) -- a and b on the same side
+ -- Initialisation
+ local lab = line:new(a, b) -- Line through a and b
+ local Cab = circle:diameter(a, b) -- Circle with a and b diameters
+ local i = intersection(lab, self) -- Intersection with current line
+
+ -- One point on the line (a)
+ if self : in_out(a) and not self:in_out(b) then
+ local lmed = lab : mediator()
+ local laperp = self:ortho_from(a)
+ local o = intersection(lmed,laperp)
+ return circle:new(o,a),
+ circle:new(o,a)
+ end
+ -- One point on the line (b)
+ if self:in_out(b) and not self:in_out(a) then
+ local lmed = lab:mediator()
+ local laperp = self:ortho_from(b)
+ local o = intersection(lmed,laperp)
+ return circle:new(o,b),
+ circle:new(o,b)
+ end
+ -- Check: if the intersection exists and lies on the segment [a, b].
+ if i and lab:in_out_segment(i) then
+ return nil, nil -- No circle is possible
+ end
+
+ -- If the current line is orthogonal to lab
+ if self:is_orthogonal(lab) then
+ local lmed = lab:mediator()
+ local m = midpoint(a, b)
+ local r = length(m, i)
+ local pt1 = lab:isosceles_s(r)
+ local pt2 = lab:isosceles_s(r, true)
+ return circle:new(pt1, a),
+ circle:new(pt2, a)
+ end
+
+ -- If the two lines are parallel
+ if lab:is_parallel(self) then
+ local mid = midpoint(a, b) -- Midpoint of segment [a, b]
+ local proj = self:projection(mid) -- Mid projection on the running line
+
+ return circle:new(circum_center_(a, b, proj), proj),
+ circle:new(circum_center_(a, b, proj), proj)
+ end
+
+ -- General case
+ local t = Cab:tangent_from(i).pb
+ local x, y = intersection(self, circle:new(i, t))
+ return circle:new(intersection(self:ortho_from(x), lab:mediator()), x),
+ circle:new(intersection(self:ortho_from(y), lab:mediator()), y)
+end
+
+
+-- Circle tangent to two straight lines passing through a given point
+function line:c_ll_p(a, p)
+
+ -- Compute the bisector of the triangle formed by self.pa, self.pb, and a
+ local lbi = bisector(self.pa, self.pb, a)
+
+ if lbi:in_out(p) then
+ -- Orthogonal projection of p onto the bisector
+ local lp = lbi:ortho_from(p)
+
+ -- Intersection of line from p to its projection with self.pa and self.pb
+ local i = intersection_ll_(p, lp.pb, self.pa, self.pb)
+
+ -- Intersection points of the line with the circle defined by (i, p)
+ local t1, t2 = intersection_lc_(self.pa, self.pb, i, p)
+
+ -- Create the main line and find orthogonal projections from t1 and t2
+ local lab = line:new(self.pa, self.pb)
+ local x = lab:ortho_from(t1).pb
+ local y = lab:ortho_from(t2).pb
+
+ -- Return two circles based on the orthogonal projections and points t1, t2
+ return circle:new(intersection_ll_(x, t1, self.pa, p), t1),
+ circle:new(intersection_ll_(y, t2, self.pa, p), t2)
+ else
+ -- Reflection of p across the bisector
+ local q = lbi : reflection (p)
+
+ -- Compute circles from the Wallis construction
+ local c1, c2 = self:c_l_pp(p, q)
+
+ -- Return two circles with centers and points on their circumference
+ return c1,c2
+ end
+end
+
+
+
----------------------
-- Result -> triangle
----------------------
-function line: equilateral (swap)
- if swap == nil then
- swap = false
- end
- if swap then
- return triangle : new (self.pa,self.pb,rotation_ (self.pa,-math.pi/3,self.pb))
+function line:equilateral(swap)
+ swap = swap or false
+ if swap then
+ return triangle:new(self.pa, self.pb, rotation_(self.pa, -math.pi / 3, self.pb))
else
- return triangle : new (self.pa,self.pb,rotation_ (self.pa,math.pi/3,self.pb))
-end
+ return triangle:new(self.pa, self.pb, rotation_(self.pa, math.pi / 3, self.pb))
+ end
end
-function line: isosceles (phi,swap)
- local pta,ptb
- if swap == nil then
- swap = false
- end
+function line:isosceles(phi,swap)
+ local pta,ptb
+ swap = swap or false
if swap then
- pta = rotation_ (self.pa,-phi,self.pb)
- ptb = rotation_ (self.pb,phi,self.pa)
- return triangle : new (self.pa,self.pb, intersection_ll_ (self.pa,pta,self.pb,ptb ))
+ pta = rotation_(self.pa,-phi,self.pb)
+ ptb = rotation_(self.pb,phi,self.pa)
+ return triangle : new (self.pa,self.pb, intersection_ll_(self.pa,pta,self.pb,ptb ))
else
- pta = rotation_ (self.pa,phi,self.pb)
- ptb = rotation_ (self.pb,-phi,self.pa)
+ pta = rotation_(self.pa,phi,self.pb)
+ ptb = rotation_(self.pb,-phi,self.pa)
return triangle : new (self.pa,self.pb, intersection_ll_ (self.pa,pta,self.pb,ptb ))
end
end
+line.isosceles_a = line.isosceles
+
+function line:isosceles_s(a,swap)
+ local c1,c2,pta,ptb,pt1,pt2
+ c1 = circle : radius (self.pa,a)
+ c2 = circle : radius (self.pb,a)
+ pta,ptb = intersection_cc (c1,c2)
+ if get_angle(self.pa,self.pb,pta) < get_angle(self.pa,self.pb,ptb) then
+ pt1=pta pt2=ptb
+ else pt1=ptb pt2=pta end
+ swap = swap or false
+ if swap then
+ return triangle : new (self.pa,self.pb,pt2 )
+ else
+ return triangle : new (self.pa,self.pb,pt1)
+end
+end
-function line: two_angles (alpha,beta)
+function line:two_angles(alpha,beta,swap)
local pta,ptb,pt
- pta = rotation_ (self.pa,alpha,self.pb)
- ptb = rotation_ (self.pb,-beta,self.pa)
- pt = intersection_ll_ (self.pa,pta,self.pb,ptb)
- return triangle : new (self.pa,self.pb,pt)
+ swap = swap or false
+ if swap then
+ pta = rotation_(self.pa,-alpha,self.pb)
+ ptb = rotation_(self.pb,beta,self.pa)
+ else
+ pta = rotation_(self.pa,alpha,self.pb)
+ ptb = rotation_(self.pb,-beta,self.pa)
+ end
+ pt = intersection_ll_(self.pa,pta,self.pb,ptb)
+ return triangle:new(self.pa,self.pb,pt)
end
-function line: school ()
+function line:school(swap)
local pta,ptb,pt
- pta = rotation_ (self.pa,math.pi/6,self.pb)
- ptb = rotation_ (self.pb,-math.pi/3,self.pa)
- pt = intersection_ll_ (self.pa,pta,self.pb,ptb)
- return triangle : new (self.pa,self.pb,pt)
+ swap = swap or false
+ if swap then
+ pta = rotation_(self.pa,-math.pi/6,self.pb)
+ ptb = rotation_(self.pb,math.pi/3,self.pa)
+ else
+ pta = rotation_(self.pa,math.pi/6,self.pb)
+ ptb = rotation_(self.pb,-math.pi/3,self.pa)
+ end
+ pt = intersection_ll_(self.pa,pta,self.pb,ptb)
+ return triangle:new(self.pa,self.pb,pt)
end
-function line: half ()
+function line:half(swap)
local x,pt
x = midpoint_(self.pa,self.pb)
- pt = rotation_ (self.pb,-math.pi/2,x)
- return triangle : new (self.pa,self.pb,pt)
+ swap = swap or false
+ if swap then
+ pt = rotation_(self.pb,math.pi/2,x)
+ else
+ pt = rotation_(self.pb,-math.pi/2,x)
+ end
+ return triangle:new(self.pa,self.pb,pt)
end
-function line: sss (a,b)
+function line:sss(a,b,swap)
local pta,ptb,i,j
+ swap = swap or false
pta = self.pa + point ( a, 0 )
ptb = self.pb + point ( -b , 0)
i,j = intersection_cc_ (self.pa,pta,self.pb,ptb)
- return triangle : new (self.pa,self.pb,i),triangle : new (self.pa,self.pb,j)
+ if swap then
+ return triangle : new (self.pa,self.pb,j)
+ else
+ return triangle : new (self.pa,self.pb,i)
+ end
end
-function line: ssa (a,phi)
- local x,y,pt
- x = rotation_ (self.pb,-phi,self.pa)
- y = self.pa + polar_ ( a , self.slope)
- i,j = intersection_lc_ (self.pb,x,self.pa,y)
- return triangle : new (self.pa,self.pb,i),triangle : new (self.pa,self.pb,j)
+function line:ssa(a, phi,swap)
+ local x, y, i, j
+ swap = swap or false
+ x = rotation_(self.pb, -phi, self.pa)
+ y = self.pa + polar_(a, self.slope)
+ i, j = intersection_lc_(self.pb, x, self.pa, y)
+ if swap then
+ return triangle:new(self.pa, self.pb, j)
+ else
+ return triangle:new(self.pa, self.pb, i)
+ end
end
-function line: sas (a,phi)
- local x,pt
- x = self.pa + polar_ ( a , self.slope)
- pt = rotation_ (self.pa,phi,x)
- return triangle : new (self.pa,self.pb,pt)
+function line:sas(a, phi,swap)
+ local x, pt
+ swap = swap or false
+ x = self.pa + polar_(a, self.slope)
+ if swap then
+ pt = rotation_(self.pa, -phi, x)
+ else
+ pt = rotation_(self.pa, phi, x)
+ end
+ return triangle:new(self.pa, self.pb, pt)
end
-function line: asa (alpha,beta)
+function line:asa(alpha,beta,swap)
local pta,ptb,pt
+ swap = swap or false
+ if swap then
+ pta = rotation_ (self.pa,-alpha,self.pb)
+ ptb = rotation_ (self.pb,beta,self.pa)
+ else
pta = rotation_ (self.pa,alpha,self.pb)
ptb = rotation_ (self.pb,-beta,self.pa)
- pt = intersection_ll_ (self.pa,pta,self.pb,ptb)
+ end
+ pt = intersection_ll_ (self.pa,pta,self.pb,ptb)
return triangle : new (self.pa,self.pb,pt)
end
---- sacred triangles ----
-function line: gold (swap)
+function line:gold(swap)
local pt
- if swap == nil then
- swap = false
- end
-if swap then
- pt = rotation_ (self.pa,-math.pi/2,self.pb)
- return triangle : new (self.pa,self.pb, self.pa + (pt-self.pa) * tkzinvphi)
-else
- pt = rotation_ (self.pa,math.pi/2,self.pb)
- return triangle : new (self.pa,self.pb, self.pa + (pt-self.pa) * tkzinvphi)
-end
+ swap = swap or false
+ if swap then
+ pt = rotation_ (self.pa,-math.pi/2,self.pb)
+ return triangle : new (self.pa,self.pb, self.pa + (pt-self.pa) * tkzinvphi)
+ else
+ pt = rotation_ (self.pa,math.pi/2,self.pb)
+ return triangle : new (self.pa,self.pb, self.pa + (pt-self.pa) * tkzinvphi)
+ end
end
-function line: sublime ()
+function line:sublime(swap)
local pta,ptb,pt
- pta = rotation_ (self.pa,2*math.pi/5,self.pb)
- ptb = rotation_ (self.pb,-2*math.pi/5,self.pa)
- pt = intersection_ll_ (self.pa,pta,self.pb,ptb)
- return triangle : new (self.pa,self.pb,pt)
+ swap = swap or false
+ if swap then
+ pta = rotation_(self.pa,-2*math.pi/5,self.pb)
+ ptb = rotation_(self.pb,2*math.pi/5,self.pa)
+ pt = intersection_ll_(self.pa,pta,self.pb,ptb)
+ return triangle:new(self.pa,self.pb,pt)
+ else
+ pta = rotation_(self.pa,2*math.pi/5,self.pb)
+ ptb = rotation_(self.pb,-2*math.pi/5,self.pa)
+ pt = intersection_ll_(self.pa,pta,self.pb,ptb)
+ return triangle:new(self.pa,self.pb,pt)
+end
end
line.euclid = line.sublime
-function line: euclide (swap)
- if swap == nil then
- return triangle : new (self.pa,self.pb, rotation_ (self.pa,math.pi/5,self.pb))
- else
- return triangle : new (self.pa,self.pb, rotation_ (self.pa,-math.pi/5,self.pb))
- end
+function line:euclide (swap)
+ swap = swap or false
+ if swap then
+ return triangle : new (self.pa,self.pb, rotation_(self.pa,-math.pi/5,self.pb))
+ else
+ return triangle : new (self.pa,self.pb, rotation_(self.pa,math.pi/5,self.pb))
+ end
end
-function line: divine ()
- local pta,ptb,pt,h
- pta = rotation_ (self.pa,math.pi/5,self.pb)
- ptb = rotation_ (self.pb,-math.pi/5,self.pa)
- pt = intersection_ll_ (self.pa,pta,self.pb,ptb)
- return triangle : new (self.pa,self.pb,pt)
-end
+ function line:divine(swap)
+ local pta, ptb, pt
+ swap = swap or false
+ if swap then
+ pta = rotation_(self.pa, -math.pi / 5, self.pb)
+ ptb = rotation_(self.pb, math.pi / 5, self.pa)
+ pt = intersection_ll_(self.pa, pta, self.pb, ptb)
+ return triangle:new(self.pa, self.pb, pt)
+ else
+ pta = rotation_(self.pa, math.pi / 5, self.pb)
+ ptb = rotation_(self.pb, -math.pi / 5, self.pa)
+ pt = intersection_ll_(self.pa, pta, self.pb, ptb)
+ return triangle:new(self.pa, self.pb, pt)
+ end
+ end
-function line: cheops ()
- local m,n,pt
- m = midpoint_ (self.pa,self.pb)
- n = rotation_ (m,- math.pi/2,self.pa)
- pt = m + (n-m)* tkzsqrtphi
- return triangle : new (self.pa,self.pb,pt)
+function line:cheops(swap)
+ local m, n, pt
+ m = midpoint_(self.pa, self.pb)
+ swap = swap or false
+ if swap then
+ n = rotation_(m, math.pi / 2, self.pa)
+ pt = m + (n - m) * tkzsqrtphi
+else
+ n = rotation_(m, -math.pi / 2, self.pa)
+ pt = m + (n - m) * tkzsqrtphi
+ end
+ return triangle:new(self.pa, self.pb, pt)
end
-function line: egyptian ()
- local n,pt
- n = rotation_ (self.pb,- math.pi/2,self.pa)
- pt = self.pb + (n-self.pb)/point.mod(n-self.pb)*self.length* 0.75
- return triangle : new (self.pa,self.pb,pt)
+
+function line:egyptian(swap)
+ local n, pt
+ swap = swap or false
+ if swap then
+ n = rotation_(self.pb, math.pi / 2, self.pa)
+ pt = self.pb + (n - self.pb) / point.mod(n - self.pb) * self.length * 0.75
+ else
+ n = rotation_(self.pb, -math.pi / 2, self.pa)
+ pt = self.pb + (n - self.pb) / point.mod(n - self.pb) * self.length * 0.75
+ end
+ return triangle:new(self.pa, self.pb, pt)
end
+
line.pythagoras = line.egyptian
line.isis = line.egyptian
line.golden = line.sublime
@@ -509,12 +689,14 @@ line.golden_gnomon = line.divine
------------------------------
-- Result -> square
------------------------------
-function line: square (swap)
- if swap == nil
+function line:square (swap)
+ swap = swap or false
+ if swap
then
- return square : side (self.pa,self.pb)
- else
return square : side (self.pa,self.pb,indirect)
+ else
+ return square : side (self.pa,self.pb)
+
end
end