小编ht.*_*vit的帖子

浮点计算保持返回0.0

我正在编写一种方法来返回2点之间的点数列表.不管怎样,无论startPoint和endPoint位置如何,斜率(y2-y1)/(x2-x1)始终给我0.0.这是方法:

public ArrayList<Point> calculatePath(Point startPoint, Point endPoint) {
        ArrayList<Point> calculatedPath = new ArrayList<>();
        int x1 = startPoint.x;
        int y1 = startPoint.y;
        int x2 = endPoint.x;
        int y2 = endPoint.y;
        System.out.println("Run");
        if ((x2 - x1) != 0) {
            float ratio = ((y2 - y1) / (x2 - x1));
            System.out.println(ratio);
            int width = x2 - x1;
            for (int i = 0; i < width; i++) {
                int x = Math.round(x1 + i);
                int y = Math.round(y1 + (ratio * i));
                calculatedPath.add(new Point(x, …
Run Code Online (Sandbox Code Playgroud)

java math debugging methods

2
推荐指数
1
解决办法
1682
查看次数

标签 统计

debugging ×1

java ×1

math ×1

methods ×1