-
Notifications
You must be signed in to change notification settings - Fork 2
/
misc_funcs.js
90 lines (70 loc) · 2.78 KB
/
misc_funcs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
collection of short useful functions
*/
// function to modify underbrace text:
function changeUnderText(underTextIndex,value,numOfDec,parent=document){
// underTextIndex: underbrace you want to modify, input 1 for the first underbrace
// value: value you want for underbrace
// numOfDec: number of decimals you want displayed
// parent: the div to search for the underbraces, optional
// get the element with the desired text:
textSpan=parent.getElementsByClassName("mjx-under")[(underTextIndex-1)*2+1].children[0].children[0].children[0].children[0]
// round the value:
roundedValue=Math.round(value*(10**numOfDec))/(10**numOfDec)
// set the text to the rounded value:
textSpan.innerText=roundedValue
}
// changes the opacity of all shapes in an array (or nested array), called in branches when changing opacity
function changeOpacity(shapeGroups,opacitySel){
var allShapes=shapeGroups.flat(Infinity)
for (let i=0;i<allShapes.length;i++){
var shape=allShapes[i]
shape.opacity=opacitySel
}
}
function changeVisibility(shapeGroups,isVisible){
var allShapes=shapeGroups.flat(Infinity)
for (let i=0;i<allShapes.length;i++){
var shape=allShapes[i]
shape.visible=isVisible
}
}
function linspace(startValue, stopValue, cardinality) {
var arr = [];
var step = (stopValue - startValue) / (cardinality - 1);
for (var i = 0; i < cardinality; i++) {
arr.push(startValue + (step * i));
}
return arr;
}
function vecToMat(pointsV){
var pointsM=[]
for (let i=0;i<pointsV.length;i++){
pointsM[i]=[]
pointsM[i][0]=pointsV[i].x
pointsM[i][1]=pointsV[i].y
pointsM[i][2]=pointsV[i].z
}
return pointsM
}
function matToVec(pointsM){
var pointsV=[]
for (let i=0;i<pointsM.length;i++){
pointsV[i]=vec(0,0,0)
pointsV[i].x=pointsM[i][0]
pointsV[i].y=pointsM[i][1]
pointsV[i].z=pointsM[i][2]
}
return pointsV
}
function makeCoordShape(coordShapePos=vec(0,0,0),coordShapeScale=1){
var coordTextGap=.1
var xDir=arrow({axis:vec(1,0,0).multiply(coordShapeScale),pos:coordShapePos})
var yDir=arrow({axis:vec(0,1,0).multiply(coordShapeScale),pos:coordShapePos})
var zDir=arrow({axis:vec(0,0,1).multiply(coordShapeScale),pos:coordShapePos})
var xText=label({text:"x",pos:vec(1+coordTextGap,0,0).multiply(coordShapeScale).add(coordShapePos), box: false, opacity: 0})
var yText=label({text:"y",pos:vec(0,1+coordTextGap,0).multiply(coordShapeScale).add(coordShapePos), box: false, opacity: 0})
var zText=label({text:"z",pos:vec(0,0,1+coordTextGap).multiply(coordShapeScale).add(coordShapePos), box: false, opacity: 0})
var coordShape=[xDir,yDir,zDir,xText,yText,zText]
return coordShape
}