genCentres.py 3.35 KB
Newer Older
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
#!/usr/bin/python

import math, copy
import numpy as np
import collections
import sys

from points import *
from shapes import *

#def genCentres(innerRadius, outerRadius, hexSide, rotation=0.) :
#    
#    hexWidth = hexSide * math.sqrt(3.) 
#
#    nCentresInOuterRadius = int ( outerRadius / hexSide )
#
#    centres = [ ] # list of all centers
#    yStep = (3./2.) * hexSide
#    xStep = hexWidth
#    # generate the row 0 positive col
#    for iCentreY in range(-nCentresInOuterRadius, nCentresInOuterRadius+1) :
#        Ycentre = iCentreY * yStep 
#        for iCentreX in range(-nCentresInOuterRadius, nCentresInOuterRadius+1) :
#            if (iCentreY%2) == 0:
#                Xcentre = iCentreX * xStep 
#            else :
#                Xcentre = iCentreX * xStep + xStep/2.
#            R = math.sqrt( Xcentre*Xcentre + Ycentre*Ycentre )
#            if  R > innerRadius and R < outerRadius:                  
#                sin = math.sin(rotation)
#                cos = math.cos(rotation)
#                centres.append( [ Xcentre*cos-Ycentre*sin, Xcentre*sin+Ycentre*cos ] )
#                
#    return centres

def genCentres(innerRadius, outerRadius, hexSide, rotation=0., xTranslation=0., yTranslation=0.) :
    
    hexWidth = hexSide * math.sqrt(3.) 

    nCentresInOuterRadius = int ( outerRadius / hexSide )

    centres = {} # list of all centers
    yStep = (3./2.) * hexSide
    xStep = hexWidth
    # generate the row 0 positive col
    for row in range(-nCentresInOuterRadius, nCentresInOuterRadius+1) :
        centres[row] = {} 
      
        for column in range(-nCentresInOuterRadius, nCentresInOuterRadius+1) :
            if (column%2) == 0:
                XcentreOrg = row * xStep
            else :
                XcentreOrg = row * xStep + xStep/2.
            YcentreOrg = column * yStep 

            # transformations
            sin = math.sin(rotation)
            cos = math.cos(rotation)
                
            Xcentre = XcentreOrg*cos-YcentreOrg*sin
            Ycentre = XcentreOrg*sin+YcentreOrg*cos
            
            Xcentre = Xcentre + xTranslation 
            Ycentre = Ycentre + yTranslation 
    
            R = math.sqrt( Xcentre*Xcentre + Ycentre*Ycentre )
            if  R > innerRadius and R < outerRadius:                  
 #               Xcentre = Xcentre - hexSide
                centres[row][column] = Point2D( Xcentre, Ycentre ) 
                
    return centres


def genPanelCentres(hexSide, rotation=0., xTranslation=0., yTranslation=0.) :
    
    hexWidth = hexSide * math.sqrt(3.) 

    centres = {} # list of all centers
    yStep = (3./2.) * hexSide
    xStep = hexWidth

    # generate the row 0 positive col
    for row in range(0, 2) :
        centres[row] = {} 
      
        for column in range(0, 3) :
            if (column%2) == 0:
                XcentreOrg = row * xStep
            else :
                XcentreOrg = row * xStep + xStep/2.
            YcentreOrg = column * yStep 

            # transformations
            sin = math.sin(rotation)
            cos = math.cos(rotation)
                
            Xcentre = XcentreOrg*cos-YcentreOrg*sin
            Ycentre = XcentreOrg*sin+YcentreOrg*cos
            
            Xcentre = Xcentre + xTranslation 
            Ycentre = Ycentre + yTranslation 
            
            centres[row][column] = Point2D( Xcentre, Ycentre ) 

    return centres