-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathbeam.js
executable file
·121 lines (90 loc) · 3.05 KB
/
beam.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* Created by ghassaei on 9/16/16.
*/
// var beamMaterialHighlight = new THREE.LineBasicMaterial({color: 0xff0000, linewidth: 1});
// var beamMaterial = new THREE.LineBasicMaterial({color: 0x000000, linewidth: 1});
function Beam(nodes){
this.type = "beam";
nodes[0].addBeam(this);
nodes[1].addBeam(this);
this.vertices = [nodes[0]._originalPosition, nodes[1]._originalPosition];
this.nodes = nodes;
// var lineGeometry = new THREE.Geometry();
// lineGeometry.dynamic = true;
// lineGeometry.vertices = this.vertices;
// this.object3D = new THREE.Line(lineGeometry, beamMaterial);
this.originalLength = this.getLength();
}
// Beam.prototype.highlight = function(){
// this.object3D.material = beamMaterialHighlight;
// };
//
// Beam.prototype.unhighlight = function(){
// this.object3D.material = beamMaterial;
// };
Beam.prototype.getLength = function(){
return this.getVector().length();
};
Beam.prototype.getOriginalLength = function(){
return this.originalLength;
};
Beam.prototype.recalcOriginalLength = function(){
this.originalLength = this.getVector().length();
};
Beam.prototype.isFixed = function(){
return this.nodes[0].fixed && this.nodes[1].fixed;
};
Beam.prototype.getVector = function(fromNode){
if (fromNode == this.nodes[1]) return this.vertices[0].clone().sub(this.vertices[1]);
return this.vertices[1].clone().sub(this.vertices[0]);
};
// Beam.prototype.setVisibility = function(state){
// this.object3D.visible = state;
// };
//dynamic solve
Beam.prototype.getK = function(){
return globals.axialStiffness/this.getLength();
};
Beam.prototype.getD = function(){
return globals.percentDamping*2*Math.sqrt(this.getK()*this.getMinMass());
};
Beam.prototype.getNaturalFrequency = function(){
return Math.sqrt(this.getK()/this.getMinMass());
};
Beam.prototype.getMinMass = function(){
var minMass = this.nodes[0].getSimMass();
if (this.nodes[1].getSimMass()<minMass) minMass = this.nodes[1].getSimMass();
return minMass;
};
Beam.prototype.getOtherNode = function(node){
if (this.nodes[0] == node) return this.nodes[1];
return this.nodes[0];
};
// var valleyColor = new THREE.LineBasicMaterial({color:0x0000ff});
// var mtnColor = new THREE.LineBasicMaterial({color:0xff0000});
// Beam.prototype.setMountain = function(){
// this.object3D.material = mtnColor;
// };
//
// Beam.prototype.setValley = function(){
// this.object3D.material = valleyColor;
// };
//render
// Beam.prototype.getObject3D = function(){
// return this.object3D;
// };
// Beam.prototype.render = function(shouldComputeLineDistance){
// this.object3D.geometry.verticesNeedUpdate = true;
// this.object3D.geometry.computeBoundingSphere();
// if (shouldComputeLineDistance) this.object3D.geometry.computeLineDistances();//for dashed lines
// };
//deallocate
Beam.prototype.destroy = function(){
var self = this;
_.each(this.nodes, function(node){
node.removeBeam(self);
});
this.vertices = null;
// this.object3D = null;
this.nodes = null;
};