- totalement réécrit la fonction arctangente dans le module trigo pour nodeMCU
- réécrit aussi equa2azim, cela a l'air de bien fonctionner maintenant
This commit is contained in:
0
Trigo/Icon
Normal file
0
Trigo/Icon
Normal file
1
Trigo/Lua, tables de trigonométrie.gsheet
Normal file
1
Trigo/Lua, tables de trigonométrie.gsheet
Normal file
@@ -0,0 +1 @@
|
||||
{"url": "https://docs.google.com/open?id=1p7vD3c2epzUz_xE9CP6CEJbpspGn2hzpBLVqSr5hP1c", "doc_id": "1p7vD3c2epzUz_xE9CP6CEJbpspGn2hzpBLVqSr5hP1c", "email": "christian.zufferey@gmail.com"}
|
||||
102
Trigo/sincos.csv
Normal file
102
Trigo/sincos.csv
Normal file
@@ -0,0 +1,102 @@
|
||||
Angle [rad],Sinus,Cosinus
|
||||
0,0,1
|
||||
0.06283185307,0.06279051953,0.9980267284
|
||||
0.1256637061,0.1253332336,0.9921147013
|
||||
0.1884955592,0.1873813146,0.9822872507
|
||||
0.2513274123,0.2486898872,0.9685831611
|
||||
0.3141592654,0.3090169944,0.9510565163
|
||||
0.3769911184,0.3681245527,0.9297764859
|
||||
0.4398229715,0.4257792916,0.9048270525
|
||||
0.5026548246,0.4817536741,0.87630668
|
||||
0.5654866776,0.535826795,0.8443279255
|
||||
0.6283185307,0.5877852523,0.8090169944
|
||||
0.6911503838,0.6374239897,0.7705132428
|
||||
0.7539822369,0.6845471059,0.7289686274
|
||||
0.8168140899,0.7289686274,0.6845471059
|
||||
0.879645943,0.7705132428,0.6374239897
|
||||
0.9424777961,0.8090169944,0.5877852523
|
||||
1.005309649,0.8443279255,0.535826795
|
||||
1.068141502,0.87630668,0.4817536741
|
||||
1.130973355,0.9048270525,0.4257792916
|
||||
1.193805208,0.9297764859,0.3681245527
|
||||
1.256637061,0.9510565163,0.3090169944
|
||||
1.319468915,0.9685831611,0.2486898872
|
||||
1.382300768,0.9822872507,0.1873813146
|
||||
1.445132621,0.9921147013,0.1253332336
|
||||
1.507964474,0.9980267284,0.06279051953
|
||||
1.570796327,1,0
|
||||
1.63362818,0.9980267284,-0.06279051953
|
||||
1.696460033,0.9921147013,-0.1253332336
|
||||
1.759291886,0.9822872507,-0.1873813146
|
||||
1.822123739,0.9685831611,-0.2486898872
|
||||
1.884955592,0.9510565163,-0.3090169944
|
||||
1.947787445,0.9297764859,-0.3681245527
|
||||
2.010619298,0.9048270525,-0.4257792916
|
||||
2.073451151,0.87630668,-0.4817536741
|
||||
2.136283004,0.8443279255,-0.535826795
|
||||
2.199114858,0.8090169944,-0.5877852523
|
||||
2.261946711,0.7705132428,-0.6374239897
|
||||
2.324778564,0.7289686274,-0.6845471059
|
||||
2.387610417,0.6845471059,-0.7289686274
|
||||
2.45044227,0.6374239897,-0.7705132428
|
||||
2.513274123,0.5877852523,-0.8090169944
|
||||
2.576105976,0.535826795,-0.8443279255
|
||||
2.638937829,0.4817536741,-0.87630668
|
||||
2.701769682,0.4257792916,-0.9048270525
|
||||
2.764601535,0.3681245527,-0.9297764859
|
||||
2.827433388,0.3090169944,-0.9510565163
|
||||
2.890265241,0.2486898872,-0.9685831611
|
||||
2.953097094,0.1873813146,-0.9822872507
|
||||
3.015928947,0.1253332336,-0.9921147013
|
||||
3.078760801,0.06279051953,-0.9980267284
|
||||
3.141592654,0,-1
|
||||
3.204424507,-0.06279051953,-0.9980267284
|
||||
3.26725636,-0.1253332336,-0.9921147013
|
||||
3.330088213,-0.1873813146,-0.9822872507
|
||||
3.392920066,-0.2486898872,-0.9685831611
|
||||
3.455751919,-0.3090169944,-0.9510565163
|
||||
3.518583772,-0.3681245527,-0.9297764859
|
||||
3.581415625,-0.4257792916,-0.9048270525
|
||||
3.644247478,-0.4817536741,-0.87630668
|
||||
3.707079331,-0.535826795,-0.8443279255
|
||||
3.769911184,-0.5877852523,-0.8090169944
|
||||
3.832743037,-0.6374239897,-0.7705132428
|
||||
3.89557489,-0.6845471059,-0.7289686274
|
||||
3.958406744,-0.7289686274,-0.6845471059
|
||||
4.021238597,-0.7705132428,-0.6374239897
|
||||
4.08407045,-0.8090169944,-0.5877852523
|
||||
4.146902303,-0.8443279255,-0.535826795
|
||||
4.209734156,-0.87630668,-0.4817536741
|
||||
4.272566009,-0.9048270525,-0.4257792916
|
||||
4.335397862,-0.9297764859,-0.3681245527
|
||||
4.398229715,-0.9510565163,-0.3090169944
|
||||
4.461061568,-0.9685831611,-0.2486898872
|
||||
4.523893421,-0.9822872507,-0.1873813146
|
||||
4.586725274,-0.9921147013,-0.1253332336
|
||||
4.649557127,-0.9980267284,-0.06279051953
|
||||
4.71238898,-1,0
|
||||
4.775220833,-0.9980267284,0.06279051953
|
||||
4.838052687,-0.9921147013,0.1253332336
|
||||
4.90088454,-0.9822872507,0.1873813146
|
||||
4.963716393,-0.9685831611,0.2486898872
|
||||
5.026548246,-0.9510565163,0.3090169944
|
||||
5.089380099,-0.9297764859,0.3681245527
|
||||
5.152211952,-0.9048270525,0.4257792916
|
||||
5.215043805,-0.87630668,0.4817536741
|
||||
5.277875658,-0.8443279255,0.535826795
|
||||
5.340707511,-0.8090169944,0.5877852523
|
||||
5.403539364,-0.7705132428,0.6374239897
|
||||
5.466371217,-0.7289686274,0.6845471059
|
||||
5.52920307,-0.6845471059,0.7289686274
|
||||
5.592034923,-0.6374239897,0.7705132428
|
||||
5.654866776,-0.5877852523,0.8090169944
|
||||
5.71769863,-0.535826795,0.8443279255
|
||||
5.780530483,-0.4817536741,0.87630668
|
||||
5.843362336,-0.4257792916,0.9048270525
|
||||
5.906194189,-0.3681245527,0.9297764859
|
||||
5.969026042,-0.3090169944,0.9510565163
|
||||
6.031857895,-0.2486898872,0.9685831611
|
||||
6.094689748,-0.1873813146,0.9822872507
|
||||
6.157521601,-0.1253332336,0.9921147013
|
||||
6.220353454,-0.06279051953,0.9980267284
|
||||
6.283185307,0,1
|
||||
|
12
Trigo/test_trigo1.lua
Normal file
12
Trigo/test_trigo1.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
-- tests des routines trigonométriques pour NodeMCU
|
||||
print("\ntest_trigo1.lua zf180819.1731 \n")
|
||||
|
||||
-- chargement des routines trigonométriques
|
||||
dofile("trigo3.lua")
|
||||
|
||||
for i = 0, 2*pi, 2*pi/100 do
|
||||
a=i
|
||||
--print("tangente: "..a..", "..math.tan(a)..", "..ztan(a))
|
||||
b=math.tan(a)
|
||||
print("arctangente: "..b..", "..math.atan(b)..", "..zatan(b)..", "..math.atan(b)/zatan(b))
|
||||
end
|
||||
49
Trigo/trigo1.lua
Normal file
49
Trigo/trigo1.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
-- Essais de fire des fonctions trigos qui manque dans NodeMCU
|
||||
-- ATTENTION: arcsin ne fonctionne pas pour les valeur proche de 1 !
|
||||
-- source: https://www.esp8266.com/viewtopic.php?p=64415#
|
||||
print("\ntrigo1.lua zf180726.1136 \n")
|
||||
|
||||
function sin(x)
|
||||
local p=-x*x*x
|
||||
local f=6
|
||||
local r=x+p/f
|
||||
for j=1,60 do
|
||||
p=-p*x*x
|
||||
f=f*2*(j+1)*(j+j+3)
|
||||
r=r+p/f
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
function cos(x)
|
||||
return sin(math.pi/2-x)
|
||||
end
|
||||
|
||||
function tan(x)
|
||||
return sin(x)/cos(x)
|
||||
end
|
||||
|
||||
function arcsin(x)
|
||||
local suma=x
|
||||
for i=1,60 do
|
||||
suma = suma + (dfi(2*i-1)/dfp(2*i))*(math.pow(x,2*i+1)/(2*i+1))
|
||||
print("Suma: "..suma)
|
||||
end
|
||||
return suma
|
||||
end
|
||||
|
||||
function dfp(x)
|
||||
local par=1
|
||||
for i=2,x,2 do
|
||||
par = par * i
|
||||
end
|
||||
return par
|
||||
end
|
||||
|
||||
function dfi(x)
|
||||
local impar=1
|
||||
for i=1,x,2 do
|
||||
impar = impar * i
|
||||
end
|
||||
return impar
|
||||
end
|
||||
90
Trigo/trigo2.lua
Normal file
90
Trigo/trigo2.lua
Normal file
@@ -0,0 +1,90 @@
|
||||
-- 2e Essais de faire des fonctions trigos qui manque dans NodeMCU
|
||||
-- source pour sin&cos: https://www.esp8266.com/viewtopic.php?p=64415#
|
||||
-- source pour arcsin&arctan: http://www.electronicwings.com/nodemcu/magnetometer-hmc5883l-interfacing-with-nodemcu
|
||||
print("\ntrigo2.lua zf180726.1149 \n")
|
||||
|
||||
|
||||
|
||||
function sin(x)
|
||||
local p=-x*x*x
|
||||
local f=6
|
||||
local r=x+p/f
|
||||
for j=1,60 do
|
||||
p=-p*x*x
|
||||
f=f*2*(j+1)*(j+j+3)
|
||||
r=r+p/f
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
function cos(x)
|
||||
return sin(math.pi/2-x)
|
||||
end
|
||||
|
||||
function tan(x)
|
||||
return sin(x)/cos(x)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
pi = 3.14159265358979323846
|
||||
|
||||
|
||||
function arcsin(value)
|
||||
local val = value
|
||||
local sum = value
|
||||
if(value == nil) then
|
||||
return 0
|
||||
end
|
||||
-- as per equation it needs infinite iterations to reach upto 100% accuracy
|
||||
-- but due to technical limitations we are using
|
||||
-- only 10000 iterations to acquire reliable accuracy
|
||||
for i = 1,10000, 2 do
|
||||
val = (val*(value*value)*(i*i)) / ((i+1)*(i+2))
|
||||
sum = sum + val;
|
||||
end
|
||||
return sum
|
||||
end
|
||||
|
||||
function arctan(value)
|
||||
if(value == nil) then
|
||||
return 0
|
||||
end
|
||||
local _value = value/math.sqrt((value*value)+1)
|
||||
return arcsin(_value)
|
||||
end
|
||||
|
||||
function atan2(y, x)
|
||||
if(x == nil or y == nil) then
|
||||
return 0
|
||||
end
|
||||
|
||||
if(x > 0) then
|
||||
return arctan(y/x)
|
||||
end
|
||||
if(x < 0 and 0 <= y) then
|
||||
return arctan(y/x) + pi
|
||||
end
|
||||
if(x < 0 and y < 0) then
|
||||
return arctan(y/x) - pi
|
||||
end
|
||||
if(x == 0 and y > 0) then
|
||||
return pi/2
|
||||
end
|
||||
if(x == 0 and y < 0) then
|
||||
return -pi/2
|
||||
end
|
||||
if(x == 0 and y == 0) then
|
||||
return 0
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
print("On voit que l'arc sinus est précis au 1/2% prêt !")
|
||||
print("sin(3.14/2): "..sin(3.14/2))
|
||||
print("pi/(arcsin(1)*2): "..pi/(arcsin(1)*2))
|
||||
|
||||
|
||||
|
||||
|
||||
117
Trigo/trigo3.lua
Normal file
117
Trigo/trigo3.lua
Normal file
@@ -0,0 +1,117 @@
|
||||
-- 3e Essais de faire des fonctions trigos qui manque dans NodeMCU
|
||||
-- source pour arctan,arcsin et arccos: http://mathonweb.com/help_ebook/html/algorithms.htm
|
||||
-- source pour sin&cos: https://www.esp8266.com/viewtopic.php?p=64415#
|
||||
-- source pour arcsin&arctan: http://www.electronicwings.com/nodemcu/magnetometer-hmc5883l-interfacing-with-nodemcu
|
||||
print("\ntrigo3.lua zf180819.1745 \n")
|
||||
|
||||
pi = 3.14159265358979323846
|
||||
|
||||
function zsin(x)
|
||||
local p=-x*x*x local f=6 local r=x+p/f
|
||||
for j=1,60 do
|
||||
p=-p*x*x f=f*2*(j+1)*(j+j+3) r=r+p/f
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
function zcos(x)
|
||||
return zsin(math.pi/2-x)
|
||||
end
|
||||
|
||||
function ztan(x)
|
||||
return zsin(x)/zcos(x)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
function zatan(x)
|
||||
local y=1 local z
|
||||
if x<0 then
|
||||
y=-1 x=y*x
|
||||
end
|
||||
if x<1 then
|
||||
z=zzatan(x)
|
||||
else
|
||||
z=pi/2-zatan(1/x)
|
||||
end
|
||||
return y*z
|
||||
end
|
||||
|
||||
function zzatan(x)
|
||||
return x-x^3/3+x^5/5-x^7/7
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
--print("On voit que l'arc sinus est précis au 1/2% prêt !")
|
||||
a=0.9
|
||||
print("théorique tan("..a.."): "..math.tan(a))
|
||||
print("calculée tan("..a.."): "..ztan(a))
|
||||
b=math.tan(a)
|
||||
print("théorique atan("..b.."): "..math.atan(b))
|
||||
print("calculée atan("..b.."): "..zatan(b)..", "..pi/2-zatan(1/b))
|
||||
--print("pi/(arcsin(1)*2): "..pi/(arcsin(1)*2))
|
||||
]]
|
||||
|
||||
|
||||
--[[
|
||||
print("On voit que l'arc sinus est précis au 1/2% prêt !")
|
||||
print("sin(3.14/2): "..sin(3.14/2))
|
||||
print("pi/(arcsin(1)*2): "..pi/(arcsin(1)*2))
|
||||
]]
|
||||
|
||||
|
||||
--[[
|
||||
function arcsin(value)
|
||||
local val = value
|
||||
local sum = value
|
||||
if(value == nil) then
|
||||
return 0
|
||||
end
|
||||
-- as per equation it needs infinite iterations to reach upto 100% accuracy
|
||||
-- but due to technical limitations we are using
|
||||
-- only 10000 iterations to acquire reliable accuracy
|
||||
for i = 1,10000, 2 do
|
||||
val = (val*(value*value)*(i*i)) / ((i+1)*(i+2))
|
||||
sum = sum + val;
|
||||
end
|
||||
return sum
|
||||
end
|
||||
|
||||
function arctan(value)
|
||||
if(value == nil) then
|
||||
return 0
|
||||
end
|
||||
local _value = value/math.sqrt((value*value)+1)
|
||||
return arcsin(_value)
|
||||
end
|
||||
|
||||
function atan2(y, x)
|
||||
if(x == nil or y == nil) then
|
||||
return 0
|
||||
end
|
||||
|
||||
if(x > 0) then
|
||||
return arctan(y/x)
|
||||
end
|
||||
if(x < 0 and 0 <= y) then
|
||||
return arctan(y/x) + pi
|
||||
end
|
||||
if(x < 0 and y < 0) then
|
||||
return arctan(y/x) - pi
|
||||
end
|
||||
if(x == 0 and y > 0) then
|
||||
return pi/2
|
||||
end
|
||||
if(x == 0 and y < 0) then
|
||||
return -pi/2
|
||||
end
|
||||
if(x == 0 and y == 0) then
|
||||
return 0
|
||||
end
|
||||
return 0
|
||||
end
|
||||
]]
|
||||
Reference in New Issue
Block a user