示例#1
0
 def _get_incidence_angle(self, incident_vector: Vector) -> float:
     normal_vec_angle = incident_vector.angle(
         self.segment.get_normal_vector())
     inverted_normal_vec_angle = incident_vector.angle(
         self.segment.get_normal_vector().invert())
     return normal_vec_angle if abs(normal_vec_angle) < abs(
         inverted_normal_vec_angle) else inverted_normal_vec_angle
示例#2
0
 def __init__(self,
              t=0.,
              m=0.,
              r: Vector = Vector(0., 0.),
              v: Vector = Vector(0., 0.),
              a: Vector = Vector(0., 0.)):
     self.t = t
     self.m = m
     self.r = r
     self.v = v
     self.a = a
示例#3
0
 def _get_reflection_vector(self, reflection_angle: float,
                            incident_vector: Vector) -> Vector:
     cs = math.cos(reflection_angle)
     sn = math.sin(reflection_angle)
     x, y = incident_vector.x, incident_vector.y
     new_x = (x * cs) - (y * sn)
     new_y = (x * sn) + (y * cs)
     return Vector(new_x, new_y)
示例#4
0
    def __init__(self, r: Vector, v: Vector, m: float):
        """
        :param r: position in world reference frame
        :param v: velocity in world reference frame
        :param m: mass
        """
        self.id = uuid.uuid1()
        self.t = 0  # living duration in seconds
        self.m = m

        self.r = r
        self.v = v
        self.a = Vector()
示例#5
0
    def _get_entities(self, world):

        entities = [
            Entity(
                world.id, EntityType.World,
                ParticleKinematic(world.t, 0.,
                                  Vector(world.rect.w // 2,
                                         world.rect.h // 2)))
        ]

        for p in world.particles:
            entities.append(
                Entity(p.id, EntityType.Particle,
                       ParticleKinematic(p.t, p.m, p.r, p.v, p.a)))
        return entities
示例#6
0
    def _fill_world_data(self, world: Entity, observer: Entity, entities):
        if world.id not in self.entity_dict:
            self.entity_dict[world.id] = {
                "ts": deque(maxlen=Plotter.queue_size),
                "pxs": deque(maxlen=Plotter.queue_size),
                "pys": deque(maxlen=Plotter.queue_size),
                "Es": deque(maxlen=Plotter.queue_size)
            }
        E = 0
        p = Vector()
        for e in entities:
            if e.type != EntityType.Particle:
                continue

            v = (e.kin.v - observer.kin.v)
            E += 0.5 * e.kin.m * v.length()**2
            p += v * e.kin.m

        self.entity_dict[world.id]["ts"].append(world.kin.t)
        self.entity_dict[world.id]["Es"].append(E)
        self.entity_dict[world.id]["pxs"].append(p.x)
        self.entity_dict[world.id]["pys"].append(p.y)
示例#7
0
from src.mathematics import Segment, Vector
from src.physics.mechanics import Particle
from src.physics.optics import PlaneMirror
from src.physics.world import World
from src.simulation import Simulation

w = World((800, 600))

m = 1.
w.add_particle(Particle(Vector(0., 0.), Vector(10, 10), m))

w.mirrors.append(PlaneMirror(Segment((0, 150), (200, 0))))
w.mirrors.append(PlaneMirror(Segment((650, 0), (800, 150))))
w.mirrors.append(PlaneMirror(Segment((650, 600), (800, 450))))
w.mirrors.append(PlaneMirror(Segment((0, 450), (200, 600))))

Simulation(w).run()
示例#8
0
import random

from src.mathematics import Vector, Segment
from src.physics.mechanics import CentralForce, Particle
from src.physics.optics import PlaneMirror
from src.physics.world import World
from src.simulation import Simulation

w = World((2000, 2000))
c = Vector(w.rect.w // 2, w.rect.h // 2)
w.forces.append(CentralForce(c, 10000.))

n_particles = 1
vmax = 100
for _ in range(n_particles):
    pos = random.randint(0, w.rect.w), random.randint(0, w.rect.h)
    s = random.uniform(-vmax, vmax), random.uniform(-vmax, vmax)
    m = 1.
    w.add_particle(Particle(Vector(pos[0], pos[1]), Vector(s[0], s[1]), m))
w.mirrors.append(PlaneMirror(Segment((250, 250), (750, 750))))
w.mirrors.append(PlaneMirror(Segment((250, 750), (750, 250))))
w.mirrors.append(PlaneMirror(Segment((1250, 1250), (1750, 1750))))
w.mirrors.append(PlaneMirror(Segment((1250, 1750), (1750, 1250))))

w.mirrors.append(PlaneMirror(Segment((1250, 250), (1750, 750))))
w.mirrors.append(PlaneMirror(Segment((1250, 750), (1750, 250))))
w.mirrors.append(PlaneMirror(Segment((250, 1250), (750, 1750))))
w.mirrors.append(PlaneMirror(Segment((250, 1750), (750, 1250))))
Simulation(w).run()
示例#9
0
 def _compute_force_on(self, p: Particle) -> Vector:
     f = Vector()
     for force in self.forces:
         f += force.apply_on(p)
     return f
示例#10
0
 def _get_ray_segment(self, angle: float, ray: Ray) -> Segment:
     v = Vector(math.cos(angle), math.sin(angle))
     v = v.scale_to(self.width * self.height)
     x, y = ray.points[-1]
     ray_segment = DirectedSegment((x, y), (x + v.x, y + v.y))
     return ray_segment
示例#11
0
import random

from src.mathematics import Vector
from src.physics.mechanics import ConstantForce, Particle
from src.physics.world import World
from src.simulation import Simulation

w = World((800, 600))
w.forces.append(ConstantForce(Vector(0, -10.)))

n_particles = 25
vmax = 50
for _ in range(n_particles):
    pos = 0., 0.
    s = random.uniform(0, vmax), random.uniform(0, vmax)
    m = 1.
    w.add_particle(Particle(Vector(0., 0.), Vector(s[0], s[1]), m))

Simulation(w).run()