0

I have JavaFX project and I need coordinates of each dot in the orange line from image bellow.

https://i.stack.imgur.com/A7zVa.png

I spent a lot of hours googling but I can not find a solution.

It is a simple application. I need those coordinates beacuse I need to make G CODE for CNC machine.

My Code is:


public class KS2 extends Application {

    private LineChart<Number, Number> chart;

    @Override
    public void start(Stage primaryStage) throws Exception {
        final NumberAxis xAxis = new NumberAxis(0.0, 150.0, 2);
        final NumberAxis yAxis = new NumberAxis(0.0, 100.0, 2);

        // Flip the axis
        // yAxis.setScaleY(-1);
        Rectangle r = new Rectangle(0, 0, 80, 50);

        r.setFill(Color.TRANSPARENT);
        r.setStrokeWidth(0.5);
        r.setStroke(Color.BLACK);

        this.chart = new LineChart<Number, Number>(xAxis, yAxis) {
            @Override
            public void layoutPlotChildren() {
                super.layoutPlotChildren();
                r.getTransforms().setAll(chartDisplayTransform(xAxis, yAxis));
                // note nodes don't get removed from the plot children, and this method may be
                // called often:
                if (!getPlotChildren().contains(r)) {
                    getPlotChildren().add(r);
                }
            }
        };
        this.chart.setAnimated(false);

        XYChart.Series series = new XYChart.Series();
        series.getData().add(new XYChart.Data(54, 50));
        series.getData().add(new XYChart.Data(80, 0));
        //series.setName("My portfolio");
        this.chart.getData().add(series);
        
        VBox vbox = new VBox(this.chart);

        Scene scene = new Scene(vbox, 400, 200);
        primaryStage.setScene(scene);
        primaryStage.setHeight(600);
        primaryStage.setWidth(400);
        primaryStage.show();
    }

    private Transform chartDisplayTransform(NumberAxis xAxis, NumberAxis yAxis) {
        return new Affine(xAxis.getScale(), 0, xAxis.getDisplayPosition(0), 0, yAxis.getScale(),
                yAxis.getDisplayPosition(0));
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
} 

Coder D.
  • 1
  • 3
  • 1
    Find (or write) a java implementation of [Bresenham's line algorithm](https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#:~:text=From%20Wikipedia%2C%20the%20free%20encyclopedia%20Bresenham%27s%20line%20algorithm,approximation%20to%20a%20straight%20line%20between%20two%20points.) – jewelsea Feb 17 '22 at 14:00
  • For a straight line, use the [point–slope form](https://en.wikipedia.org/wiki/Linear_equation#Point–slope_form_or_Point-gradient_form) to interpolate, for [example](https://stackoverflow.com/a/61398612/230513). – trashgod Feb 17 '22 at 23:33

0 Answers0