自动化立体仓库 - WMS系统
pang.jiabao
2 天以前 ddc6cd417d5e912d5cba297bb7849a1dcf7367be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.zy.asrs.utils;
 
import java.util.ArrayList;
import java.util.List;
 
public class Point {
    public double x;
    public double y;
 
    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }
 
    public double distance(Point other) {
        double dx = this.x - other.x;
        double dy = this.y - other.y;
        return Math.sqrt(dx*dx + dy*dy);
    }
 
    public double angle(Point other) {
        double dx = other.x - this.x;
        double dy = other.y - this.y;
        return Math.atan2(dy, dx);
    }
 
    public Point interpolate(Point other, double t) {
        double newX = this.x + t * (other.x - this.x);
        double newY = this.y + t * (other.y - this.y);
        return new Point(newX, newY);
    }
 
    public static List<Point> interpolate(Point p1, Point p2, double interval) {
        List<Point> points = new ArrayList<>();
        double distance = p1.distance(p2);
        double angle = p1.angle(p2);
 
        for (double t=interval/distance; t<1; t+=interval/distance) {
            Point p = p1.interpolate(p2, t);
            points.add(p);
        }
 
        return points;
    }
}