了解Javascript D3可视化四叉树 [英] Understanding Javascript D3 visualization quadtree

查看:140
本文介绍了了解Javascript D3可视化四叉树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用并了解 D3可视化库(http://mbostock.github .com / d3 /),我正在看他们的部队指示代码,似乎他们正在使用四叉树来计算粒子上的力。代码是

I am trying to use and understand the D3 visualization library (http://mbostock.github.com/d3/), and I am looking at their force directed code and it seems they are using a quadtree to calculate the force on a particle. The code is

      var k = kc * quad.count * dn * dn;
      node.px -= dx * k;
      node.py -= dy * k;

这里看起来很像quad.count是四叉树节点中的粒子数。但是在四叉树代码 https://github.com/mbostock/d3/blob/master/d3.geom.js#L696\"rel =nofollow> https://github.com/mbostock/d3/blob/master/d3.geom .js#L696 ,我找不到对 count 的任何引用,以及它是如何计算的。我问,因为我想修改一些东西,或许可以改变每个节点的重量或费用。

where it seems thay quad.count is the number of particles in the quadtree node. But looking at their quadtree code in https://github.com/mbostock/d3/blob/master/d3.geom.js#L696, I can't find any reference to count, and how it is being calculated. I ask because I want to modify some things to perhaps change the "weight" or "charge" of each node.

推荐答案

Take看一下 d3_layout_forceAccumulate 方法:

Take a look at the d3_layout_forceAccumulate method:

https://github.com/mbostock/d3/blob/master/src/layout/force.js#L294-324

四叉树本身不计算其粒子的电荷中心(因为四叉树只知道粒子位置,并且不对其电荷做任何假设)。生成四叉树后,力布局递归计算每个象限的电荷中心。

The quadtree by itself doesn't compute the center of charge for its particles (because the quadtree only knows about particle positions, and doesn’t make any assumptions about their charges). After the quadtree is generated, the force layout recursively computes the center of charge for each quadrant.

这篇关于了解Javascript D3可视化四叉树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆