desmoslogger
v1.0.0
Published
Logger creates pastable code to visulise points/planes in desmos, hear me out
Downloads
86
Readme
desmosLogger
Do you like debugging your physics engin with desmos? Generates copy pastable code for desmos. A focus of the package is to make the generated desmos graphs interactable througth variables.
Installation
npm install desmosloggerdependencys
-earcut for polygon triangulation.
Demo
let mVects = [[1.304,-1.493,4.132],{x:0.7061,y:0.1408,z:6.363},
"(0.1883,-2.309,4.431)","(0.4871,-3.126,3.316)",
"(2.962,-3.126,0.8404)","(3.833,-0.6766,2.419)",
"(2.12,0.1404,4.949)","(2.36,-1.183,-0.7697)",
"(0.7599,-1.699,0.3134)","(2.687,0.3665,0.452)"];
let e2Faces = [[0,1,2,3,4,5,6],[7,5,6],[7,9,6],[7,8,3],[7,4,3],[7,8,9],[9,8,6],[8,6,0],[8,1,0],[8,1,2],[8,3,2],[7,4,5]];
const path = require("path");
const { createDesDebug } = require("desmosLogger");
const TMP_LOG = path.join(__dirname,"model_desmoslog.txt");
let MdlDes = createDesDebug(TMP_LOG);
MdlDes.model(mVects,e2Faces);By default all expressions are written to desmoslog.txt in the project root. Open that file and paste its contents into Desmos.
Point format
All points provided can be one of 3 types below,
[1,2,3]"(1,2,3)"or"1,2,3"{x:1,y:2,z:3}
Naming conventions
Varibale names in desmos are made up of the varibale letter and subscripts. For each elemnt of the graph the below naming convention is used.
- objectLetterobjectCount elemntSpesification elementCount
desmos
- A focus of the package is to make graphs a interactive as possibal.
- Some values need to be defined but not visibal this is achived by defining points as a output of functions.
f(a)={(p.x,p.y,p.z)}get point withf(1)
Public API
All methods return a Promise that resolves when their log writes have been enqueued.
init(): Promise<void>
Clears the log file and resets all internal counters for points/lines/triangles/etc.point(point): Promise<void>
Logs a point Pn in Desmos.line(point1 [,point2,options]): Promise<void>
Logs a line segment Ln between two points. If nopoint2is provided the line segment will be betweenpoint1and the oiginoptions
showPoints: iftruecreate variables for each point, iffalsedirectly inserts value into segemnt.
triangle(p1, p2, p3[,options]): Promise<void>
Logs a triangle Tn with vertexes p1,p2,p3 , optionally logging its three vertices as named points.options
showPoints: iftruecreate variables for each point, iffalsedirectly inserts value into segemnt.
vector(direction[,origin,options]): Promise<void>
Logs a vector Vn starting fromoriginin the givendirection.options
len:length of vector
desmos
- creates variables
origin, to refrence.
normal(origin, point1, point2[, options]): Promise<void>
Logs a normal vector Nn derived from the oriented triangle(origin, p1, p2), scaled tolength. Point1, and point2 should be in order of the right rule from theorigin.options
showTriangle:iftruedisplays triangle betweenorigin, point1, point2len:length of normal
poly(points[,options]): Promise<void>
Logs a polygon surface Sn defined by a list of 3D points.points:Array of points making up the polygon. Order must form a path around the edge.
options
justShow:iftruedo not display basis vectors or tagvectors.tagVects:vector will be added to the center of mass of polygon, to show rays,normals etc.offSet:defines the origin point of the model
desmos
- points projected on plane and basis found, change of basis to convert all points to 2d cordinates, define change of cordinate function
f(x,y)=unit2*x + unit3*y + dot(unt1*p1)*unit1 + offSet. List vertexes in 2d cordinate spacev = [p1,p2,...]. Use earcut algorithum, define triangle constructor functionf(a,b,c)=triangle(v[a],v[b],v[c]). Define all triangles. - UI:
offsetorigin point of polygon - UI:``
function model(points, faces [,options]): Promise<void>
Logs a simple model composed of multiple polygon faces.points: array of vertex positions (as strings/arrays/objects)faces: array of faces, where each face is an array of indices intopoints
options
justShow:iftruedo not display basis vectors or tagvectors.tagVects:Array of vectors to be added to each face of the model.offSet:defines the origin point of the modelz
