Example #1
0
    def __init__(self):
        # POV-Ray
        self.edge_color = "rgb <{}, {}, {}>".format(0, 0, 0)  # black
        self.edge_radius = 0.03
        self.vert_color = "rgb <{}, {}, {}>".format(0, 0, 0)  # black
        self.vert_radius = 0.03
        self.face_color = "rgb <0, 0, 0>"  # not used

        verts = dict(
            e=-Qvector((1, 0, 0, 0)),  #E
            f=-Qvector((0, 1, 0, 0)),  #F
            g=-Qvector((0, 0, 1, 0)),  #G
            h=-Qvector((0, 0, 0, 1)))  #H

        self.name = "InvTetrahedron"
        self.volume = 1  # per Concentric Hierarchy
        self.center = ORIGIN

        # 4 vertices
        self.vertexes = verts

        # 4 faces
        self.faces = (('e', 'f', 'g'), ('e', 'g', 'h'), ('e', 'h', 'f'),
                      ('f', 'h', 'g'))

        self.edges = self._distill()
Example #2
0
    def __init__(self):
        # POV-Ray
        self.edge_color = "rgb <{}, {}, {}>".format(1, 165 / 255, 0)  # orange
        self.edge_radius = 0.03
        self.vert_color = "rgb <{}, {}, {}>".format(1, 165 / 255, 0)  # orange
        self.vert_radius = 0.03
        self.face_color = "rgb <0, 0, 0>"  # not used

        verts = dict(
            a=Qvector((1, 0, 0, 0)),  #A
            b=Qvector((0, 1, 0, 0)),  #B
            c=Qvector((0, 0, 1, 0)),  #C
            d=Qvector((0, 0, 0, 1)))  #D

        self.name = "Tetrahedron"
        self.volume = 1  # per Concentric Hierarchy
        self.center = ORIGIN

        # 4 vertices
        self.vertexes = verts

        # 4 faces
        self.faces = (('a', 'b', 'c'), ('a', 'c', 'd'), ('a', 'd', 'b'),
                      ('b', 'd', 'c'))

        self.edges = self._distill()
Example #3
0
 def test_quadrant(self):
     qA = Qvector((1, 0, 0, 0))
     qB = Qvector((0, 1, 0, 0))
     qC = Qvector((0, 0, 1, 0))
     tet = Tetrahedron(qA.length(), qB.length(), qC.length(),
                       (qA - qB).length(), (qA - qC).length(),
                       (qB - qC).length())
     self.assertAlmostEqual(tet.ivm_volume(), Decimal(0.25))
Example #4
0
def animation2(targdir="anim2"):
    
    path = os.path.join(".",targdir)
    if not os.path.isdir(targdir):
        os.mkdir(targdir)
    
    radii = np.linspace(0, 0.5, 8).tolist()
    radii += reversed(radii[1:-1])
    for frame_id, radius in enumerate(radii, start=1):
        filename = f"balls{frame_id:03}.pov"

        with open(os.path.join(path,filename), "w") as target:
            target.write(pov_header) 
            cubocta             = Cuboctahedron()
            cubocta.vert_radius = radius
            cubocta.vert_color  = "rgb <1,0,0>"
            draw_poly(cubocta, target, v=True, e=False)
            draw_vert(Qvector((0,0,0,0)), c=cubocta.vert_color, 
                      r=cubocta.vert_radius, t=target)
            
            if frame_id < 9:
                rd   = RD()
                draw_poly(rd, target)
                for p in twelve_around_one(rd):
                    draw_poly(p, target)
            
            draw_poly(Cuboctahedron(), target, v=True, e=True)
Example #5
0
def animation11(targdir="anim11"):
    targdir = os.path.join(".",targdir)
    if not os.path.isdir(targdir):
        os.mkdir(targdir)

    thirteen_balls = [Qvector((0,0,0,0))] + list(IVM_DIRS)
     
    neighbors = one_hop_away(thirteen_balls)
    
    colors = cycle(["rgb <1,0,0>", "rgb <.8,0,.2>", "rgb <.6,0,.4>", 
                    "rgb <.4,0,.6>", "rgb <.2,0,.8>", "rgb <0,.5,.2>", 
                    "rgb <0,.7,.2>"])
    
    rainbow = [next(colors) for _ in range(13)]
    
    for frame_id in range(13):
        filename = f"balls{frame_id:03}.pov"
            
        with open(os.path.join(targdir,filename), "w") as target:
            target.write(pov_header) 
            rd = RD()
            draw_poly(rd, target)

            for idx, p in enumerate(twelve_around_one(rd)):
                if idx <= frame_id:
                    draw_vert(neighbors[idx], 
                              rainbow[idx],
                              r=0.4, t=target)
                draw_poly(p, target)
                
            if 12 == frame_id:
                draw_vert(neighbors[12],
                          rainbow[12],
                          r=0.4, t=target)
Example #6
0
def animation10(targdir="anim10"):
    targdir = os.path.join(".",targdir)
    if not os.path.isdir(targdir):
        os.mkdir(targdir)

    thirteen_balls = [Qvector((0,0,0,0))] + list(IVM_DIRS)
     
    neighbors = one_hop_away(thirteen_balls)
    
    for frame_id in range(13):
        filename = f"balls{frame_id:03}.pov"
            
        with open(os.path.join(targdir,filename), "w") as target:
            target.write(pov_header) 
            rd = RD()
            draw_poly(rd, target)

            for idx, p in enumerate(twelve_around_one(rd)):
                if idx <= frame_id:
                    draw_vert(neighbors[idx], 
                              c="rgb <1,0,0>", 
                              r=0.5, t=target)
                draw_poly(p, target)
                
            if 12 == frame_id:
                draw_vert(neighbors[12], 
                          c="rgb <1,0,0>", 
                          r=0.5, t=target)
Example #7
0
def animation3(targdir="anim3"):
    
    targdir = os.path.join(".",targdir)
    if not os.path.isdir(targdir):
        os.mkdir(targdir)
    
    radii = np.linspace(0, 0.5, 8).tolist()
    radii += reversed(radii[1:-1])
    for frame_id, radius in enumerate(radii, start=1):
        filename = f"balls{frame_id:03}.pov"

        with open(os.path.join(targdir,filename), "w") as target:
            target.write(pov_header) 
            cubocta             = Cuboctahedron()
            cubocta.vert_radius = radius
            cubocta.vert_color  = "rgb <1,0,0>"
            if frame_id <= 9:
                draw_poly(cubocta, target, v=True, e=False)
                draw_vert(Qvector((0,0,0,0)), c=cubocta.vert_color, 
                          r=cubocta.vert_radius, t=target)
                                
            if frame_id > 9:
                cube = Cube()
                ico  = Icosahedron() * (1/PHI * math.sqrt(2)/2) * 1.2 * radius 
                st   = Struts(cube, ico)
                draw_poly(ico, target)
                draw_poly(st, target)
                # draw_poly(cube, target)
                for ik in twelve_around_one(ico):
                    draw_poly(ik, target)
                # for c in twelve_around_one(cube):
                    # draw_poly(c, target)
                for s in twelve_around_one(st):
                    draw_poly(s, target)
Example #8
0
def sphere_packing():
    cube = Cube()
    rd = RD()
    octa = Octahedron()
    cubocta = Cuboctahedron()
    draw_poly(cube)
    draw_poly(octa)
    draw_poly(rd)
    for p in twelve_around_one(cube):
        draw_poly(p)
    for p in twelve_around_one(rd):
        draw_poly(p)
    for p in twelve_around_one(octa):
        draw_poly(p)
    cubocta.vert_radius = Qvector((2, 1, 1, 0)).length() / 2  # grow the balls
    cubocta.vert_color = (1, 0, 0)
    draw_poly(cubocta, v=True, e=False)
    draw_vert(Qvector((0, 0, 0, 0)),
              c=cubocta.vert_color,
              r=cubocta.vert_radius)
Example #9
0
def spheres_bulging():
    with open("sphere_pack2.pov", "w") as target:
        target.write(pov_header)
        cube = Cube()
        rd   = RD()
        octa    = Octahedron()
        cubocta = Cuboctahedron()
        draw_poly(cube, target)
        draw_poly(octa, target)
        draw_poly(rd, target)
        for p in twelve_around_one(cube):
            draw_poly(p, target)
        for p in twelve_around_one(rd):
            draw_poly(p, target)
        for p in twelve_around_one(octa):
            draw_poly(p, target)
        cubocta.vert_radius = Qvector((2,1,1,0)).length()/2 # grow the balls
        cubocta.vert_color = "rgb <1,0,0>"
        draw_poly(cubocta, target, v=True, e=False)
        draw_vert(Qvector((0,0,0,0)), c=cubocta.vert_color, 
                  r=cubocta.vert_radius, t=target)
Example #10
0
 def test_quadrant(self):
     qA = Qvector((1,0,0,0))
     qB = Qvector((0,1,0,0))
     qC = Qvector((0,0,1,0))
     tet = Tetrahedron(qA.length(), qB.length(), qC.length(), 
             (qA-qB).length(), (qA-qC).length(), (qB-qC).length())
     self.assertAlmostEqual(tet.ivm_volume(), 0.25) 
Example #11
0
def struts():
    IVM = {}
    IVM[0] = [Qvector((0, 0, 0, 0))]
    IVM[1] = list(IVM_DIRS)
    print(IVM)
    polys_blender.IVM = IVM
    radius = 0.5
    cube = Cube()
    ico = Icosahedron() * (1 / PHI * math.sqrt(2) / 2) * 1.2 * radius
    st = Struts(cube, ico, True)
    draw_poly(ico)
    draw_poly(st)
    # draw_poly(cube, target)
    for ik in twelve_around_one(ico):
        draw_poly(ik)
    # for c in twelve_around_one(cube):
    # draw_poly(c, target)
    for s in twelve_around_one(st):
        draw_poly(s, v=False)
Example #12
0
from polys_blender import Cuboctahedron, Cube, Octahedron
from polys_blender import Tetrahedron, InvTetrahedron, RD, Icosahedron, Struts
from polys_blender import twelve_around_one, draw_poly, draw_vert
from qrays import Qvector
from itertools import cycle

import os
import numpy as np
import math

from itertools import permutations

g = permutations((2, 1, 1, 0))
UNIQUE = {p for p in g}  # set comprehension

IVM_DIRS = {Qvector(x) for x in UNIQUE}
PHI = (1 + math.sqrt(5)) / 2


def ch():
    ico = Icosahedron() * 2
    cubo = Cuboctahedron() * 2
    cub = Cube() * 2
    rd = RD() * 2
    tet = Tetrahedron() * 2
    octa = Octahedron() * 2
    draw_poly(ico)
    draw_poly(cubo)
    draw_poly(rd)
    draw_poly(cub)
    draw_poly(tet)
Example #13
0
 def test_martian(self):
     p = Qvector((2, 1, 0, 1))
     q = Qvector((2, 1, 1, 0))
     r = Qvector((2, 0, 1, 1))
     result = make_tet(5 * q, 2 * p, 2 * r)
     self.assertAlmostEqual(result[0], 20, 7)
Example #14
0
 def test_phi_tet_2(self):
     p = Qvector((2, 1, 0, 1))
     q = Qvector((2, 1, 1, 0))
     r = Qvector((2, 0, 1, 1))
     result = make_tet(PHI * q, (1 / PHI) * p, r)
     self.assertAlmostEqual(result[0], 1, 7)
Example #15
0
 def test_area_martian2(self):
     p = 3 * Qvector((2,1,0,1))
     q = 4 * Qvector((2,1,1,0))
     result = p.area(q)
     self.assertAlmostEqual(result, 12)
Example #16
0
    if f:
        for f in p.faces:
            draw_face(f, fc, the_file)

    if e:
        for e in p.edges:
            draw_edge(e, ec, er, the_file)


import math
from qrays import Qvector

PHI = (1 + math.sqrt(5)) / 2.0

ORIGIN = Qvector((0, 0, 0, 0))
A = Qvector((1, 0, 0, 0))
B = Qvector((0, 1, 0, 0))
C = Qvector((0, 0, 1, 0))
D = Qvector((0, 0, 0, 1))

E, F, G, H = B + C + D, A + C + D, A + B + D, A + B + C
I, J, K, L, M, N = A + B, A + C, A + D, B + C, B + D, C + D
O, P, Q, R, S, T = I + J, I + K, I + L, I + M, N + J, N + K
U, V, W, X, Y, Z = N + L, N + M, J + L, L + M, M + K, K + J

# OPPOSITE DIAGONALS
# ZY WX
# RV OS
# TU PQ
control = (Z - T).length()
Example #17
0
import bpy
from qrays import Qvector
import sys

sys.path.append("C:\\Users\\Kirby\\School_of_Tomorrow")
from itertools import permutations
g = permutations((2, 1, 1, 0))

ORIGIN_IVM = Qvector((0, 0, 0, 0))
# set comprehension in list comprehension
SPOKES_IVM = [Qvector(v) for v in {p for p in g}]
ORIGIN_XYZ = ORIGIN_IVM.xyz().xyz  # (0,0,0)

c6xty_ball = bpy.ops.mesh.primitive_ico_sphere_add
c6xty_ball(radius=0.5, enter_editmode=False, location=ORIGIN_XYZ)
bpy.ops.object.shade_smooth()

for qv in SPOKES_IVM:
    xyz = qv.xyz().xyz
    c6xty_ball(radius=0.5, enter_editmode=False, location=xyz)
    # bpy.ops.object.shade_smooth()
Example #18
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Sep  4 09:56:18 2020

@author: mac
"""

import tetravolume as tv
from itertools import permutations
from qrays import Qvector
from random import choice
from gmpy2 import mpfr, get_context

ccp_spokes = [Qvector(p) for p in set(permutations((0,1,1,2)))]

get_context().precision=1000
zero = mpfr('0.0')

def rand_vert():
    vert = Qvector((zero, zero, zero, zero))
    for _ in range(1000):
        vert += choice(ccp_spokes)
    return vert

# vertexes
A = rand_vert()
B = rand_vert()
C = rand_vert()
D = rand_vert()
Example #19
0
def twelve_around_one(p):
    twelve = []
    for v in unique:
        trans_vector = Qvector(v)
        twelve.append(p + trans_vector)
    return twelve
Example #20
0
def rand_vert():
    vert = Qvector((zero, zero, zero, zero))
    for _ in range(1000):
        vert += choice(ccp_spokes)
    return vert
Example #21
0
 def test_quadrant(self):
     qA = Qvector((1, 0, 0, 0))
     qB = Qvector((0, 1, 0, 0))
     qC = Qvector((0, 0, 1, 0))
     tet = make_tet(qA, qB, qC)
     self.assertAlmostEqual(tet[0], 0.25)
Example #22
0
"""

import sqlite3 as sql

from flextegrity import Cuboctahedron, Cube, Octahedron
from flextegrity import Tetrahedron, InvTetrahedron, RD, Icosahedron

import sys
sys.path.append("/Users/kurner/Documents/Python5")

from string import ascii_uppercase as AtoZ
from qrays import Qvector
import time, os

# four spokes of a caltrop
A = Qvector((1, 0, 0, 0))
B = Qvector((0, 1, 0, 0))
C = Qvector((0, 0, 1, 0))
D = Qvector((0, 0, 0, 1))
E, F, G, H = B + C + D, A + C + D, A + B + D, A + B + C  # inverse tet
I, J, K, L, M, N = A + B, A + C, A + D, B + C, B + D, C + D  # octahedron
O, P, Q, R, S, T = I + J, I + K, I + L, I + M, N + J, N + K  # cuboctahedron
U, V, W, X, Y, Z = N + L, N + M, J + L, L + M, M + K, K + J  # ...


class DB:
    backend = 'sqlite3'  # default
    timezone = int(time.strftime("%z", time.localtime()))
    target_path = os.getcwd()  # current directory
    db_name = ":file:"
    db_name = os.path.join(target_path, 'shapes_lib.db')
Example #23
0
import bpy

import sys
sys.path.append("C:\\Users\\Kirby\\School_of_Tomorrow")

from qrays import Qvector
from functools import partial

from itertools import permutations
g = permutations((2, 1, 1, 0))

ORIGIN_IVM = Qvector((0, 0, 0, 0))
# set comprehension in list comprehension
SPOKES_IVM = [Qvector(v) for v in {p for p in g}]
nucleus = tuple([ORIGIN_IVM])


def next_layer(curr_layer, prev_layer):
    """
    generates a next layer of FCC spheres by trying 12-around-1 
    for each in the current layer (curr_layer) but without keeping
    any duplicates i.e. discarding redundant sphere centers.
    """
    next_layer = set()
    for qv in curr_layer:
        for bv in SPOKES_IVM:
            v_sum = qv + bv
            if (not v_sum in curr_layer and not v_sum in prev_layer):
                next_layer.add(v_sum)
    return sorted(list(next_layer))
Example #24
0
 def setUp(self):
     q1 = Qvector((1,0,0,0))
     q2 = Qvector((0,1,0,0))
     q3 = Qvector((0,0,1,0))
     q4 = Qvector((0,0,0,1))
     self.the_tet = Tetrahedron(q1,q2,q3,q4)