summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-01-04 21:22:01 +0000
committerubq323 <ubq323@ubq323.website>2024-01-04 21:22:01 +0000
commit18eb189a3bdc55f43d2206e09d449768bcf030c0 (patch)
tree6e59f03108d50b21dfa749c5fc492bff31b7a0ff
parent74dd8b6b857edcbeb12cbeca8c559b2ebbc2e79e (diff)
tweaks
-rw-r--r--main.lua26
1 files changed, 20 insertions, 6 deletions
diff --git a/main.lua b/main.lua
index 0f224d2..ecac412 100644
--- a/main.lua
+++ b/main.lua
@@ -5,6 +5,10 @@ local function plot(f,x0,xn)
x0 = x0 or G.inverseTransformPoint(0,0)
xn = xn or G.inverseTransformPoint(G.getDimensions(),0)
+ if xn < x0 then
+ xn,x0 = x0,xn
+ end
+
local h = (xn-x0)/n
local ps = {}
for i=0,n do
@@ -39,7 +43,7 @@ function love.wheelmoved(x,y)
L = L + (y/5)
end
-local function catenary(x1,y1,x2,y2)
+local function catenary0(x1,y1,x2,y2)
y1 = -y1
y2 = -y2
local dx = x2-x1
@@ -48,7 +52,7 @@ local function catenary(x1,y1,x2,y2)
local my = (y1+y2)/2
local D = math.sqrt(dx^2+dy^2)
- -- local L = D*1.2
+ -- local L = D+(1/D)
local r = math.sqrt(L^2 - dy^2)/dx
local A = solve_for_A(r)
@@ -59,6 +63,13 @@ local function catenary(x1,y1,x2,y2)
return function(x) return -(a * math.cosh((x-b)/a) + c) end
end
+local function catenary(x1,y1,x2,y2)
+ if x2 < x1 then
+ x1,x2 = x2,x1
+ y1,y2 = y2,y1
+ end
+ return catenary0(x1,y1,x2,y2)
+end
local Ps = {{-1,1}, {1,1}}
@@ -81,11 +92,13 @@ function love.draw()
G.translate(W/2,H/2)
G.scale(150)
- -- G.setColor(0.8,0.8,0.8)
- -- G.line(-10,0,10,0)
- -- G.line(0,-10,0,10)
+ G.setColor(0.8,0.8,0.8)
+ for i=-10,10 do
+ G.line(-10,i,10,i)
+ G.line(i,-10,i,10)
+ end
- -- G.circle('line',0,0,1)
+ G.circle('line',0,0,1)
-- G.setColor(0,0,0)
-- -- plot(function(x) return x^2 end)
@@ -93,6 +106,7 @@ function love.draw()
-- G.setColor(0,1,0)
-- plot(atanh)
+ G.setColor(0,0,0)
plot(catenary(Ps[1][1],Ps[1][2], Ps[2][1], Ps[2][2]),
Ps[1][1], Ps[2][1])