mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-08 01:13:27 +01:00
minimization magic
This commit is contained in:
parent
955bcbb6fc
commit
9aec197419
5 changed files with 19 additions and 9 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -3,6 +3,8 @@
|
||||||
/out/
|
/out/
|
||||||
/.idea/
|
/.idea/
|
||||||
*.iml
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
# Package Files #
|
# Package Files #
|
||||||
*.jar
|
*.jar
|
||||||
|
|
|
||||||
|
|
@ -792,8 +792,8 @@ TCAD.TWO.DragTool.prototype.solveRequest = function(fineLevel) {
|
||||||
&& this.obj.parent._class === 'TCAD.TWO.Arc') {
|
&& this.obj.parent._class === 'TCAD.TWO.Arc') {
|
||||||
|
|
||||||
if (this.obj.id != this.obj.parent.c.id) {
|
if (this.obj.id != this.obj.parent.c.id) {
|
||||||
locked.push(this.obj.parent.c._x);
|
// locked.push(this.obj.parent.c._x);
|
||||||
locked.push(this.obj.parent.c._y);
|
// locked.push(this.obj.parent.c._y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -200,16 +200,18 @@ TCAD.parametric.lock1 = function(constrs, locked) {
|
||||||
TCAD.parametric.lock2Equals2 = function(constrs, locked) {
|
TCAD.parametric.lock2Equals2 = function(constrs, locked) {
|
||||||
var _locked = [];
|
var _locked = [];
|
||||||
for (var i = 0; i < locked.length; ++i) {
|
for (var i = 0; i < locked.length; ++i) {
|
||||||
_locked.push(new TCAD.constraints.Weighted(new TCAD.constraints.EqualsTo([locked[i]], locked[i].get()), 0.1));
|
_locked.push(new TCAD.constraints.Weighted(new TCAD.constraints.EqualsTo([locked[i]], locked[i].get()), 1));
|
||||||
}
|
}
|
||||||
return _locked;
|
return _locked;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TCAD.parametric._alg = 5;
|
||||||
|
|
||||||
TCAD.parametric.prepare = function(constrs, locked, aux, alg) {
|
TCAD.parametric.prepare = function(constrs, locked, aux, alg) {
|
||||||
|
|
||||||
this.lock1(constrs, aux);
|
this.lock1(constrs, aux);
|
||||||
var lockingConstrs = this.lock2Equals2(constrs, locked);
|
var lockingConstrs = this.lock2Equals2(constrs, locked);
|
||||||
// Array.prototype.push.apply( constrs, lockingConstrs );
|
Array.prototype.push.apply( constrs, lockingConstrs );
|
||||||
|
|
||||||
var sys = new TCAD.parametric.System(constrs);
|
var sys = new TCAD.parametric.System(constrs);
|
||||||
|
|
||||||
|
|
@ -231,7 +233,7 @@ TCAD.parametric.prepare = function(constrs, locked, aux, alg) {
|
||||||
sys.setParams(point);
|
sys.setParams(point);
|
||||||
return sys.makeJacobian();
|
return sys.makeJacobian();
|
||||||
};
|
};
|
||||||
alg = 5;
|
alg = TCAD.parametric._alg;
|
||||||
|
|
||||||
function solve(fineLevel) {
|
function solve(fineLevel) {
|
||||||
if (constrs.length == 0) return;
|
if (constrs.length == 0) return;
|
||||||
|
|
@ -252,7 +254,10 @@ TCAD.parametric.prepare = function(constrs, locked, aux, alg) {
|
||||||
TCAD.math.solve_UNCMIN(sys);
|
TCAD.math.solve_UNCMIN(sys);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
optim.dog_leg(sys);
|
if (optim.dog_leg(sys) !== 0) {
|
||||||
|
TCAD.parametric._alg = alg = -5;
|
||||||
|
solve(fineLevel);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return sys;
|
return sys;
|
||||||
|
|
@ -260,9 +265,10 @@ TCAD.parametric.prepare = function(constrs, locked, aux, alg) {
|
||||||
|
|
||||||
var opt = new LMOptimizer(sys.getParams(), arr(sys.constraints.length), model, jacobian);
|
var opt = new LMOptimizer(sys.getParams(), arr(sys.constraints.length), model, jacobian);
|
||||||
var eps;
|
var eps;
|
||||||
|
fineLevel = 1;
|
||||||
switch (fineLevel) {
|
switch (fineLevel) {
|
||||||
case 1:
|
case 1:
|
||||||
eps = 0.01;
|
eps = 0.001;
|
||||||
opt.init0(eps, eps, eps);
|
opt.init0(eps, eps, eps);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
|
|
||||||
|
|
@ -358,10 +358,10 @@ optim.dog_leg = function(subsys) {
|
||||||
var alpha=0.;
|
var alpha=0.;
|
||||||
var nu=2.;
|
var nu=2.;
|
||||||
var iter=0, stop=0, reduce=0;
|
var iter=0, stop=0, reduce=0;
|
||||||
while (!stop) {
|
while (stop === 0) {
|
||||||
|
|
||||||
// check if finished
|
// check if finished
|
||||||
if (fx_inf <= tolf) // Success
|
if (fx_inf <= tolf || err <= tolf) // Success
|
||||||
stop = 1;
|
stop = 1;
|
||||||
else if (g_inf <= tolg)
|
else if (g_inf <= tolg)
|
||||||
stop = 2;
|
stop = 2;
|
||||||
|
|
|
||||||
|
|
@ -746,6 +746,8 @@ TCAD.TWO.Constraints.RR = function(arc1, arc2) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TCAD.TWO.Constraints.RR.prototype.NAME = 'RR';
|
TCAD.TWO.Constraints.RR.prototype.NAME = 'RR';
|
||||||
|
TCAD.TWO.Constraints.RR.prototype.reducible = true;
|
||||||
|
|
||||||
|
|
||||||
TCAD.TWO.Constraints.RR.prototype.getSolveData = function() {
|
TCAD.TWO.Constraints.RR.prototype.getSolveData = function() {
|
||||||
return [['equal', [this.arc1.r, this.arc2.r], []]];
|
return [['equal', [this.arc1.r, this.arc2.r], []]];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue