-
Notifications
You must be signed in to change notification settings - Fork 3
Data Extraction
Given an object list:
obj: [
["grid","","",-1.5,6.5,-2.5,4,40],
["forceGen","F_2",[-0.5,3.5]],
["momentGen","M_2",[1.5,3.5]],
["beam","",[0,0],[3,0],0.15,"locked"],
["bar","",[3,0],[5,-1],"hide"],
["fix12","A",[0,0],0,"hide"],
["fix12","C",[5,-1],0,"show"],
["label","\\(B\\)",[2.8,-0.5]],
["q","","q_0",[0,0.3],[3,0.3],0.7,0.7,0,"show"],
["force","A_v",[0,0],[0,1.6],10,"active"],
["force","A_h",[0,0],[1.1,0],10,"active"],
["force","B",[3,0],[4.2,-0.6000000000000001],10,"active"]
];
and the associated names
names: [0,0,0,"locked",[12],[10,11],"show",0,"show",A_v,A_h,B];
We want to extract entries by properties:
All forces:
sublist_indices (objects, lambda ([x], x[1]="force"));
results in:
[10,11,12]
All active forces
sublist (objects, lambda ([x], x[length(x)]="active" and x[1]="force"));
results in
[10,11,12]
Force B
sublist_indices (objects, lambda ([x], x[1]="force" and x[2]="B"));
Number of forces at object with given index
num: length( sublist_indices (names[index], lambda ([x], obj[x][1]="force" ) ) );
Indices of forces at fixed support A
names[sublist_indices (objects, lambda ([x], x[1]="fix12" and x[2]="A"))[1]];
results in [10,11]
active vertical force with name A_v
sublist_indices (objects, lambda ([x], x[length(x)]="active" and x[1]="force" and (x[4]-x[3])[1]=0 and x[2]="A_v"));
results in [10]
a
and b
are items from the object list with 2-point based location (force, bar, spring, dashpot, but not rope).
parallelp(a,b):= block([da,db],
da: a[4]-a[3], db: b[4]-b[3],
return(is (abs(da[1]*db[2]-da[2]*db[1])<0.05) ));
In order to try code snippets in jsfiddle,
- copy the code from the wiki page to the clipboard
- follow the link for the JSXGraph version you want to try
- Replace the code in the HTML section (contents of
<p hidden id="init">
) with the content of the clipboard