首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flot能绘制一个向量场吗?

Flot能绘制一个向量场吗?
EN

Stack Overflow用户
提问于 2016-05-28 14:16:05
回答 1查看 89关注 0票数 2

我有一些JS,它探讨了平面模型的一些性质,以及在自旋晶格中引起相变的机制。相变的一个指标是自旋在晶格中的定向方式,为此,我想画一个矢量场。弗洛能这么做吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-28 20:29:35

是的,只要对flot库做一个小小的更改,就可以做到这一点。在drawSeriesPoints(series)函数中(1986年版本为0.7行)更改行

代码语言:javascript
复制
symbol(ctx, x, y, radius, shadow);

到这个

代码语言:javascript
复制
symbol(ctx, x, y, radius, shadow, series, Math.floor(i / ps));

这样您就可以在绘制数据池时访问它。

在表单[x coordinate, y coordinate, vector angle, vector length]中格式化数据点,并使用如下自定义符号函数:

代码语言:javascript
复制
function vector(ctx, x, y, radius, shadow, series, index) {

  var vectorAngle = series.data[index][2]; // in radians
  var vectorLength = series.data[index][3]; // in pixels

  var bottom = [Math.round(x + vectorLength * Math.sin(vectorAngle)), Math.round(y - vectorLength * Math.cos(vectorAngle))];
  var top = [Math.round(x - vectorLength * Math.sin(vectorAngle)), Math.round(y + vectorLength * Math.cos(vectorAngle))];
  var left = [top[0] - (top[0] - bottom[0]) / 4 + (top[1] - bottom[1]) / 4, top[1] - (top[1] - bottom[1]) / 4 - (top[0] - bottom[0]) / 4];
  var right = [top[0] - (top[0] - bottom[0]) / 4 - (top[1] - bottom[1]) / 4, top[1] - (top[1] - bottom[1]) / 4 + (top[0] - bottom[0]) / 4];

  ctx.beginPath();
  ctx.moveTo(top[0], top[1]);
  ctx.lineTo(left[0], left[1]);
  ctx.lineTo(right[0], right[1]);
  ctx.lineTo(top[0], top[1]);
  ctx.closePath();
  ctx.fillStyle = series.color;
  ctx.fill();

  ctx.beginPath();
  ctx.moveTo(top[0], top[1])
  ctx.lineTo(bottom[0], bottom[1]);
  ctx.stroke();

  ctx.beginPath();
  ctx.moveTo(x, y);
}

完整的例子,如小提琴。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37500052

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档