forked from liebeskind/feap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
109 lines (92 loc) · 3.98 KB
/
index.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>One Graph</title>
<script type="text/javascript" src="lib/d3.v3.js"></script>
<script src="matrixUtil/src/matrixUtil.js"></script>
<script src="src/mesh.js"></script>
<script src="src/festress.js"></script>
<script src="src/elemSolve.js"></script>
<script src="src/fesolve.js"></script>
<script src="src/feap.js"></script>
</head>
<body>
<div class="chart"></div>
<script type="text/javascript">
var feap = new FEAP();
var results = feap.solve();
var surface = d3.select('.chart').append('svg:svg').attr('class','surface').attr('width',800).attr('height',600);
var nodes;
var nodeData = [];
var mouseCoords;
var isHovering = false;
surface.on('click',function(event){
var p1 = d3.mouse(this);
console.log(p1);
surface.append('svg:circle').attr('class','node')
.attr('cx',function(e){return p1[0];})
.attr('cy',function(e){return p1[1];})
.attr('r',4);
})
var createNodes = function(n){
var activeNodes = [];
for(var i = 0 ; i < n; i++){
activeNodes.push(i);
nodeData.push({
id: i,
x: feap.inputParameters.x[i][0],
y: feap.inputParameters.x[i][1]
});
}
nodes = surface.selectAll('nodes').data(nodeData, function(e){return e.id;});
nodes.enter().append('svg:circle').attr('class','node')
.attr('cx',function(e){return e.x+100;})
.attr('cy',function(e){return e.y+200;})
.attr('r',2);
};
var createElements = function(){
for(var i = 0 ; i < feap.inputParameters.elem.length; i++){
var myLine = surface.append("svg:line")
.attr("x1", feap.inputParameters.x[feap.inputParameters.elem[i][0]-1][0]+100)
.attr("y1", feap.inputParameters.x[feap.inputParameters.elem[i][0]-1][1]+200)
.attr("x2", feap.inputParameters.x[feap.inputParameters.elem[i][1]-1][0]+100)
.attr("y2", feap.inputParameters.x[feap.inputParameters.elem[i][1]-1][1]+200)
.style("stroke", "rgb(6,120,155)");
}
}
var createDeflectedElements = function(){
for(var i = 0 ; i < feap.inputParameters.elem.length; i++){
var myLine = surface.append("svg:line")
.attr("x1", feap.inputParameters.x[feap.inputParameters.elem[i][0]-1][0]+100+200*results.U[(feap.inputParameters.elem[i][0]-1)*3])
.attr("y1", feap.inputParameters.x[feap.inputParameters.elem[i][0]-1][1]+200-200*results.U[(feap.inputParameters.elem[i][0]-1)*3+1])
.attr("x2", feap.inputParameters.x[feap.inputParameters.elem[i][1]-1][0]+100+200*results.U[(feap.inputParameters.elem[i][1]-1)*3])
.attr("y2", feap.inputParameters.x[feap.inputParameters.elem[i][1]-1][1]+200-200*results.U[(feap.inputParameters.elem[i][1]-1)*3+1])
.style("stroke", "rgb(6,120,155)")
.style("stroke-width","3");;
}
}
var createDeflectedNodes = function(n){
var activeNodes = [];
for(var i = 0 ; i < n; i++){
activeNodes.push(i);
nodeData.push({
id: i,
x: feap.inputParameters.x[i][0]+200*results.U[i*3],
y: feap.inputParameters.x[i][1]+200*results.U[i*3+1]
});
}
nodes = surface.selectAll('nodes').data(nodeData, function(e){return e.id;});
nodes.enter().append('svg:circle').attr('class','node')
.attr('cx',function(e){return e.x+100;})
.attr('cy',function(e){return e.y+200;})
.attr('r',5);
};
createDeflectedNodes();
createDeflectedElements();
createElements()
createNodes(feap.inputParameters.x.length);
console.log('done')
</script>
</body>
</html>