Commit 9074dc7d authored by amandaghassaei's avatar amandaghassaei
Browse files

working on static solver

parent df7e26b5
......@@ -120,6 +120,7 @@ $(function() {
globals = initGlobals();
globals.model = initModel(globals);
globals.staticSolver = initStaticSolver(globals);
globals.staticSolver.syncNodesAndEdges();
globals.pattern = initPattern(globals);
globals.threeView.render();
// globals.threeView.sceneAdd(raycasterPlane);
......
......@@ -30,6 +30,16 @@ function initModel(globals){
var creases = [];
creases.push(new Crease(edges[2], 0, 1, Math.PI/2, 1, nodes[1], nodes[3], 0));
var _allNodeObject3Ds = [];
_.each(nodes, function(node){
var obj3D = node.getObject3D();
_allNodeObject3Ds.push(obj3D);
globals.threeView.sceneAddModel(obj3D);
});
_.each(edges, function(edge){
globals.threeView.sceneAddModel(edge.getObject3D());
});
function buildModel(_faces, _vertices, _allEdges, allCreaseParams){
var _nodes = [];
......
......@@ -5,9 +5,9 @@
var nodeMaterial = new THREE.MeshBasicMaterial({color: 0x000000, side:THREE.DoubleSide});
var nodeMaterialFixed = new THREE.MeshBasicMaterial({color: 0x000000, side:THREE.DoubleSide});
var nodeMaterialHighlight = new THREE.MeshBasicMaterial({color: 0xffffff, side:THREE.DoubleSide});
var nodeGeo = new THREE.SphereGeometry(10,20);
var nodeGeo = new THREE.SphereGeometry(1,20);
nodeGeo.rotateX(Math.PI/2);
var nodeFixedGeo = new THREE.CubeGeometry(10, 10, 10);
var nodeFixedGeo = new THREE.CubeGeometry(1, 1, 1);
nodeFixedGeo.applyMatrix( new THREE.Matrix4().makeTranslation(0, 0.25, 0) );
......
......@@ -32,46 +32,46 @@ function initPattern(globals){
});
}
loadSVG("assets/Tessellations/miura-ori.svg", function(svg){
var _$svg = $(svg);
//format all lines
var $paths = _$svg.children("path");
$paths.css({fill:"none", 'stroke-width':3, 'stroke-dasharray':"none"});
var $outlines = $paths.filter(function(){
var stroke = $(this).attr("stroke").toLowerCase();
return stroke == "#000000" || stroke == "#000";
});
// $outlines.css({fill:'#ffffff'});
var $mountains = $paths.filter(function(){
var stroke = $(this).attr("stroke").toLowerCase();
return stroke == "#ff0000" || stroke == "#f00";
});
$mountains.css({'stroke-dasharray':'12, 6, 3, 6'});
var $valleys = $paths.filter(function(){
var stroke = $(this).attr("stroke").toLowerCase();
return stroke == "#0000ff" || stroke == "#00f";
});
$valleys.css({'stroke-dasharray':'7, 6, 7, 6'});
var $cuts = $paths.filter(function(){
var stroke = $(this).attr("stroke").toLowerCase();
return stroke == "#00ff00" || stroke == "#0f0";
});
var $svg = $('<svg version="1.1" viewBox="'+_$svg.attr("viewBox")+'" id="mySVG" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> </svg>');
$svg.append($outlines);
$svg.append($mountains);
$svg.append($valleys);
$svg.append($cuts);
$("#svgViewer").html($svg);
parseSVG($outlines, $mountains, $valleys, $cuts);
});
// loadSVG("assets/Tessellations/miura-ori.svg", function(svg){
// var _$svg = $(svg);
//
// //format all lines
// var $paths = _$svg.children("path");
// $paths.css({fill:"none", 'stroke-width':3, 'stroke-dasharray':"none"});
//
// var $outlines = $paths.filter(function(){
// var stroke = $(this).attr("stroke").toLowerCase();
// return stroke == "#000000" || stroke == "#000";
// });
// // $outlines.css({fill:'#ffffff'});
//
// var $mountains = $paths.filter(function(){
// var stroke = $(this).attr("stroke").toLowerCase();
// return stroke == "#ff0000" || stroke == "#f00";
// });
// $mountains.css({'stroke-dasharray':'12, 6, 3, 6'});
//
// var $valleys = $paths.filter(function(){
// var stroke = $(this).attr("stroke").toLowerCase();
// return stroke == "#0000ff" || stroke == "#00f";
// });
// $valleys.css({'stroke-dasharray':'7, 6, 7, 6'});
//
// var $cuts = $paths.filter(function(){
// var stroke = $(this).attr("stroke").toLowerCase();
// return stroke == "#00ff00" || stroke == "#0f0";
// });
//
// var $svg = $('<svg version="1.1" viewBox="'+_$svg.attr("viewBox")+'" id="mySVG" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> </svg>');
// $svg.append($outlines);
// $svg.append($mountains);
// $svg.append($valleys);
// $svg.append($cuts);
//
// $("#svgViewer").html($svg);
//
// parseSVG($outlines, $mountains, $valleys, $cuts);
// });
function parsePath(_verticesRaw, _segmentsRaw, $paths){
for (var i=0;i<$paths.length;i++){
......
......@@ -50,6 +50,32 @@ function initStaticSolver(){
setUpParams();
}
function solve(){
if (fixedIndicesMapping.length == 0){//no boundary conditions
var X = initEmptyArray(nodes.length, 3);
render(X);
console.warn("no boundary conditions");
return;
}
var X = numeric.dot(inv_Ctrans_Q_C, numeric.sub(F, Ctrans_Q_Cf_Xf));
console.log(X);
render(X);
}
function render(X){
for (var i=0;i<X.length;i++){
var nodePosition = new THREE.Vector3(X[i][0],X[i][1],X[i][2]);
var node = nodes[indicesMapping[i]];
node.render(nodePosition.sub(node.getOriginalPosition()));
}
for (var i=0;i<fixedIndicesMapping.length;i++){
nodes[fixedIndicesMapping[i]].render(new THREE.Vector3(0,0,0));
}
for (var i=0;i<edges.length;i++){
edges[i].render(true);
}
}
function initEmptyArray(dim1, dim2, dim3){
if (dim2 === undefined) dim2 = 0;
if (dim3 === undefined) dim3 = 0;
......@@ -88,32 +114,28 @@ function initStaticSolver(){
//disp = 1x3nodes
Q = initEmptyArray(numEdges, numEdges);
C = initEmptyArray(numEdges, 3*numVerticesFree);
Cfixed = initEmptyArray(numEdges, 3*numVerticesFixed);
C = initEmptyArray(numEdges, numVerticesFree);
Cfixed = initEmptyArray(numEdges, numVerticesFixed);
calcQ();
calcCs();
Ctrans = numeric.transpose(C);
CfixedTrans = numeric.transpose(Cfixed);
F = initEmptyArray(3*indicesMapping);
Xfixed = initEmptyArray(3*numVerticesFixed);
F = initEmptyArray(numVerticesFree);
Xfixed = initEmptyArray(numVerticesFixed);
for (var i=0;i<indicesMapping.length;i++){
F[i] = 0;
F[i+1] = 1;//gravity
F[i+2] = 0;
for (var i=0;i<numVerticesFree;i++){
F[i] = [0,1000,0];
}
for (var i=0;i<numVerticesFixed;i++){
var position = nodes[fixedIndicesMapping[i]].getOriginalPosition();
Xfixed[i] = position.x;
Xfixed[i+1] = position.y;
Xfixed[i+2] = position.z;
Xfixed[i] = [position.x, position.y, position.z];
}
Ctrans_Q = numeric.dot(Ctrans, Q);
Ctrans_Q_C = numeric.dot(Ctrans_Q, C);
console.log(JSON.stringify(Ctrans_Q_C));
// console.log(JSON.stringify(Ctrans_Q_C));
if (numeric.det(Ctrans_Q_C) == 0){
console.warn("zero determinant");
return;
......@@ -122,6 +144,7 @@ function initStaticSolver(){
Ctrans_Q_Cf = numeric.dot(Ctrans_Q, Cfixed);
Ctrans_Q_Cf_Xf = numeric.dot(Ctrans_Q_Cf, Xfixed);
solve();
}
function calcCs(){
......@@ -129,44 +152,42 @@ function initStaticSolver(){
var edge = edges[j];
var _nodes = edge.nodes;
var edgeVector0 = edge.getVector(_nodes[0]);
var edgeVector1 = edge.getVector(_nodes[1]);
if (_nodes[0].fixed) {
var i = fixedIndicesMapping.indexOf(_nodes[0].getIndex());
Cfixed[j][i*3] = edgeVector0.x;
Cfixed[j][i*3+1] = edgeVector0.y;
Cfixed[j][i*3+2] = edgeVector0.z;
Cfixed[j][i] = 1;
// Cfixed[j][3*i] = edgeVector0.x;
// Cfixed[j][3*i+1] = edgeVector0.y;
// Cfixed[j][3*i+2] = edgeVector0.z;
} else {
var i = indicesMapping.indexOf(_nodes[0].getIndex());
C[j][3*i] = edgeVector0.x;
C[j][3*i+1] = edgeVector0.y;
C[j][3*i+2] = edgeVector0.z;
C[j][i] = 1;
// C[j][3*i] = edgeVector0.x;
// C[j][3*i+1] = edgeVector0.y;
// C[j][3*i+2] = edgeVector0.z;
}
if (_nodes[1].fixed) {
var i = fixedIndicesMapping.indexOf(_nodes[1].getIndex());
Cfixed[j][i*3] = edgeVector1.x;
Cfixed[j][i*3+1] = edgeVector1.y;
Cfixed[j][i*3+2] = edgeVector1.z;
Cfixed[j][i] = -1;
// Cfixed[j][3*i] = -edgeVector0.x;
// Cfixed[j][3*i+1] = -edgeVector0.y;
// Cfixed[j][3*i+2] = -edgeVector0.z;
} else {
var i = indicesMapping.indexOf(_nodes[1].getIndex());
C[j][3*i] = edgeVector1.x;
C[j][3*i+1] = edgeVector1.y;
C[j][3*i+2] = edgeVector1.z;
C[j][i] = -1;
// C[j][3*i] = -edgeVector0.x;
// C[j][3*i+1] = -edgeVector0.y;
// C[j][3*i+2] = -edgeVector0.z;
}
}
}
function calcQ(){
function calcQ() {
var axialStiffness = globals.axialStiffness;
for (var i=0;i<numEdges;i++){
for (var i = 0; i < numEdges; i++) {
Q[i][i] = axialStiffness;
}
}
function solve(){
}
return {
syncNodesAndEdges: syncNodesAndEdges
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment