mirror of
https://github.com/xibyte/jsketcher
synced 2026-02-16 12:24:22 +01:00
P2LDistance implemented
This commit is contained in:
parent
c3237d1b24
commit
085c52c948
4 changed files with 46 additions and 15 deletions
|
|
@ -6,6 +6,7 @@ import cad.gcs.Param;
|
|||
import cad.gcs.Solver;
|
||||
import cad.gcs.constr.Equal;
|
||||
import cad.gcs.constr.EqualsTo;
|
||||
import cad.gcs.constr.P2LDistance;
|
||||
import cad.gcs.constr.Parallel;
|
||||
import cad.gcs.constr.Perpendicular;
|
||||
import gnu.trove.map.TIntObjectMap;
|
||||
|
|
@ -38,7 +39,7 @@ public class SolveServer {
|
|||
|
||||
ResourceHandler rh = new ResourceHandler();
|
||||
rh.setDirectoriesListed(true);
|
||||
rh.setResourceBase("/home/xibyte/Dropbox/project/cadit/web");
|
||||
rh.setResourceBase("/home/verastov/Dropbox/project/cadit/web");
|
||||
handlers.addHandler(rh);
|
||||
|
||||
server.setHandler(handlers);
|
||||
|
|
@ -115,6 +116,9 @@ class SolveHandler extends AbstractHandler {
|
|||
case "parallel":
|
||||
constraints.add(new Parallel(h.get(0), h.get(1), h.get(2), h.get(3), h.get(4), h.get(5), h.get(6), h.get(7)));
|
||||
break;
|
||||
case "P2LDistance":
|
||||
constraints.add(new P2LDistance(constants.getDouble(0), h.get(0), h.get(1), h.get(2), h.get(3), h.get(4), h.get(5)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ public class GlobalSolver {
|
|||
int count = 0;
|
||||
|
||||
solveLM_COMMONS(subSystem);
|
||||
// Solver.solve_BFGS(subSystem, false);
|
||||
// Solver.solve_DL(subSystem);
|
||||
// Solver.solve_LM(subSystem);
|
||||
|
||||
linearSolvedCallback.run();
|
||||
if (true) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ TCAD.App2D = function() {
|
|||
},
|
||||
|
||||
P2LDistance : function() {
|
||||
app.viewer.parametricManager.p2lDistance(app.viewer.selected);
|
||||
app.viewer.parametricManager.p2lDistance(app.viewer.selected, prompt);
|
||||
}
|
||||
};
|
||||
actionsF.add(actions, 'addSegment');
|
||||
|
|
|
|||
|
|
@ -28,6 +28,25 @@ TCAD.TWO.ParametricManager.prototype._fetchTwoPoints = function(objs) {
|
|||
};
|
||||
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchPointAndLine = function(objs) {
|
||||
|
||||
var point = null;
|
||||
var line = null;
|
||||
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
if (objs[i]._class == 'TCAD.TWO.EndPoint') {
|
||||
point = objs[i];
|
||||
} else if (objs[i]._class == 'TCAD.TWO.Segment') {
|
||||
line = objs[i];
|
||||
}
|
||||
}
|
||||
if (point == null || line == null) {
|
||||
throw "Illegal Argument. Constraint requires point and line."
|
||||
}
|
||||
|
||||
return [point, line];
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchTwoLines = function(objs) {
|
||||
var lines = [];
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
|
|
@ -61,19 +80,23 @@ TCAD.TWO.ParametricManager.prototype.perpendicular = function(objs) {
|
|||
this.add(new TCAD.TWO.Constraints.Perpendicular(lines[0], lines[1]));
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.p2lDistance = function(objs) {
|
||||
var target = null;
|
||||
var segment = null;
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
if (objs[i]._class == 'TCAD.TWO.EndPoint') {
|
||||
target = objs[i];
|
||||
} else if (objs[i]._class == 'TCAD.TWO.Segment') {
|
||||
segment = objs[i];
|
||||
TCAD.TWO.ParametricManager.prototype.p2lDistance = function(objs, promptCallback) {
|
||||
var pl = this._fetchPointAndLine(objs);
|
||||
|
||||
var target = pl[0];
|
||||
var segment = pl[1];
|
||||
|
||||
var ex = new TCAD.Vector(-(segment.b.y - segment.a.y), segment.b.x - segment.a.x).normalize();
|
||||
var distance = Math.abs(ex.dot(new TCAD.Vector(segment.a.x - target.x, segment.a.y - target.y)));
|
||||
|
||||
var promptDistance = promptCallback("Enter the distance", distance.toFixed(2));
|
||||
|
||||
if (promptDistance != null) {
|
||||
promptDistance = Number(promptDistance);
|
||||
if (promptDistance == promptDistance) { // check for NaN
|
||||
this.add(new TCAD.TWO.Constraints.P2LDistance(target, segment, promptDistance));
|
||||
}
|
||||
}
|
||||
if (target == null || segment == null) {
|
||||
throw "Illegal Argument. P2LDistance requires point and line."
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.coincident = function(objs) {
|
||||
|
|
@ -184,9 +207,9 @@ TCAD.TWO.Constraints.Perpendicular.prototype.getSolveData = function() {
|
|||
return ['perpendicular', params, []];
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.P2LDistance = function(l, p, d) {
|
||||
this.l = l;
|
||||
TCAD.TWO.Constraints.P2LDistance = function(p, l, d) {
|
||||
this.p = p;
|
||||
this.l = l;
|
||||
this.d = d;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue