From 106290fcbdb78d08af4437eed3548ad59e3cc306 Mon Sep 17 00:00:00 2001 From: Johannes Wolf Date: Sun, 7 Apr 2024 17:37:58 +0200 Subject: [PATCH] WOP --- apps/find_plane.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++ apps/init.lua | 2 ++ 2 files changed, 54 insertions(+) create mode 100644 apps/find_plane.lua diff --git a/apps/find_plane.lua b/apps/find_plane.lua new file mode 100644 index 0000000..52725f7 --- /dev/null +++ b/apps/find_plane.lua @@ -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) diff --git a/apps/init.lua b/apps/init.lua index 896004c..e1626e5 100644 --- a/apps/init.lua +++ b/apps/init.lua @@ -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'