简体   繁体   English

图形编辑器(Java)关于如何在顶点之间绘制边的技巧

[英]Graph Editor (Java) tips on how to draw edges between vertices

For a school assignment we have to make a graph editor like the next one (given example): 对于学校作业,我们必须像下一个一样制作一个图形编辑器(给定示例):

连接图的示例

Most of the assignment goes well, we're stuck on one point: drawing the edges between vertices. 大部分分配工作进展顺利,我们只停留在一点上:在顶点之间绘制边缘。 In the given example, the lines are nicely drawn from points relatively close to the connecting vertex. 在给定的示例中,线条是从相对靠近连接顶点的点很好地绘制的。 For example the top one has two lines on its bottom edge, one more to the left and one more to the right. 例如,顶部的底部边缘有两条线,左边的另一条,右边的另一条。

We are not sure on how to let the drawing of the lines keep the positions of the connecting vertex in account and how to adjust the positions of the beginning and end points on that (what calculations to make). 我们不确定如何让线图考虑连接顶点的位置以及如何调整起点和终点的位置(要进行哪些计算)。 Can someone help out? 有人可以帮忙吗?

In fact, that's rather simple: Draw the lines first , from the position of each vertex to the position of the respective other vertex (the "position" here refers to the center of the rectangle). 实际上,这很简单: 首先绘制线,从每个顶点的位置到各个其他顶点的位置(此处的“位置”是指矩形的中心 )。 Afterwards, draw the rectangles for the vertices. 然后,绘制顶点的矩形。 They will be painted over the edges, and the result will look exactly like the screenshot. 它们将被绘制在边缘上,其结果将与屏幕截图完全一样。

If you extend the connector lines, you can see they are drawn from the geometric center of the graph node rectangles: 如果扩展连接器线,则可以看到它们是从图形节点矩形的几何中心绘制的:

示例连接图,扩展

Since you already seem to have a good positioning algorithm for your nodes, all you need to do is draw the connector lines first. 由于您似乎已经对节点具有良好的定位算法,因此您所需要做的就是首先绘制连接器线。 Then draw the node rectangles on top of them. 然后在其顶部绘制节点矩形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM