本文介绍了在图节点之间画线有哪些好的算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我特别要处理的不仅仅是图形的布局,而是当用户选择图形节点并开始将其拖到屏幕区域周围时,必须不断重画线以反映其外观就像 if 一样,用户将释放节点。我想这是布局算法的一部分吗?What I'm specifically grappling with is not just the layout of a graph, but when a user selects a graph node and starts to drag it around the screen area, the line has to constantly be redrawn to reflect what it would look like if the user were to release the node. I suppose this is part of the layout algorithm?另外,某些应用程序看起来有点花哨,而不是简单地以曲线优美的方式画线,而且还以几乎直角围绕矩形节点弯曲线。请参见所附图像,并记住当拖动节点时,线条将作为行进的蚂蚁绘制,并且在保持其弯曲样式的同时进行了很好的重新排列。Also some applications get a bit fancy and don't simply draw the line in a nice curvy way, but also bend the line around the square shaped node in almost right angles. See attached image and keep in mind that as a node is dragged, the line is drawn as marching ants, and re-arranged nicely, while retaining its curved style. 替代文字http://img260.imageshack.us/img260/5458/nodesr.png推荐答案如果您的图表不是很疯狂,则无需为此使用额外的花哨算法,而只需使用一些常识即可。If your diagrams are not crazy full you should not need an extra-fancy algorithm for this, but just use some common sense. 用矩形网格覆盖表面,然后找到一种方法以最小的角度沿网格线连接到具有直线的盒子:如果盒子不在同一条网格线上,并且您不在乎连接的位置,则如果它们之间没有其他节点,则需要一个角度。如果有节点,您至少需要再增加一个角度。Cover the surface with a rectangular grid and then find a way to connect to boxes with straight lines along grid lines with a minimum number of angles: if the boxes are not on the same grid lines and you don't care where you connect you need one angle if there is no other node in between. If there are e.g. nodes in the way you need at least one more angle.作为更完整图的第二步,添加的代码不仅可以优化最小数量的边,而且还可以优化线的最小长度。如果您的图表还不够疯狂,那么就应用程序响应而言,这应该就不太明显了。As a second step for fuller diagrams add code that not only optimizes for minimal number of edges but also for minimal length of the lines. If your diagrams are not crazy full this should be hardly noticeable in terms of application response.为使角度更加圆润,请考虑两个角度的长度腿,并检查是否与表面上的其他对象相交。我将使用90°的圆并调整圆的半径(显然不是上面所做的)-对于较长的腿,半径应该更大。也许您使用的工具包可以在这里为您提供帮助。For extra eye candy round the angles taking into account the lengths of both legs and checking for intersections with other objects on the surface. I would use 90°-pies of circles and adjust the radius of the circles (apparently not what was done above) -- for longer legs the radius should be bigger. Maybe the toolkit you are using can help you here. 这篇关于在图节点之间画线有哪些好的算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!