온라인 과정에서 pset를 완료했습니다. 타일을 그리드 주위로 무작위로 움직이는 임의의 봇을 만들었습니다. 각 타일을 순차적으로 청소하고 속도를 1.0으로 설정하면이를 달성하는 봇을 만들고 싶었습니다.속도와 방향에 따라 위치 업데이트
그러나 속도를 1 씩 늘리면 봇이 하나가 아닌 두 위치로 이동하여 각 증가와 직접적인 관련성이 있습니다.
class Pos(object):
"""
A Position represents a location in a two-dimensional room.
"""
def __init__(self, x, y):
"""
Initializes a position with coordinates (x, y).
"""
self.x = x
self.y = y
def getX(self):
return self.x
def getY(self):
return self.y
def getNewPos(self, angle, speed):
"""
Computes and returns the new Position after a single clock-tick has
passed, with this object as the current position, and with the
specified angle and speed.
Does NOT test whether the returned position fits inside the room.
angle: number representing angle in degrees, 0 <= angle < 360
speed: positive float representing speed
Returns: a Po sobject representing the new position.
"""
old_x, old_y = self.getX(), self.getY()
angle = float(angle)
# Compute the change in position
delta_y = speed * math.cos(math.radians(angle))
delta_x = speed * math.sin(math.radians(angle))
# Add that to the existing position
new_x = old_x + delta_x
new_y = old_y + delta_y
return Position(new_x, new_y)
def __str__(self):
return "(%0.2f, %0.2f)" % (self.x, self.y)
은 로봇 이동, 나는 속도를 증가하는 그는 여전히 이동 속도를 증가 것이라고 생각 속도와 양의 관계 란 : 여기
는 새로운 위치를 계산하는 클래스입니다 분명히 그것이 틀렸다는 것을 각 위치를 넘었다 고 생각하십시오.누군가 계산을 어떻게하는지 정확하게 설명 할 수 있을까요? 오랜 시간 죄, 코사인 등을 사용하지 않았습니까? 필요로하는 것을 달성하기 위해 변경할 수 있습니까? 아니면 매우 다른 것을 필요로합니까?
감사합니다. 완전히 다른 접근 방식이 필요합니다. 속도가 계산되는 방식 대신에이 방식이 계산됩니다. 미안하지만 분명하지는 않습니다. 경험이 거의 없습니다. 귀하의 맥락에서 –
을 늘리려는 경우 ** 시간 해상도 ** (** ** 시간 - 델타 ** 감소)입니다. 반대로 속도를 올리면 매번 델타에 걸리는 거리가 늘어납니다. – aha
어떻게하면 좋을까요?이 –