diff options
author | Karl Berry <karl@freefriends.org> | 2025-02-24 20:29:57 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2025-02-24 20:29:57 +0000 |
commit | 7852aac264119b644d4ff44a30bbf58b78969673 (patch) | |
tree | f9c4688aadebebb5be041c646b8ac99742d11b15 /Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_vector.lua | |
parent | be430c4bb16fc977fd4c5f80f5218d27604809e2 (diff) |
tkz-elements (24feb25)
git-svn-id: svn://tug.org/texlive/trunk@74262 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_vector.lua')
-rw-r--r-- | Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_vector.lua | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_vector.lua b/Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_vector.lua index 7e9f0ff94fe..5fdebade8b8 100644 --- a/Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_vector.lua +++ b/Master/texmf-dist/tex/latex/tkz-elements/tkz_elements_vector.lua @@ -1,6 +1,6 @@ -- tkz_elements_vectors.lua --- date 2025/01/06 --- version 3.10 +-- date 2025/02/14 +-- version 3.30 -- 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 @@ -14,20 +14,21 @@ -- ---------------------------------------------------------------------------- vector = {} -function vector: new(za, zb) +-- Constructor for creating a new vector +function vector:new(za, zb) local type = 'vector' local slope = angle_normalize_(point.arg(zb-za)) local norm = point.mod(zb-za) - local mtx = matrix : new {{za},{zb}} - local o = {tail = za, + local mtx = matrix:new { { za }, { zb } } + local vect = {tail = za, head = zb, norm = norm, mtx = mtx, slope = slope, type = type } - setmetatable(o, self) + setmetatable(vect, self) self.__index = self - return o + return vect end function vector.__add(v1,v2) @@ -35,48 +36,45 @@ function vector.__add(v1,v2) end function vector.__sub(v1,v2) - local v = v2 : scale(-1) - return v1 : add (v) + return v1:add(v2:scale(-1)) end function vector.__unm(v) - return v : scale(-1) + return v:scale(-1) end function vector.__mul(r,v) return v : scale(r) end - +-- Normalize the vector (unit vector) function vector: normalize () local z = self.head-self.tail local d = point.abs(z) - local nz = point(z.re/d,z.im/d) - return vector : new (self.tail,nz + self.tail) + local nz = point(z.re / d, z.im / d) + return vector:new(self.tail, nz + self.tail) end function vector: add (ve) return vector :new (self.tail,self.head+ve.head-ve.tail) end - -function vector: orthogonal (d) -local z +-- Create an orthogonal vector +function vector:orthogonal (d) if d == nil then return vector : new (self.tail, rotation_(self.tail,math.pi/2,self.head)) else - z = self.tail+ point (d*math.cos(self.slope),d*math.sin(self.slope)) + local z = self.tail+ point (d*math.cos(self.slope),d*math.sin(self.slope)) return vector : new (self.tail, rotation_(self.tail,math.pi/2,z)) end end -function vector: scale (d) - local l,z - l = self.norm - z = self.tail+ point (d*l*math.cos(self.slope),d*l*math.sin(self.slope)) - return vector : new (self.tail,z ) +-- Scale the vector by a scalar +function vector:scale(d) + local z = self.tail + point(d * self.norm * math.cos(self.slope), d * self.norm * math.sin(self.slope)) + return vector:new(self.tail, z) end -function vector: at (zc) - return vector :new (zc,zc+self.head-self.tail) +function vector:at (zc) + return vector:new(zc, zc + self.head - self.tail) end return vector |