我必须让一个球体以无限符号的形状移动,以我的计算机图形课.
我想我已经成功地在下面的Python程序中重新创建了球体的精确运动,如任务图所示.
以下是结果:
The sphere following a path in the shape of the number eight
我的问题是
我的程序需要做一些事情来实现这一点:
-
我得画两个球体的模型.一个位于(-8,4,0),另一个位于(7,-3,0).我这样做是为了将球体放置在与原点不同的两个坐标周围.
-
我让第一个模型绕坐标(-8,4,0)旋转,直到它做了一个半循环.之后,我把它改为原点在(7,-3,0)的第二个模型,它一直旋转,直到它做了一个完整的循环.一旦它发生,我再次将其更改为第一个模型,并做一个完整的循环和半.它再次重复,从而遵循一个无限符号的轨迹.
这就是我在我的python程序中所做的
run = True
angle = 0
x_position = -8
y_position = 4
points_matrix = generate_sphere_points(x0=x_position, y0=y_position, z0=0)
points_matrix2 = generate_sphere_points(x0=-x_position-1, y0=-y_position+1, z0=0)
index = False
matrices_points = [points_matrix, points_matrix2]
delta_angle = -4
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
draw_world_axes()
glLineWidth(1)
glTranslatef(x_position, y_position, 0)
glRotatef(angle, 0, 0, 1)
plot_parametric_mesh(matrices_points[index])
pygame.display.flip()
pygame.time.wait(10)
if angle <= -180 or angle >= 180:
index = not index
x_position = -x_position - 1
y_position = -y_position + 1
delta_angle *= -1
angle += delta_angle
pygame.quit()
当它工作时,我认为你只需要一个球体模型.然而,我还没有弄清楚如何使球体甚至物体绕着一个不同于原点的坐标(0,0,0)旋转,而不需要在创建 timeshift 动该物体.我知道你可以用glRotatef()*glTranslatef()
来使物体绕原点旋转,但我想要的是它绕着我指定的坐标旋转.
在这种情况下,创建一个绕一个坐标旋转的球体模型,然后将其中心切换到不同的坐标,并在整个8循环中重复.
有没有人知道我如何让一个球围绕一个坐标旋转,只是使用变换矩阵(fittef和rotatef),而不必改变球的参数方程中心,并且只使用一个球的模型来做8循环,而不是交换两个模型?