javascript - 使用来自服务器的数据在客户端绘制曲线
问题描述
需要实现图形插值。我计划这样做是在服务器端进行计算,然后将数据传输到客户端,并绘制图形。但我不明白如何做到这一点?我通过插值找到点,但是如何获得漂亮的插值曲线?毕竟,这些点将连接并得到一条折线。我不明白什么?下面是插值代码。
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));
}
}
解决方案
推荐阅读
- node.js - 用于 TypeScript Mocha 测试的 Vscode 断点
- javascript - .each 函数不在最后一个元素上运行
- c++ - 如何使用cpp编写对元素列表进行降序排序的选择排序算法?
- javascript - 用 TypeScript 编写时如何查看 Deno 转译的 javascript?
- zeromq - ZMQ 多发布者和单订阅者——观察到数据丢失
- html - 如何设置画布的响应宽度和高度?
- node.js - 如何一次运行多个猫鼬查询并使用 expressjs 生成 json 响应
- python - 使用 JDBC + 参数化 SQL 查询 + Databricks 的 SQL 数据库
- angular - Angular 不是已知元素:在同一个模块中
- python - python 3.X更改文件的偏移量06和07