小编Ale*_*der的帖子

How can I manually place networkx nodes using the mouse?

I have a fairly large and messy network of nodes that I wish to display as neatly as possible.

This is how it's currently being displayed: 例子

First, I tried playing with the layout to see if it could generate a good output automatically.

I have tried many different nx layouts, but they all display similar results. I have also tried answers from all of these stack exchange questions:

How to increase node spacing for networkx.spring_layout

Drawing a huge graph with …

python networkx python-3.x

5
推荐指数
1
解决办法
1440
查看次数

使用矢量将重力添加到弹跳球

我有一个重力矢量(形式为[r,theta]),我加入了我的球的速度矢量.由于某种原因,球在弹跳后不会返回到相同的高度,而是偶尔慢慢地失去高度.我猜测有一些舍入错误或我正在使用的计算中的某些内容,但我无法隔离问题.

这是我的代码.你需要文件和pygame来运行它.对不起,如果有点混乱.如果你愿意,我可以发表更多评论.

每当球到达最大高度时我都会添加一个标记,所以你们就是我的意思.我希望每次弹跳时球都能恢复到完全相同的高度.

我拿了一些不必要的代码.完整的程序在pastebin链接下.


https://pastebin.com/FyejMCmg - PhysicsSim

import pygame, sys, math, tools, random, time
from pygame.locals import *

clock = pygame.time.Clock()
lines = []

class Particle:
    def __init__(self,screen,colour, mass, loc, vel):
        self.screen = screen
        self.colour = colour

        self.mass = mass

        self.x = loc[0]
        self.y = loc[1]
        self.location = self.x,self.y
        self.speed = vel[0]
        self.angle = vel[1]


    def update(self):
        global lines

        # add gravity
        self.speed,self.angle = tools.add_vectors2([self.speed,self.angle], tools.GRAVITY)

        # update position
        dt = clock.tick(60)
        self.x += self.speed * tools.SCALE * math.cos(self.angle) * …
Run Code Online (Sandbox Code Playgroud)

python pygame game-physics

4
推荐指数
1
解决办法
437
查看次数

标签 统计

python ×2

game-physics ×1

networkx ×1

pygame ×1

python-3.x ×1