基于力的图形绘制算法中对边缘充电?

发布于 2025-01-06 19:12:44 字数 526 浏览 5 评论 0原文

我正在尝试用 Python 编写一个简短的小程序,它可以使用 force-基于算法的图形绘制。

我正在尝试尽量减少线条相交的次数。维基百科建议给这些线带上电荷,以便它们相互排斥。我问我的物理老师如何模拟这个,她提到使用微积分和库仑定律,但我不确定如何开始。

有人可以给我一个提示,告诉我如何做到这一点吗? (或者,另一种方法来调整基于力的图形绘制算法以最小化线条交叉的次数?)我只是在寻找提示;没有源代码请。

如果有人感兴趣,我的源代码和<我制作了一个 href="http://www.youtube.com/watch?v=CFynirN0vPA" rel="nofollow">youtube vid 。

I'm attempting to write a short mini-program in Python that plays around with force-based algorithms for graph drawing.

I'm trying to minimize the number of times lines intersect. Wikipedia suggests giving the lines an electrical charge so that they repel each other. I asked my physics teacher how I might simulate this, and she mentioned using calculus with Coulomb's Law, but I'm uncertain how to start.

Could somebody give me a hint on how I could do this? (Or alternatively, another way to tweak a force-based graph drawing algorithm to minimize the number of times the lines cross?) I'm just looking for a hint; no source code please.

In case anybody's interested, my source code and a youtube vid I made about it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长不大的小祸害 2025-01-13 19:12:44

您需要在成本函数中明确包含一个项,以最大限度地减少边交叉的数量。例如,对于每对交叉的边,您都会受到固定的惩罚,或者,如果边被加权,您会受到两个权重乘积的惩罚。

You need to explicitly include a term in your cost function that minimizes the number of edge crossings. For example, for every pair of edges that cross, you incur a fixed penalty or, if the edges are weighted, you incur a penalty that is the product of the two weights.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文