示例#1
0
    def test_velocity_rear(self):

        point = Point(Vector2D(-10, 0))
        velocity = point.total_velocity(Vector2D(0, 0), 3)

        self.assertAlmostEqual(-0.524, velocity.y, 3)
        self.assertAlmostEqual(0, velocity.x)
示例#2
0
    def __init__(self, point: Point):
        super(NanoBot, self).__init__()
        self.dest = point
        self.point = Point(0, 0, point.visible)

        self.angle = self.point.angle(self.dest)
        self.speed = Speed()
示例#3
0
    def __init__(self, name,
                 relative_pos=Vector2D(0, 0),
                 chord_length=1,
                 angle=Angle(0),
                 area=1,
                 lift_curve=None,
                 drag_curve=None,
                 atmosphere=Atmosphere()):

        self._point = Point(relative_pos)

        self.name = name
        self.angle = angle
        self.area = area
        self._atmosphere = atmosphere

        self.lift_curve = lift_curve
        self.drag_curve = drag_curve

        if lift_curve is not None:
            stall_angle = lift_curve.stall_angle()
        else:
            stall_angle = None

        self.cp = CP(relative_pos, chord_length, stall_angle)

        self.velocity = Vector2D(0, 0)
        self.current_cp = Vector2D(0, 0)
示例#4
0
    def test_velocity_2_rotations(self):
        point = Point(Vector2D(10, 0))

        # rotate 360 degree / second
        velocity = point.total_velocity(Vector2D(0, 0), 720)

        # speed = circumference
        speed = 4 * math.pi * 10

        self.assertAlmostEqual(speed, velocity.y, 3)
        self.assertAlmostEqual(0, velocity.x)
示例#5
0
class NanoBot(object):
    def __init__(self, point: Point):
        super(NanoBot, self).__init__()
        self.dest = point
        self.point = Point(0, 0, point.visible)

        self.angle = self.point.angle(self.dest)
        self.speed = Speed()

    def moveto(self, point: Point):
        self.dest = point
        self.angle = Point(0, 0).angle(self.dest)
        # self.speed = Speed()

    def update(self):
        # thee goal is to get to the the point from dest
        if not inrange(self.point.x, self.dest.x, self.speed.value):
            if self.point.x < self.dest.x:
                self.point.x += (
                    20 * math.radians(math.sin(self.angle))) + self.speed.value
            else:
                self.point.x -= (
                    20 * math.radians(math.sin(self.angle))) + self.speed.value

        if not inrange(self.point.y, self.dest.y, self.speed.value):
            if self.point.y < self.dest.y:
                self.point.y += (
                    20 * math.radians(math.cos(self.angle))) + self.speed.value
            else:
                self.point.y -= (
                    20 * math.radians(math.cos(self.angle))) + self.speed.value
示例#6
0
 def fromfile(self, filename):
     with open(filename) as file:
         content = file.read().strip("\n").split("\n")
     for i, line in enumerate(content):
         for j, data in enumerate(line):
             if data == "*":
                 self.FILEDATA.append(
                     Point(
                         x=(UnusualMatrix.START_X +
                            (j * UnusualMatrix.SPACE)),
                         y=(UnusualMatrix.START_Y +
                            (i * UnusualMatrix.SPACE)),
                     ))
     return self
示例#7
0
 def _plan(self):
     bot_create = 0
     for i in range(UnusualMatrix.SIZE):
         for j in range(UnusualMatrix.SIZE):
             if not bot_create == len(Planner.BOTS):
                 if self.CONDITION(i, j):
                     bot = Planner.BOTS[bot_create]
                     bot.speed = Speed()
                     bot.moveto(
                         Point(
                             x=(UnusualMatrix.START_X +
                                (j * UnusualMatrix.SPACE)),
                             y=(UnusualMatrix.START_Y +
                                (i * UnusualMatrix.SPACE)),
                         ))
                     bot_create += 1
                 continue
         if bot_create == len(Planner.BOTS): break
示例#8
0
    def plan(self):
        if not Planner.PLANNING:
            Planner.PLANNING = True
            if not self.FILEDATA:
                self._plan()
            else:
                bots = (bot for bot in Planner.BOTS)
                i = 0

                for bot in bots:
                    try:
                        bot.moveto(self.FILEDATA[i])
                        i += 1
                    except IndexError:
                        break

                for bot in bots:
                    bot.moveto(Point(-10, -10))

            Planner.PLANNING = False
示例#9
0
 def moveto(self, point: Point):
     self.dest = point
     self.angle = Point(0, 0).angle(self.dest)
示例#10
0
class Surface:
    ''' A plane has multiple services that generate lift
    and drag forces'''

    def __init__(self, name,
                 relative_pos=Vector2D(0, 0),
                 chord_length=1,
                 angle=Angle(0),
                 area=1,
                 lift_curve=None,
                 drag_curve=None,
                 atmosphere=Atmosphere()):

        self._point = Point(relative_pos)

        self.name = name
        self.angle = angle
        self.area = area
        self._atmosphere = atmosphere

        self.lift_curve = lift_curve
        self.drag_curve = drag_curve

        if lift_curve is not None:
            stall_angle = lift_curve.stall_angle()
        else:
            stall_angle = None

        self.cp = CP(relative_pos, chord_length, stall_angle)

        self.velocity = Vector2D(0, 0)
        self.current_cp = Vector2D(0, 0)

    def aoa(self, velocity):
        vel_angle = velocity.angle()
        return self.angle.minus(vel_angle)

    def calculate_forces(self, translation_velocity,
                         angular_velocity, altitude):

        surface_velocity = self._point.total_velocity(
            translation_velocity,
            angular_velocity)

        self.velocity = surface_velocity
        air_density = self._atmosphere.get_air_density(altitude)

        velocity_magnitude = surface_velocity.magnitude()
        aoa = self.aoa(surface_velocity)

        forces = []

        current_cp = self.cp.calculate(aoa)
        self.current_cp = current_cp

        CL = 0
        if self.lift_curve is not None:
            CL = self.lift_curve.calculate_lift_coefficient(aoa)
            lift_mag = self.calculate_lift(CL, velocity_magnitude, air_density)
            lift_dir = Surface.get_lift_unit(aoa, surface_velocity)
            lift_force = lift_dir.scale(lift_mag)
            forces.append(Force("lift", Force.LIFT,
                                current_cp, lift_force))

        CD = 0
        if self.drag_curve is not None:
            CD = self.drag_curve.calculate_drag_coefficient(aoa, CL)
            drag_mag = self.calculate_drag(
                CD, velocity_magnitude, air_density)
            drag_dir = surface_velocity.reverse().unit()
            drag_vector = drag_dir.scale(drag_mag)
            drag_force = Force("drag", Force.DRAG,
                               current_cp, drag_vector)
            forces.append(drag_force)

        return forces

    def get_lift_unit(aoa, surface_velocity):
        if abs(aoa.relative_degrees()) <= 90:
            return surface_velocity.rotate(Angle(90)).unit()
        else:
            # trailing edge is leading so velocity vector is reversed
            return surface_velocity.rotate(Angle(-90)).unit()

    def calculate_lift(self, CL, velocity_magnitude, air_density):
        return (air_density * velocity_magnitude**2 * self.area * CL) \
            / 2

    def calculate_drag(self, CD, velocity_magnitude, air_density):
        return CD * self.area * (air_density * velocity_magnitude**2) \
            / 2