示例#1
0
文件: 3DPlot.py 项目: PauliSpin/3D
 def make_quads(self):
     # Create the quad objects, based on the vertex objects already created.
     for x in range(L-2):
         for y in range(L-2):
             v0 = self.get_vertex(x, y)
             v1 = self.get_vertex(x+1, y)
             v2 = self.get_vertex(x+1, y+1)
             v3 = self.get_vertex(x, y+1)
             vp.quad(vs=[v0, v1, v2, v3])
示例#2
0
 def surf(self, x, y, z):
     q = self.corners(x, y, z)  # get corners
     self.top = []
     vtex = self.vlst(q)
     for v in vtex:
         self.top.append(vp.quad(vs=v))
     return self.top
示例#3
0
文件: vpmnb.py 项目: com-py/compy
 def surf(self, x, y, z):
     q = self.corners(x, y, z)   # get corners
     self.top = []
     vtex = self.vlst(q)
     for v in vtex:
         self.top.append(vp.quad(vs=v))
     return self.top
示例#4
0
def Quad():
    """how to make a quad"""
    a = vertex(pos=vec(0, 0, 0), color=color.red)
    b = vertex(pos=vec(1, 0, 0), color=color.blue)
    c = vertex(pos=vec(1, 1, 0), color=color.green)
    d = vertex(pos=vec(0, 1, 0), color=color.yellow)
    return quad(vs=[a, b, c, d])
示例#5
0
def draw_compound(xys):
    return compound([
        quad(vs=[
            vertex(pos=points[_idx[(x + dx, y + dy)]],
                   normal=points_n[_idx[x + dx, y + dy]],
                   color=colors[_idx[(x + dx, y + dy)]])
            for dx, dy in [(0, 0), (D, 0), (D, D), (0, D)]
        ]) for x, y in xys
    ])
示例#6
0
def make_ramp(alpha, H):
    parts = []
    B = H * sin(0.5 * pi - alpha) / sin(alpha)
    front = triangle(
        v0=vertex(pos=vec(-0.5 * B, 0, 0.25 * H)),
        v1=vertex(pos=vec(-0.5 * B, H, 0.25 * H)),
        v2=vertex(pos=vec(0.5 * B, 0, 0.25 * H))
    )
    back = triangle(
        v0=vertex(pos=vec(-0.5 * B, 0, - 0.25 * H)),
        v1=vertex(pos=vec(-0.5 * B, H, - 0.25 * H)),
        v2=vertex(pos=vec(0.5 * B, 0, - 0.25 * H))
    )
    top = quad(
        v0=front.v1,
        v1=back.v1,
        v2=back.v2,
        v3=front.v2,
    )
    bottom = quad(
        v0=front.v0,
        v1=back.v0,
        v2=back.v2,
        v3=front.v2
    )
    side = quad(
        v0=front.v0,
        v1=back.v0,
        v2=back.v1,
        v3=front.v1
    )
    parts.append(front)
    parts.append(back)
    parts.append(top)
    parts.append(bottom)
    parts.append(side)
    obj = compound(parts)
    obj.height = H
    obj.base = B
    obj.angle = alpha
    # obj.color = color.cyan
    # obj.opacity = 0.1

    return obj
示例#7
0
def create_landscape_from_points():
    # --- create quads
    quadlist = []
    for y, line in enumerate(Game.points):
        for x, point in enumerate(line):
            #a = point
            try:
                a = Game.points[y][x]
                b = Game.points[y][x + 1]
                c = Game.points[y + 1][x + 1]
                d = Game.points[y + 1][x]
            except IndexError:
                continue
            quadlist.append(v.quad(vs=[a, b, c, d]))

    Game.landscape = v.compound(quadlist,
                                origin=v.vector(0, 0, 0),
                                pos=v.vector(0, 0, 0))
示例#8
0
文件: main.py 项目: rbunger/Orbitrap
 def quad(self,
          i_1,
          phi_1,
          i_2,
          phi_2,
          i_3,
          phi_3,
          i_4,
          phi_4,
          mirror=False):
     p_1 = self.point(i_1, phi_1, mirror)
     p_2 = self.point(i_2, phi_2, mirror)
     p_3 = self.point(i_3, phi_3, mirror)
     p_4 = self.point(i_4, phi_4, mirror)
     n = cross(p_2 - p_1, p_3 - p_1)
     n /= mag(n)
     if (mirror):
         n *= -1
     return quad(vs=[
         self.vertex(p_1, n),
         self.vertex(p_2, n),
         self.vertex(p_3, n),
         self.vertex(p_4, n)
     ])
示例#9
0
for i in range(len(maze.grid)):
    for j in range(len(maze.grid[0])):
        for k in range(len(maze.grid[0][0])):
            #Using if statements for each wall, draw the ones that exist.
            abspos = vp.vector(maze.grid[i][j][k].pos[1], maze.height - maze.grid[i][j][k].pos[0], maze.length - maze.grid[i][j][k].pos[2])
            cellcolor = vp.vector(random.random(),random.random(),random.random())
            DBL = vp.vertex(pos = abspos + vp.vector(0,-1,-1), color = cellcolor)
            DBR = vp.vertex(pos = abspos + vp.vector(1,-1,-1), color = cellcolor)
            DFR = vp.vertex(pos = abspos + vp.vector(1,-1,0), color = cellcolor)
            DFL = vp.vertex(pos = abspos + vp.vector(0,-1,0), color = cellcolor)
            UFL = vp.vertex(pos = abspos, color = cellcolor)
            UFR = vp.vertex(pos = abspos + vp.vector(1,0,0), color = cellcolor)
            UBR = vp.vertex(pos = abspos + vp.vector(1,0,-1), color = cellcolor)
            UBL = vp.vertex(pos = abspos + vp.vector(0,0,-1), color = cellcolor)
            if maze.grid[i][j][k].walls[0]:
                quadArray.append(vp.quad(vs = [UFL,UFR,UBR,UBL]))
            if maze.grid[i][j][k].walls[1]:
                quadArray.append(vp.quad(vs = [UFL,UBL,DBL,DFL]))
            if maze.grid[i][j][k].walls[2]:
                quadArray.append(vp.quad(vs = [UFL,UFR,DFR,DFL]))
            if maze.grid[i][j][k].walls[3]:
                quadArray.append(vp.quad(vs = [UFR,DFR,DBR,UBR]))
            if maze.grid[i][j][k].walls[4]:
                quadArray.append(vp.quad(vs = [UBL,UBR,DBR,DBL]))
            if maze.grid[i][j][k].walls[5]:
                quadArray.append(vp.quad(vs = [DFL,DFR,DBR,DBL]))

def create_uniform_particles(x_range, y_range, z_range, xB_range, yB_range, zB_range, N):
    particles = np.empty((N, 6))
    particles[:, 0] = uniform(x_range[0], x_range[1], size=N)
    particles[:, 1] = uniform(y_range[0], y_range[1], size=N)
示例#10
0
def vertices(R=0, C=0):
    lowerRight = (2 * R + 1, 2 * C)
    upperRight = (2 * R + 1, 2 * C + 1)
    upperLeft = (2 * R, 2 * C + 1)
    lowerLeft = (2 * R, 2 * C)

    return [
        vertex(pos=vertexes[lowerRight], color=color.red),
        vertex(pos=vertexes[upperRight], color=color.blue),
        vertex(pos=vertexes[upperLeft], color=color.green),
        vertex(pos=vertexes[lowerLeft], color=color.yellow)
    ]


cells = dict()
for row in range(Rows):
    for col in range(Cols):
        cells[row, col] = quad(vs=vertices(row, col))

#make lefties
for row, col in cells.keys():
    cell = cells[row, col]
    #vertices of the cell
    ll, lr, ur, ul = cell.vs
    #corners of the cell to be
    UR = ul
    LR = ll
    LL = vertex(color=color.white, pos=vec(0, 0, 0))
    UL = vertex(color=color.white, pos=vec(1, 1, 0))
    q = quad(vs=[LL, LR, UR, UL])
示例#11
0
            min_value=min_value,
            num_points=idx - 1,
            center=center)

print('-' * 80)
print('Basic info:')
pprint(info)

################################################
# Draw ground
color = vector(0.2, 0.2, 0.2)
v0 = vertex(pos=vector(0, 0, 0) - center, color=color)
v1 = vertex(pos=vector(shape[0], 0, 0) - center, color=color)
v2 = vertex(pos=vector(shape[0], shape[1], 0) - center, color=color)
v3 = vertex(pos=vector(0, shape[1], 0) - center, color=color)
quad(vs=[v0, v1, v2, v3])


# Draw quad using vertex in xys
def draw_compound(xys):
    return compound([
        quad(vs=[
            vertex(pos=points[_idx[(x + dx, y + dy)]],
                   normal=points_n[_idx[x + dx, y + dy]],
                   color=colors[_idx[(x + dx, y + dy)]])
            for dx, dy in [(0, 0), (D, 0), (D, D), (0, D)]
        ]) for x, y in xys
    ])


# Draw surface
示例#12
0
import vpython as vp

N = 100
m = 8
vp.scene.width = vp.scene.height = N * m
vp.scene.center = vp.vec(N * m / 2, N * m / 2, 0)
vp.scene.range = 0.5 * N * m
v = []
quads = []
for x in range(N):
    for y in range(N):
        c = vp.color.hsv_to_rgb(vp.vec(x / N, 1, 1))
        v.append(
            vp.vertex(pos=vp.vec(x, y, 0), color=c, normal=vp.vec(0, 0, 1)))
for x in range(N - 1):
    for y in range(N - 1):
        quads.append(
            vp.quad(vs=[
                v[N * x + y], v[N * x + N + y], v[N * x + N + y + 1], v[N * x +
                                                                        y + 1]
            ]))
q = vp.compound(quads)
clones = []
n = N - 1
for x in range(m):
    for y in range(m):
        clones.append(q.clone(pos=vp.vec(n * x + N / 2, n * y + N / 2, 0)))
q.visible = False  # make the original object invisible
示例#13
0
front = vector(0, 0, 1)

arrow(pos=O, axis=up, color=color.red)
arrow(pos=O, axis=right, color=color.green)
arrow(pos=O, axis=front, color=color.blue)


points = [0]
with open(os.path.join('..', 'parts', 'small_arm_v.txt'), 'rb') as pFile:
    line = pFile.readline()
    while line:
        p = [float(e) for e in line.split()]
        points.append(vector(p[0], p[1], p[2]))
        line = pFile.readline()

faces = []
with open(os.path.join('..', 'parts', 'small_arm_f.txt'), 'rb') as pFile:
    line = pFile.readline()
    while line:
        f = [int(float(e)) for e in line.split() if b'NaN' not in e]
        faces.append(f)
        line = pFile.readline()

input('press Enter to continue.')

arm = compound([quad(vs=[vertex(pos=points[e], color=color.cyan) for e in f])
                for f in faces if len(f) == 4])
while True:
    rate(30)
    arm.rotate(axis=vector(0, 0, 1), angle=radians(2), origin=O)