使用Radial Positions algorithm从这个问题转换为 python 的 C ,我已经成功地创建了一个基于根节点的径向图,一直到每个节点的最后一个子节点。现在我有一个新问题,我有多个根节点,需要它们以找到的第一个根为中心,或者至少是一个中心点。
我发现的最接近的例子是这张图:
到目前为止,我能想到的就是对于找到的每个根节点,将其乘以它的索引,然后将 x 位置与 y 半径相加。到目前为止,它的效果还不是很好,因为我的子节点没有遵循它。我已经被这个问题难住了几天了。
def RadialPositions(node, id):
children_in_node = len(timelinedatta.neighbors(id, mode="out"))
def rotate_node(x, y, nangle):
nx = x * math.cos(nangle) - y * math.sin(nangle)
ny = x * math.sin(nangle) + y * math.cos(nangle)
return nx, ny
def get_depth(id):
count = 0
for v in timelinedatta.bfsiter(id, mode="in", advanced=True):
count = count + 1
return count - 1
if len(timelinedatta.neighbors(id, mode="out")) > 0 and len(timelinedatta.neighbors(id, mode="in")) == 0:
node["positions"] …Run Code Online (Sandbox Code Playgroud)