首页 > 解决方案 > 使用来自服务器的数据在客户端绘制曲线

问题描述

需要实现图形插值。我计划这样做是在服务器端进行计算,然后将数据传输到客户端,并绘制图形。但我不明白如何做到这一点?我通过插值找到点,但是如何获得漂亮的插值曲线?毕竟,这些点将连接并得到一条折线。我不明白什么?下面是插值代码。

class Main {
    // Data point
    static class Data {
        int x, y;
        public Data(int x, int y) {
            super();
            this.x = x;
            this.y = y;
        }
    };
    static double interpolate(Data f[], int xi, int n) {
        double result = 0;
        for (int i = 0; i < n; i++) {
            double term = f[i].y;
            for (int j = 0; j < n; j++) {
                if (j != i) {
                    term = term * (xi - f[j].x) / (f[i].x - f[j].x);
                }
            }
            result += term;
        }
        return result;
    }
    public static void main(String[] args) {
        Data f[] = {
                new Data(0, 2),
                new Data(1, 3),
                new Data(2, 12),
                new Data(5, 147)};
        System.out.print("Value of f(3) is : " + (int) interpolate(f, 3, 4));
    }
}

标签: javascriptjavagraphics

解决方案


推荐阅读