############################
### diag @ IAM @ DM2_w25 ###
### hu_03 setUp_ver00    ### see examples @ DM2_w23 hu_03 !
############################


##############################
import rhinoscriptsyntax as rs
import random, time, sys   ###
sys.path.append("P:/")     ###                  ### diag's path to DM_lib.py  .. please keep it !                                               
sys.path.append("P:/TUGonlineUsernam/dm2/")     ### *your* path to DM_lib.py                                            
sys.path.append("P:/WWW/lukschme/dm2/") ### *your* path to DM_lib.py                                            
sys.path.append("/Users/macpro/Desktop/DM2")    ### *your* path to DM_lib.py      
import DM_lib as dm        ###                  ### "dm" is alias for DM_lib / for adressing definitions etc in "DM_lib.py"
############################## reload(dm)

rs.ShowGrid(show=0)
rs.ShowGridAxes(show=0)
rs.ViewDisplayMode(mode="Wireframe")
rs.EnableRedraw(0)

dm.PointRadius(displayModeX=0, rad=3, styl=3)                   ### displayModeX=0="Wireframe" / rad=size of points / styl=pointStyle (try 0..5) / default 3, 3
dm.printDisplay(state=1, scale=1, thickness=1, color="Display") ### state=0/1 = off/on / for showing printWidth etc

dm.eAA()

### BASIC SETUP / mandatory input:
allInOne = 1
allCoords = dm.coordsCub (what="F")
allCoords = dm.coordsCub (edge_len=10, anz_pts=10, what="A", angle=random.uniform(0,360), axe=dm.randVec(-1,1), pos=[0,0,10], allInOne=allInOne)

coordsSph = allCoords[0]
coordsCub = allCoords[1]


##### check setup - just visualization of coords
##### don't execute  @ final version of homework
if 0:
    rs.AddPoints( coordsSph )
    
    if allInOne:
        rs.AddPoints( coordsCub )
    else:
        for i,coords in enumerate(coordsCub): 
            pts = rs.AddPoints( coords )

##### end check setup

#######################################
################ HERE YOU GO AS YOU GO:
anzahl_squ = 10
coords_squ = []

#for x in range(anzahl_squ):
#    #rs.AddPoint([x,0,0])
#    for y in range(anzahl_squ):
#        #rs.AddPoint([x,y,0])
#        for z in range(anzahl_squ):
#            coords_squ.append([x,y,z])
#            #rs.AddPoint([x,y,z])
##    rs.AddPoint([1,0,0])
##    rs.AddPoint([2,0,0])
#
#for cor in coords_squ:
#    pass
#    #cor[2] += 10

coords_squ = [[x,y,z+10] for x in range(anzahl_squ) for y in range(anzahl_squ) for z in range(anzahl_squ)]
coords_squ = [[cor[0],cor[1],cor[2]+10] for cor in coords_squ]



rs.AddPoints(coords_squ)




### Random Wuerfel
#anzahl = 10
#coords = []
#for i in range(1001):
#    coords.append([random.uniform(0,anzahl),random.uniform(0,anzahl),random.uniform(0,anzahl)])
#rs.AddPoints(coords)


### Sphere

### HU vector scale mit factor zum fuellen


pS = [5,0,0]
coords_sp = []
for i in range (anzahl_squ**3):
    #rs.AddLine([0,0,0],pS)
    pS = rs.VectorRotate( pS, 10.0*random.uniform(0,200), dm.randVec())
    coords_sp.append (pS)
    #rs.AddLine([0,0,0],pX)
    #pS = rs.VectorRotate( pS, 10.0*2, [0,0,1])
    #rs.AddLine([0,0,0],pS)
rs.AddPoints(coords_sp)
coords_sp = sorted(coords_sp, key=lambda cor: cor[0])
rs.AddCurve(coords_sp,2)

for i in range(100):
    p0 = random.choice(coords_sp)
    p1 = random.choice(coords_squ)
    #rs.AddLine(p0,p1)
allCoords = coords_sp + coords_squ
random.shuffle(allCoords)
#rs.AddCurve(allCoords,1)

allConns = dm.combinate(allCoords,2)
print "allConn", len(allConns)
#print allConns[10]

conns_dists = []
for con in allConns:
    conns_dists.append([con, rs.Distance(con[0], con[1])])
    

print conns_dists[11]

#################
#dm.eDup( 1 )
dm.zA( 0.5 )



