def update(self, vect_end, particle): self.edges = [] carga = particle.carga velocidad = particle.velocidad for node in self.nodes: radio = Vec_A2B(node, vect_end) start = structures_3D.Node(node.x, node.y, node.z) vector = q__v1xv2(velocidad, radio, carga) end = structures_3D.Node(start.x + vector.ux, start.y + vector.uy, start.z + vector.uz) edge = structures_3D.Edge(start, end) self.edges.append(edge)
def update(self, vect_end, particle): self.edges = [] for node in self.nodes: vector = Vec_A2B(node, vect_end) vector.ux, vector.uy, vector.uz = vector.ux * ( particle.carga / abs(particle.carga)), vector.uy * ( particle.carga / abs(particle.carga)), vector.uz * ( particle.carga / abs(particle.carga)) start = structures_3D.Node(node.x, node.y, node.z) end = structures_3D.Node(start.x + vector.ux, start.y + vector.uy, start.z + vector.uz) edge = structures_3D.Edge(start, end) self.edges.append(edge)
def update(self, vect_end, particle): self.edges = [ structures_3D.Edge( self.posicion, structures_3D.Node(self.posicion.x + self.velocidad.ux, self.posicion.y + self.velocidad.uy, self.posicion.z + self.velocidad.uz)) ] if self.carga > 0: self.node_color = (0, 0, 255) else: self.node_color = (255, 0, 0)
def project_on_surface(self, surface, plain=True): """Given a surface""" self.nodes = [] if plain: for node in self.thing.nodes: # hallo el punto node' en superficie surface con la ecuaciĆ³n de la recta (x, y, z) = (node.x, node.y, node.z) + lambda(n.x, n.y, n.z) l = (-surface.normal.x * node.x - surface.normal.y * node.y - surface.normal.z * node.z - surface.d) / (surface.normal.x**2 + surface.normal.y**2 + surface.normal.z**2) self.nodes.append( structures_3D.Node(node.x + surface.normal.x * l, node.y + surface.normal.y * l, node.z + surface.normal.z * l))
def generate_nodes(self, size): for x in range(200, size, int(size / 5)): for y in range(200, size, int(size / 5)): for z in range(200, size, int(size / 5)): self.nodes.append(structures_3D.Node(x, y, z)) # -(size/2)
colores = { "B_edges": (0, 255, 0), "B_nodes": (0, 100, 150), "E_edges": (0, 255, 255), "E_nodes": (150, 150, 255), "velocidad": (200, 200, 200) } pygame.init() size = 1000 espacio = Space(size, size, size) # canvas = pygame.display.set_mode([size, size]) # particula posicion = structures_3D.Node(size / 2, size / 2, size / 2) carga = 1.6 * (10**-19) particula = Particula(carga, posicion, Vector(0, 0, 0)) # puntos_B = [] puntos_E = [] for x in range(1, size): for y in range(1, size): if x % 100 == 0 and y % 100 == 0: puntos_E.append(structures_3D.Node(x, y, 0)) # if (x-50)%100 == 0 and (y-50)%100 == 0: # puntos_B.append(structures_3D.Node(x-5, y-5, 0)) campo_E = E(colores["E_nodes"], colores["E_edges"])
thing.move(axis, d) def scaleAll(self, scale): """ Scale all objects by a given scale, centred on the centre of the screen. """ centre_x = self.width/2 centre_y = self.height/2 for thing in self.objects.values(): thing.scale((centre_x, centre_y), scale) def rotateAll(self, axis, theta): """ Rotate all thing about their centre, along a given axis by a given angle. """ rotateFunction = 'rotate' + axis for thing in self.objects.values(): centre = thing.get_centre() getattr(thing, rotateFunction)(centre, theta) # cube cube_nodes = [structures_3D.Node(x,y,z) for x in (50,250) for y in (50,250) for z in (50,250)] cube_edges = [(n,n+4) for n in range(0,4)] + [(n,n+1) for n in range(0,8,2)] + [(n,n+2) for n in (0,1,4,5)] cube_edges = [structures_3D.Edge(cube_nodes[start],cube_nodes[end]) for start, end in cube_edges] cube2 = structures_3D.Object(cube_nodes, cube_edges) # cube = structures_3D.Object([], []) # cube.add_nodes([(x ,y, z) for x in (50, 250) for y in (50, 250) for z in (50, 250)]) # cube2.Show_components() pv = Projection(1000, 750) pv.add_object("cubo", cube2) pv.run()
# hallo el punto node' en superficie surface con la ecuaciĆ³n de la recta (x, y, z) = (node.x, node.y, node.z) + lambda(n.x, n.y, n.z) l = (-surface.normal.x * node.x - surface.normal.y * node.y - surface.normal.z * node.z - surface.d) / (surface.normal.x**2 + surface.normal.y**2 + surface.normal.z**2) self.nodes.append( structures_3D.Node(node.x + surface.normal.x * l, node.y + surface.normal.y * l, node.z + surface.normal.z * l)) world = World( size, size, (255, 255, 255), structures_3D.Plane( equation="0x +y +0z -500")) # structures_3D.Plane(equation="x+0+z=0") cube_nodes = [ structures_3D.Node(x, y, z) for x in (0, 50) for y in (0, 50) for z in (0, 50) ] # for node in cube_nodes: # print("x: {0} y: {1} z: {2}".format(node.x, node.y, node.z)) edges = [(cube_nodes[n], cube_nodes[n + 4]) for n in range(0, 4)] + [ (cube_nodes[n], cube_nodes[n + 1]) for n in range(0, 8, 2) ] + [(cube_nodes[n], cube_nodes[n + 2]) for n in (0, 1, 4, 5)] cube_edges = [] for edge in edges: cube_edges.append(structures_3D.Edge(edge[0], edge[1])) cube = Mat_object(cube_nodes, cube_edges) world.add_object("cube", cube)