diff --git a/misc/octave-core b/misc/octave-core new file mode 100644 index 00000000..453a3d15 Binary files /dev/null and b/misc/octave-core differ diff --git a/misc/proto.m b/misc/proto.m new file mode 100644 index 00000000..0bcc6080 --- /dev/null +++ b/misc/proto.m @@ -0,0 +1,72 @@ +pkg load optim; + +l1p1x = 1; +l1p1y = 2; +l1p2x = 3; +l1p2y = 4; +l2p1x = 5; +l2p1y = 6; +l2p2x = 7; +l2p2y = 8; + +function out = g (x) + +l1p1x = 1; +l1p1y = 2; +l1p2x = 3; +l1p2y = 4; +l2p1x = 5; +l2p1y = 6; +l2p2x = 7; +l2p2y = 8; + p = x{1}; + out = [ + (p(l2p1y) - p(l2p2y)); + -(p(l2p1y) - p(l2p2y)); + (p(l2p1x) - p(l2p2x)); + -(p(l2p1x) - p(l2p2x)); + (p(l1p1y) - p(l1p2y)); + -(p(l1p1y) - p(l1p2y)); + (p(l1p1x) - p(l1p2x)); + -(p(l1p1x) - p(l1p2x)); + ]; + +endfunction + +function out = phi (x) + +l1p1x = 1; +l1p1y = 2; +l1p2x = 3; +l1p2y = 4; +l2p1x = 5; +l2p1y = 6; +l2p2x = 7; +l2p2y = 8; + p = x{1}; + dx1 = (p(l1p1x) - p(l1p2x)); + dy1 = (p(l1p1y) - p(l1p2y)); + dx2 = (p(l2p1x) - p(l2p2x)); + dy2 = (p(l2p1y) - p(l2p2y)); + #dot product shows how the lines off to be perpendicular + off = dx1 * dx2 + dy1 * dy2; + out = off * off; +endfunction + + + +l1 = [100, 100; 300, 600]; +l2 = [400, 600; 600, 100]; + + +x0 = [l1(1,1);l1(1,2);l1(2,1);l1(2,2); l2(1,1);l2(1,2);l2(2,1);l2(2,2)]; + +#[x, obj, info, iter, nf, lambda] = sqp (x0, @phi, @g, []); + +[a,b,c] = cg_min (@phi, @g, x0); + + +#plot([l1(1), l1(2)], [l1(3), l1(4)], '-'); +#plot(reshape(l2, 2, 2)); +plot(l1(:,1), l1(:,2), l2(:,1), l2(:,2), '-'); + diff --git a/src/cad/fx/App2D.java b/src/cad/fx/App2D.java new file mode 100644 index 00000000..229fd0e2 --- /dev/null +++ b/src/cad/fx/App2D.java @@ -0,0 +1,22 @@ +package cad.fx; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class App2D extends Application { + + public static void main(String[] args) { + System.setProperty("prism.dirtyopts", "false"); + launch(args); + } + + @Override + public void start(Stage primaryStage) throws Exception { + Scene scene = new Scene(FXMLLoader.load(AppCtrl.class.getResource("app2d.fxml")), 1024, 1100); + primaryStage.setTitle("Sketch"); + primaryStage.setScene(scene); + primaryStage.show(); + } +} diff --git a/src/cad/fx/App2DCtrl.java b/src/cad/fx/App2DCtrl.java new file mode 100644 index 00000000..304beae1 --- /dev/null +++ b/src/cad/fx/App2DCtrl.java @@ -0,0 +1,75 @@ +package cad.fx; + +import cad.gcs.Constraint; +import cad.gcs.Solver; +import cad.gcs.constr.Perpendicular; +import cad.math.Vector; +import javafx.event.ActionEvent; +import javafx.fxml.Initializable; +import javafx.scene.Group; +import javafx.scene.control.Button; +import javafx.scene.layout.Pane; +import javafx.scene.shape.Line; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; +import java.util.ResourceBundle; + +public class App2DCtrl implements Initializable { + + private final CadContext cadContext = new CadContext(); + + public Pane viewer; + public Button solve; + + @Override + public void initialize(URL location, ResourceBundle resources) { + Group content = new Group(); + setInitObject(content); + viewer.getChildren().setAll(content); + + + Line l1 = new Line(100, 100, 300, 600); + Line l2 = new Line(400, 600, 600, 100); + content.getChildren().addAll(l1, l2); + + + solve.setOnAction(event -> { + + Vector a1 = new Vector(l1.getStartX(), l1.getStartY()); + Vector b1 = new Vector(l1.getEndX(), l1.getEndY()); + Vector a2 = new Vector(l2.getStartX(), l2.getStartY()); + Vector b2 = new Vector(l2.getEndX(), l2.getEndY()); + Perpendicular perpendicular = new Perpendicular(a1, b1, a2, b2); + + List parallels = Arrays.asList(perpendicular); + Solver.SubSystem subSystem = new Solver.SubSystem(parallels); + Solver.solve_DL(subSystem); + + perpendicular.out(a1, b1, a2, b2); + + l1.setStartX(a1.x); + l1.setStartY(a1.y); + l1.setEndX(b1.x); + l1.setEndY(b1.y); + + l2.setStartX(a2.x); + l2.setStartY(a2.y); + l2.setEndX(b2.x); + l2.setEndY(b2.y); + }); + + } + + private void solve(ActionEvent e) { + +// UnconstrainedLeastSquares opt = FactoryOptimization.leastSquaresTrustRegion(100, RegionStepType.DOG_LEG_FTF, false); + + } + + private void setInitObject(Group parent) { +// CSG init = new Cube(100).toCSG().difference(new Cylinder(30, 100, 10).toCSG()); +// return new CSGNode(Utils3D.getFXMesh(init), cadContext); + } +} diff --git a/src/cad/fx/app2d.fxml b/src/cad/fx/app2d.fxml new file mode 100644 index 00000000..dea147e3 --- /dev/null +++ b/src/cad/fx/app2d.fxml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + +