Ejemplo n.º 1
0
    def fromPoints(cls, point1: Union[Vector2D, tuple], point2: Union[Vector2D,
                                                                      tuple]):
        """Create a line from points with a limited domain.

            Create a line from two vectors or tuples.
            The domain will be limited to the two points including.

            Args:
                a: `Vector2D | tuple` Point A of the line
                b: `Vector2D | tuple` Point B of the line

            Returns:
                `linline` A linear line with a limited domain.
        """
        if (type(point1) == tuple):
            point1 = Vector2D.fromTuple(point1)

        if (type(point2) == tuple):
            point2 = Vector2D.fromTuple(point2)

        r = point2 - point1
        n = r.toNormalVector()
        a = round(n.x, 3)
        b = round(n.y, 3)
        c = n @ point1

        limit = [point1.x, point2.x] if b != 0 else [point1.y, point2.y]
        return cls(a, b, c, limit=limit)
Ejemplo n.º 2
0
    def __init__(self, cars, circ, window, load=False, car_scale=1.48) -> None:
        self.window = Vector2D.fromTuple(window)
        self.circuit = circ
        self.carX = self.circuit.startingPoint.x
        self.carY = self.circuit.startingPoint.y
        self.carList = [
            Agent(self.carX, self.carY, window=self.window, scale=car_scale)
            for _ in range(cars)
        ]
        self.oldCarList = []
        self.show = False
        self.showA = True
        self.carCount = cars

        self.fitnessSum = 0
        self.gen = 1
        self.autoGen = 1

        self.bestCar = 0
        self.oldBestAgent = self.carList[self.bestCar]
        self.bestCarPosition = Vector2D(0, 0)
        self.oldBestCount = 0

        self.maxStep = 1000
        self.load = load
        self.row = None
        self.blindSpots = []
        self.blindIndex = []
        self.addBlindSpot()
Ejemplo n.º 3
0
    def __init__(self, dots, window) -> None:
        self.window = Vector2D.fromTuple(window)
        self.goal = self.window
        self.dotList = [
            Dot(window=self.window, goal=(self.goal - Vector2D(10, 10)))
            for _ in range(dots)
        ]

        self.fitnessSum = 0
        self.gen = 1

        self.bestDot = 0

        self.minStep = 1000
Ejemplo n.º 4
0
    def fromPoints(cls, a: Union[Vector2D, tuple], b: Union[Vector2D,
                                                            tuple]) -> linline:
        """Create a line from points with a limited domain.

            Create a line from two vectors or tuples.
            The domain will be limited to the two points including.

            Args:
                a: `Vector2D | tuple` Point A of the line
                b: `Vector2D | tuple` Point B of the line

            Returns:
                `linline` A linear line with a limited domain.
        """
        if (type(a) == tuple):
            a = Vector2D.fromTuple(a)

        if (type(b) == tuple):
            b = Vector2D.fromTuple(b)

        if (not a.y == b.y) and (not a.x == b.x):
            rc = (b.y - a.y) / (b.x - a.x)
            p = a.y - rc * a.x
        elif (a.y == b.y):
            rc = 0
            p = a.y
        else:
            rc = 1e10
            p = -a.x * 1e10

            limit = [a.x, b.x]
            line = cls(rc, p, sorted(limit))
            line.vertical = [a.y, b.y]
            return line

        limit = [a.x, b.x]
        return cls(rc, p, sorted(limit))
Ejemplo n.º 5
0
    def _calculatePhysics(self, dt):
        #Calculate acceleration based on forces and limit it to 100 pixels per second per second
        self.acceleration = self.forces.rotate(self.carRotation.rotation()) / self.mass
        self.acceleration.limit(200)

        #Calculate velocity based on accelation and limit it to 200 pixels per second
        self.velocity += self.acceleration * dt
        self.velocity.limit(200)
        
        #Determine if we are driving backwards or forwards
        backwards = (self.velocity @ self.carRotation < 0)

        self.position += self.velocity * dt
        if not backwards:
            self.carRotation = self.velocity.copy()
        else:
            self.carRotation = -self.velocity.copy()
        
        self.middle = self.position + Vector2D.fromTuple(self.image_dimensions).rotate(self.carRotation.rotation()) * self.scale * 0.5
Ejemplo n.º 6
0
    def __init__(self, cars, carX, carY, window) -> None:
        self.window = Vector2D.fromTuple(window)
        self.goal = self.window
        self.carX = carX
        self.carY = carY
        self.carList = [
            Agent(carX,
                  carY,
                  window=self.window,
                  goal=(self.goal - Vector2D(10, 10))) for _ in range(cars)
        ]
        self.show = False
        self.showA = True

        self.fitnessSum = 0
        self.gen = 1

        self.bestCar = 0

        self.minStep = 1000