<s> from alg3dpy . vector import Vec <EOL> from alg3dpy . angles import cosplanevec , sinplanevec , cos2vecs , sin2vecs <EOL> from alg3dpy . plane import Plane <EOL> from alg3dpy . point import Point <EOL> import random as rdm <EOL> import numpy as np <EOL> import mapy <EOL> from mapy . reader import user_setattr <EOL> from mapy . constants import * <EOL> def common__str__ ( text , csys ) : <EOL> if csys . rebuilt : <EOL> return '<STR_LIT>' % ( text , csys . id , csys . o [ <NUM_LIT:0> ] , csys . o [ <NUM_LIT:1> ] , csys . o [ <NUM_LIT:2> ] , csys . x [ <NUM_LIT:0> ] , csys . x [ <NUM_LIT:1> ] , csys . x [ <NUM_LIT:2> ] , csys . y [ <NUM_LIT:0> ] , csys . y [ <NUM_LIT:1> ] , csys . y [ <NUM_LIT:2> ] , csys . z [ <NUM_LIT:0> ] , csys . z [ <NUM_LIT:1> ] , csys . z [ <NUM_LIT:2> ] ) <EOL> else : <EOL> return '<STR_LIT>' % ( text , csys . id ) <EOL> class Coord ( object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:o>' , '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT:z>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , id = None , o = None , rcid = None , z = None , vecxz = None ) : <EOL> self . card = None <EOL> self . entryclass = None <EOL> inputs = { } <EOL> if id . __class__ . __name__ == '<STR_LIT>' : <EOL> inputs = id <EOL> id = None <EOL> self . id = id <EOL> self . rcid = rcid <EOL> self . rcobj = None <EOL> self . o = o <EOL> self . x = None <EOL> self . y = None <EOL> self . z = z <EOL> self . xy = None <EOL> self . xz = None <EOL> self . yz = None <EOL> self . vecxz = vecxz <EOL> self . a1 = None <EOL> self . a2 = None <EOL> self . a3 = None <EOL> self . b1 = None <EOL> self . b2 = None <EOL> self . b3 = None <EOL> self . c1 = None <EOL> self . c2 = None <EOL> self . c3 = None <EOL> self . ida = None <EOL> self . idb = None <EOL> self . g1a = None <EOL> self . g2a = None <EOL> self . g3a = None <EOL> self . g1b = None <EOL> self . g2b = None <EOL> self . g3b = None <EOL> self . model = None <EOL> self . rebuilt = False <EOL> self . read_inputs ( inputs ) <EOL> def read_inputs ( self , inputs = { } ) : <EOL> if len ( inputs ) > <NUM_LIT:0> : <EOL> self = user_setattr ( self , inputs ) <EOL> if self . id == None and self . ida < > None : <EOL> self . id = int ( self . ida ) <EOL> CSYSGLOBAL = mapy . constants . CSYSGLOBAL <EOL> self . rcid = <NUM_LIT:0> <EOL> self . rcobj = CSYSGLOBAL <EOL> def add2model ( self , model ) : <EOL> self . model = model <EOL> model . coorddict [ self . id ] = self <EOL> if self . idb < > None and self . g1b < > None and self . g2b < > None and self . g3b < > None : <EOL> if self . __class__ . __name__ . find ( '<STR_LIT>' ) > - <NUM_LIT:1> : <EOL> newcsys = CoordR ( int ( self . idb ) , None , None , None , None ) <EOL> if self . __class__ . __name__ . find ( '<STR_LIT>' ) > - <NUM_LIT:1> : <EOL> newcsys = CoordC ( int ( self . idb ) , None , None , None , None ) <EOL> if self . __class__ . __name__ . find ( '<STR_LIT>' ) > - <NUM_LIT:1> : <EOL> newcsys = CoordS ( int ( self . idb ) , None , None , None , None ) <EOL> newcsys . ida = self . idb <EOL> newcsys . id = self . idb <EOL> newcsys . rcid = self . rcid <EOL> newcsys . rcobj = self . rcobj <EOL> newcsys . card = self . card <EOL> newcsys . entryclass = self . entryclass <EOL> newcsys . g1a = self . g1b <EOL> newcsys . g2a = self . g2b <EOL> newcsys . g3a = self . g3b <EOL> newcsys . model = model <EOL> model . coorddict [ newcsys . id ] = newcsys <EOL> self . idb = None <EOL> self . g1b = None <EOL> self . g2b = None <EOL> self . g3b = None <EOL> def check_to_rebuild ( self ) : <EOL> if self . a1 < > None and self . a2 < > None and self . a3 < > None and self . b1 < > None and self . b2 < > None and self . b3 < > None and self . c1 < > None and self . c2 < > None and self . c3 < > None : <EOL> rcobj = self . model . coorddict [ int ( self . rcid ) ] <EOL> if rcobj . rebuilt : <EOL> return True <EOL> else : <EOL> return False <EOL> elif self . ida < > None and self . g1a < > None and self . g2a < > None and self . g3a < > None : <EOL> g1a = self . model . griddict [ int ( self . g1a ) ] <EOL> g2a = self . model . griddict [ int ( self . g2a ) ] <EOL> g3a = self . model . griddict [ int ( self . g3a ) ] <EOL> if not g1a . rebuilt or not g2a . rebuilt or not g3a . rebuilt : <EOL> return False <EOL> else : <EOL> return True <EOL> else : <EOL> print '<STR_LIT>' <EOL> raise <EOL> def rebuild ( self , rcobj = None , force_new_axis = False ) : <EOL> new_axis = False <EOL> if self . o == None or self . z == None or self . vecxz == None : <EOL> new_axis = True <EOL> if not new_axis : <EOL> if self . o . __class__ . __name__ . find ( '<STR_LIT>' ) == - <NUM_LIT:1> : <EOL> self . o = Point ( np . array ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , dtype = FLOAT ) ) <EOL> if self . z == None : <EOL> print '<STR_LIT>' <EOL> raise <EOL> if self . vecxz == None : <EOL> print '<STR_LIT>' <EOL> raise <EOL> if self . z . __class__ . __name__ . find ( '<STR_LIT>' ) == - <NUM_LIT:1> : <EOL> self . z = Vec ( self . z ) <EOL> if self . vecxz . __class__ . __name__ . find ( '<STR_LIT>' ) == - <NUM_LIT:1> : <EOL> self . vecxz = Vec ( self . vecxz ) <EOL> if new_axis or force_new_axis : <EOL> if self . model == None : <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> raise <EOL> if self . a1 < > None and self . a2 < > None and self . a3 < > None and self . b1 < > None and self . b2 < > None and self . b3 < > None and self . c1 < > None and self . c2 < > None and self . c3 < > None : <EOL> self . rcobj = self . model . coorddict [ int ( self . rcid ) ] <EOL> if self . rcobj . rebuilt : <EOL> p1 = np . array ( [ self . a1 , self . a2 , self . a3 ] , dtype = FLOAT ) <EOL> p2 = np . array ( [ self . b1 , self . b2 , self . b3 ] , dtype = FLOAT ) <EOL> p3 = np . array ( [ self . c1 , self . c2 , self . c3 ] , dtype = FLOAT ) <EOL> CSYSGLOBAL = mapy . constants . CSYSGLOBAL <EOL> p1 = self . rcobj . transform ( p1 , CSYSGLOBAL ) <EOL> p2 = self . rcobj . transform ( p2 , CSYSGLOBAL ) <EOL> p3 = self . rcobj . transform ( p3 , CSYSGLOBAL ) <EOL> self . rcid = CSYSGLOBAL . id <EOL> self . rcobj = CSYSGLOBAL <EOL> self . o = p1 <EOL> self . z = p2 - p1 <EOL> self . vecxz = p3 - p1 <EOL> else : <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> raise <EOL> elif self . ida < > None and self . g1a < > None and self . g2a < > None and self . g3a < > None : <EOL> g1a = self . model . griddict [ int ( self . g1a ) ] <EOL> g2a = self . model . griddict [ int ( self . g2a ) ] <EOL> g3a = self . model . griddict [ int ( self . g3a ) ] <EOL> if not g1a . rebuilt or not g2a . rebuilt or not g3a . rebuilt : <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> raise <EOL> self . o = Point ( g1a . array ) <EOL> self . z = g2a - g1a <EOL> self . vecxz = g3a - g1a <EOL> else : <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> for slot in self . __slots__ : <EOL> print '<STR_LIT:\t>' + slot + '<STR_LIT>' , getattr ( self , slot ) <EOL> raise <EOL> self . y = self . z . cross ( self . vecxz ) <EOL> self . x = self . y . cross ( self . z ) <EOL> self . xy = Plane ( self . z [ <NUM_LIT:0> ] , self . z [ <NUM_LIT:1> ] , self . z [ <NUM_LIT:2> ] , self . o . mod ( ) ) <EOL> self . xz = Plane ( - self . y [ <NUM_LIT:0> ] , - self . y [ <NUM_LIT:1> ] , - self . y [ <NUM_LIT:2> ] , self . o . mod ( ) ) <EOL> self . yz = Plane ( self . x [ <NUM_LIT:0> ] , self . x [ <NUM_LIT:1> ] , self . x [ <NUM_LIT:2> ] , self . o . mod ( ) ) <EOL> self . rebuilt = True <EOL> def transform ( self , vec , new_csys ) : <EOL> """<STR_LIT>""" <EOL> if new_csys == None : <EOL> new_csys = CSYSGLOBAL <EOL> vec_cr = self . vec2cr ( vec ) <EOL> R = self . Rmatrix ( new_csys ) <EOL> vec_rot = np . dot ( R , vec_cr ) <EOL> vec_t = self . translate ( vec_rot , new_csys ) <EOL> vec_final = new_csys . cr2me ( vec_t ) <EOL> return vec_final <EOL> def translate ( self , vec , newcr ) : <EOL> """<STR_LIT>""" <EOL> vec = Vec ( vec ) <EOL> vec_t = vec + newcr . o + self . o <EOL> return vec_t <EOL> def Rmatrix ( self , newcr ) : <EOL> """<STR_LIT>""" <EOL> cosb = cosplanevec ( newcr . xy , self . x ) <EOL> sinb = sinplanevec ( newcr . xy , self . x ) <EOL> cosg = cosplanevec ( newcr . xz , self . x ) <EOL> sing = sinplanevec ( newcr . xz , self . x ) <EOL> tmpT = np . array ( [ [ - sing , ZER , ZER ] , <EOL> [ ZER , cosg , ZER ] , <EOL> [ ZER , ZER , ZER ] ] ) <EOL> Y2 = Vec ( np . dot ( tmpT , newcr . y . array ) ) <EOL> cosa = cos2vecs ( Y2 , self . y ) <EOL> sina = sin2vecs ( Y2 , self . y ) <EOL> Rself = np . array ( [ [ cosb * cosg , cosb * sing , - sinb ] , [ - cosa * sing + cosg * sina * sinb , cosa * cosg + sina * sinb * sing , cosb * sina ] , [ sina * sing + cosa * cosg * sinb , - cosg * sina + cosa * sinb * sing , cosa * cosb ] ] , dtype = FLOAT ) <EOL> R2new = Rself . transpose ( ) <EOL> return R2new <EOL> def R2basic ( self ) : <EOL> return self . Rmatrix ( CSYSGLOBAL ) <EOL> class CoordR ( Coord ) : <EOL> def __init__ ( self , id = None , o = None , rcid = None , z = None , vecxz = None ) : <EOL> super ( CoordR , self ) . __init__ ( id , o , rcid , z , vecxz ) <EOL> def __str__ ( self ) : <EOL> return common__str__ ( '<STR_LIT>' , self ) <EOL> def vec2cr ( self , vec ) : <EOL> return vec <EOL> def cr2me ( self , vec ) : <EOL> return vec <EOL> class CoordC ( Coord ) : <EOL> def __init__ ( self , id = None , o = None , rcid = None , z = None , vecxz = None ) : <EOL> super ( CoordC , self ) . __init__ ( id , o , rcid , z , vecxz ) <EOL> def vec2cr ( self , vec ) : <EOL> """<STR_LIT>""" <EOL> T = np . array ( [ [ np . cos ( vec [ <NUM_LIT:1> ] ) , ZER , ZER ] , <EOL> [ ZER , np . sin ( vec [ <NUM_LIT:1> ] ) , ZER ] , <EOL> [ ZER , ZER , ONE ] ] ) <EOL> tmp = np . array ( [ vec [ <NUM_LIT:0> ] , vec [ <NUM_LIT:0> ] , vec [ <NUM_LIT:2> ] ] , dtype = FLOAT ) <EOL> vec_cr = np . dot ( T , tmp ) <EOL> return vec_cr <EOL> def cr2me ( self , vec ) : <EOL> """<STR_LIT>""" <EOL> T = np . array ( [ [ np . sqrt ( vec [ <NUM_LIT:0> ] ** <NUM_LIT:2> + vec [ <NUM_LIT:1> ] ** <NUM_LIT:2> ) , ZER , ZER ] , <EOL> [ ZER , np . arctan ( vec [ <NUM_LIT:1> ] / vec [ <NUM_LIT:0> ] ) , ZER ] , <EOL> [ ZER , ZER , ONE ] ] ) <EOL> tmp = np . array ( [ <NUM_LIT:1> , <NUM_LIT:1> , vec [ <NUM_LIT:2> ] ] , dtype = FLOAT ) <EOL> return np . dot ( T , tmp ) <EOL> def __str__ ( self ) : <EOL> return common__str__ ( '<STR_LIT>' , self ) <EOL> class CoordS ( Coord ) : <EOL> def __init__ ( self , id = None , o = None , rcid = None , z = None , vecxz = None ) : <EOL> super ( CoordS , self ) . __init__ ( id , o , rcid , z , vecxz ) <EOL> def vec2cr ( self , vec ) : <EOL> """<STR_LIT>""" <EOL> T = np . array ( [ [ np . sin ( vec [ <NUM_LIT:1> ] ) * np . cos ( vec [ <NUM_LIT:2> ] ) , ZER , ZER ] , <EOL> [ ZER , np . sin ( vec [ <NUM_LIT:1> ] ) * np . sin ( vec [ <NUM_LIT:2> ] ) , ZER ] , <EOL> [ ZER , ZER , np . cos ( vec [ <NUM_LIT:1> ] ) ] ] ) <EOL> tmp = np . array ( [ vec [ <NUM_LIT:0> ] , vec [ <NUM_LIT:0> ] , vec [ <NUM_LIT:0> ] ] , dtype = FLOAT ) <EOL> return np . dot ( T , tmp ) <EOL> def cr2me ( self , vec ) : <EOL> """<STR_LIT>""" <EOL> h = vec [ <NUM_LIT:0> ] ** <NUM_LIT:2> + vec [ <NUM_LIT:1> ] ** <NUM_LIT:2> <EOL> T = np . array ( [ [ np . sqrt ( h + vec [ <NUM_LIT:2> ] ** <NUM_LIT:2> ) , ZER , ZER ] , <EOL> [ ZER , np . arctan ( np . sqrt ( h ) / vec [ <NUM_LIT:2> ] ) , ZER ] , <EOL> [ ZER , ZER , np . arctan ( vec [ <NUM_LIT:1> ] / vec [ <NUM_LIT:0> ] ) ] ] ) <EOL> tmp = np . array ( [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] , dtype = FLOAT ) <EOL> return np . dot ( T , tmp ) <EOL> def __str__ ( self ) : <EOL> return common__str__ ( '<STR_LIT>' , self ) </s>
