-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
961107e
commit 106290f
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters