Skip to content

Commit

Permalink
WOP
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Apr 7, 2024
1 parent 961107e commit 106290f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
52 changes: 52 additions & 0 deletions apps/find_plane.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
local apps = require 'apps.apps'
local ask = require('dialog.input').display_sync
local choice = require('dialog.choice').display_sync
local expr = require 'expressiontree'

local function table_to_vec(t)
local r = ""
for _, v in ipairs(t) do
r = r .. "[" .. v .. "]"
end
return "[" .. r .. "]"
end

local function ask_vector(title, dim)
dim = dim or 3
while true do
local r = ask({title = title or 'Vector'})
if not r then
return nil
end

local v = {}
for c in r:gmatch("([^,]+)") do
table.insert(v, c)
end

if #v == dim then
return v
end
end
end

local function run_plane_3pt(stack)
local pts = {}
for i = 1, 3 do
local pt = ask_vector("Point " .. tostring(i))
if not pt then
return
end
table.insert(pts, pt)
end

local a, b, c = pts[1], pts[2], pts[3]
local ab = math.evalStr(table_to_vec(a) .. "-" .. table_to_vec(b))
local ac = math.evalStr(table_to_vec(a) .. "-" .. table_to_vec(c))
local n = math.evalStr("crossp(" .. ab .. "," .. ac .. ")")
local eq = math.evalStr("dotp(" ..n .. "," .. table_to_vec({"x", "y", "z"}) .. ")")
local d = math.evalStr(string.format(eq .."|(x=%s and y=%s and z=%s)", a[1], a[2], a[3]))
stack:push_infix(eq .. "=" .. d)
end

apps.add('plane - 3pt', 'Plane - 3 Points', run_plane_3pt)
2 changes: 2 additions & 0 deletions apps/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ require 'apps.app_punktsteigung'
require 'apps.app_triangle'
require 'apps.app_constants'
require 'apps.app_analyze_fn'

require 'apps.find_plane'

0 comments on commit 106290f

Please sign in to comment.