[gallery]

 Picture


 Vector image

tube.pdf(558)

 Generator

A python program for NodeBox.

def hextube(r,n,m):
    l = r*sin(pi/n)/sqrt(3.0)*2
    print l
    hexagons = []
    for ix in range(m):
        for ith in range(n):
            c = r*cos(2*pi*ith/n)
            s = r*sin(2*pi*ith/n)
            ch = r*cos(pi*(2*ith+1)/n)
            sh = r*sin(pi*(2*ith+1)/n)
            c1 = r*cos(pi*(2*ith+2)/n)
            s1 = r*sin(pi*(2*ith+2)/n)
            c1h = r*cos(pi*(2*ith+3)/n)
            s1h = r*sin(pi*(2*ith+3)/n)
            hexagon = []
            hexagon.append((l*(ix*3), c, s))
            hexagon.append((l*(ix*3+1), c, s))
            hexagon.append((l*(ix*3+1.5), ch, sh))
            hexagon.append((l*(ix*3+1), c1, s1))
            hexagon.append((l*(ix*3), c1, s1))
            hexagon.append((l*(ix*3-0.5), ch, sh))
            hexagons.append(hexagon)
            hexagon = []
            hexagon.append((l*(ix*3+1.5), ch, sh))
            hexagon.append((l*(ix*3+2.5), ch, sh))
            hexagon.append((l*(ix*3+3.0), c1, s1))
            hexagon.append((l*(ix*3+2.5), c1h, s1h))
            hexagon.append((l*(ix*3+1.5), c1h, s1h))
            hexagon.append((l*(ix*3+1.0), c1, s1))
            hexagons.append(hexagon)
    return hexagons

def squaretube(r,n,m):
    l = 2*r*sin(pi/n)
    print l
    squares = []
    for ix in range(m):
        for ith in range(n):
            c = r*cos(2*pi*ith/n)
            s = r*sin(2*pi*ith/n)
            c1 = r*cos(pi*(2*ith+2)/n)
            s1 = r*sin(pi*(2*ith+2)/n)
            square = []
            square.append((l*(ix), c, s))
            square.append((l*(ix+1), c, s))
            square.append((l*(ix+1), c1, s1))
            square.append((l*(ix), c1, s1))
            squares.append(square)
    return squares


def outprod(a,b):
    return (a[1]*b[2]-a[2]*b[1],
            a[2]*b[0]-a[0]*b[2],
            a[0]*b[1]-a[1]*b[0])


def normal(polygon):
    #print polygon
    vec = [0.0] * 3
    for i in range(len(polygon)):
        op = outprod(polygon[i-1],polygon[i])
        for i in range(3):
            vec[i] += op[i]
    return vec


def rotatey(a,th):
    c = cos(th)
    s = sin(th)
    return (a[0]*c-a[2]*s,a[1],a[0]*s+a[2]*c)

def rotatex(a,th):
    c = cos(th)
    s = sin(th)
    return (a[0], a[1]*c-a[2]*s, a[1]*s+a[2]*c)

def depth(a,c):
    zoom = exp(a[2]/c)
    return (a[0]*zoom,a[1]*zoom,a[2])


#pos = []
#file = open("001.q.xyz","r")
#lin = file.readline()
#lin = file.readline()
#for lin in file:
#    elem,x,y,z = lin.split()
#    if elem == "O":
#        pos.append((float(x),float(y),float(z)))
#
#bonds = []
#for i in range(len(pos)):
#    xi,yi,zi = pos[i]
#    for j in range(i+1,len(pos)):
#        xj,yj,zj = pos[j]
#        d = (xi-xj)**2 + (yi-yj)**2 + (zi-zj)**2
#        if d < 10:
#            bonds.append((pos[i],pos[j]))
            
size(600,300)
from math import *
r=12.8/2
n = 16
hexagons = hextube(r,n,9)
r = 2.75
n = 6
squares  = squaretube(r,n,17)

theta = 1.3      #ANGLE
d = 50.0         #PARSE
offsx = 100
offsy = 150

#backside hexagons
fill(1,1,1,0.7)
stroke(0)
strokewidth(1)
for hexagon in hexagons:
    projected = []
    for vertex in hexagon:
        projected.append(depth(rotatey(rotatex(vertex,theta),theta),d))
    n = normal(projected)
    if n[2] > 0:
        beginpath(projected[0][0]*10+offsx, projected[0][1]*10+offsy)
        for vertex in projected:
            lineto(vertex[0]*10+offsx, vertex[1]*10+offsy)
        endpath()
#strokewidth(2)
#for v0,v1 in bonds:
#    p0 = depth(rotatey(rotatex(v0,theta),theta),d)
#    p1 = depth(rotatey(rotatex(v1,theta),theta),d)
#    line(p0[0]*10+offsx, p0[1]*10+offsy,
#         p1[0]*10+offsx, p1[1]*10+offsy)
#fill(0)
#nostroke()
#for v0,v1 in bonds:
#    p0 = depth(rotatey(rotatex(v0,theta),theta),d)
#    p1 = depth(rotatey(rotatex(v1,theta),theta),d)
#    oval(p0[0]*10+offsx-4, p0[1]*10+offsy-4,8,8)
#    oval(p1[0]*10+offsx-4, p1[1]*10+offsy-4,8,8)


#backside squares
fill(1,1,1,0.7)
stroke(0)
strokewidth(2)
for square in squares:
    projected = []
    for vertex in square:
        projected.append(depth(rotatey(rotatex(vertex,theta),theta),d))
    n = normal(projected)
    if n[2] > 0:
        beginpath(projected[0][0]*10+offsx, projected[0][1]*10+offsy)
        for vertex in projected:
            lineto(vertex[0]*10+offsx, vertex[1]*10+offsy)
        endpath()
#backside atoms
for square in squares:
    projected = []
    for vertex in square:
        projected.append(depth(rotatey(rotatex(vertex,theta),theta),d))
    n = normal(projected)
    if n[2] > 0:
        for vertex in projected:
            oval(vertex[0]*10+offsx-3, vertex[1]*10+offsy-3,6,6)
#frontside squares
for square in squares:
    projected = []
    for vertex in square:
        projected.append(depth(rotatey(rotatex(vertex,theta),theta),d))
    n = normal(projected)
    if n[2] < 0:
        beginpath(projected[0][0]*10+offsx, projected[0][1]*10+offsy)
        for vertex in projected:
            lineto(vertex[0]*10+offsx, vertex[1]*10+offsy)
        endpath()
#frontside atoms
for square in squares:
    projected = []
    for vertex in square:
        projected.append(depth(rotatey(rotatex(vertex,theta),theta),d))
    n = normal(projected)
    if n[2] < 0:
        for vertex in projected:
            oval(vertex[0]*10+offsx-3, vertex[1]*10+offsy-3,6,6)

#frontside hexagons
fill(1,1,1,0.7)
stroke(0)
strokewidth(1)
for hexagon in hexagons:
    projected = []
    for vertex in hexagon:
        projected.append(depth(rotatey(rotatex(vertex,theta),theta),d))
    n = normal(projected)
    if n[2] < 0:
        beginpath(projected[0][0]*10+offsx, projected[0][1]*10+offsy)
        for vertex in projected:
            lineto(vertex[0]*10+offsx, vertex[1]*10+offsy)
        endpath()


[2004年10月26日]

メニュー

岡山大学

関連ページ

<< 2019-4 >>
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

検索

キーワード

class

gallery

research

water

analysis

fractal noise

risk

lifehack

雑記

survey

software

links

あしあと



最新

2019/4/3

2018/12/9

2018/12/7

2018/10/11

2018/9/25

Add