<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> import math <EOL> from . geo_euclidean import Vector <EOL> eps = <NUM_LIT> <EOL> class Point ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , x = None , y = None , z = None ) : <EOL> if x is None and y is None and z is None : <EOL> self . _pos3d = Vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> elif x is not None and y is not None and z is None : <EOL> self . _pos3d = Vector ( x , y , math . sqrt ( <NUM_LIT:1> - x ** <NUM_LIT:2> - y ** <NUM_LIT:2> ) ) <EOL> elif x is not None and y is not None and z is not None : <EOL> self . _pos3d = Vector ( x , y , z ) . normalized ( ) <EOL> else : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> @ classmethod <EOL> def fromvector ( cls , v ) : <EOL> """<STR_LIT>""" <EOL> w = v . normalized ( ) <EOL> return cls ( w . x , w . y , w . z ) <EOL> @ property <EOL> def vector ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _pos3d <EOL> @ property <EOL> def list ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ self . _pos3d . x , self . _pos3d . y , self . _pos3d . z ] <EOL> @ vector . setter <EOL> def vector ( self , v ) : <EOL> self . _pos3d . x = v . x <EOL> self . _pos3d . y = v . y <EOL> self . _pos3d . z = v . z <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . join ( <EOL> ( self . __class__ . __name__ , '<STR_LIT:(>' , str ( self . _pos3d . x ) , '<STR_LIT:U+002CU+0020>' , str ( self . _pos3d . y ) , '<STR_LIT:U+002CU+0020>' , str ( self . _pos3d . z ) , '<STR_LIT:)>' ) ) <EOL> def distance ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return math . acos ( self . _pos3d . dot ( other . vector ) ) <EOL> def distances ( self , points ) : <EOL> """<STR_LIT>""" <EOL> return [ math . acos ( self . _pos3d . dot ( p . vector ) ) for p in points ] <EOL> class Line ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , a , b ) : <EOL> self . a = Point . fromvector ( a . vector ) <EOL> self . b = Point . fromvector ( b . vector ) <EOL> def get_point ( self , l ) : <EOL> d = self . a . distance ( self . b ) <EOL> n = self . a . vector . cross ( self . b . vector ) <EOL> p = Point . fromvector ( self . a . vector ) <EOL> p . vector . rotate ( l * d , n ) <EOL> return p <EOL> def distance ( self , p ) : <EOL> n = Point . fromvector ( self . a . vector . cross ( self . b . vector ) ) <EOL> return abs ( math . pi / <NUM_LIT:2> - n . distance ( p ) ) <EOL> class Circle ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , a , b , c = None ) : <EOL> if c is None : <EOL> self . c = Point . fromvector ( a . vector ) <EOL> self . x = Point . fromvector ( b . vector ) <EOL> else : <EOL> self . c = Point . fromvector ( ( b . vector - a . vector ) . cross ( c . vector - b . vector ) . normalized ( ) ) <EOL> self . x = Point . fromvector ( b . vector ) <EOL> def get_point ( self , l ) : <EOL> return Point . fromvector ( self . x . vector . rotated ( l , self . c . vector ) ) <EOL> def get_radius ( self ) : <EOL> return self . c . distance ( self . x ) <EOL> def angle ( self , p ) : <EOL> c = self . c . vector * self . x . vector . dot ( self . c . vector ) <EOL> a = ( self . x . vector - c ) . normalized ( ) <EOL> b = ( p . vector - c ) . normalized ( ) <EOL> return math . acos ( a . dot ( b ) ) <EOL> def distance ( self , p ) : <EOL> return abs ( self . c . distance ( p ) - self . c . distance ( self . x ) ) <EOL> class Construct ( object ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def midpoint ( a , b ) : <EOL> """<STR_LIT>""" <EOL> return Point . fromvector ( ( a . vector + b . vector ) / <NUM_LIT:2> ) <EOL> @ staticmethod <EOL> def line_intersect_line ( k , l ) : <EOL> c1 = k . a . vector . cross ( k . b . vector ) <EOL> c2 = l . a . vector . cross ( l . b . vector ) <EOL> p = c1 . cross ( c2 ) <EOL> return Point . fromvector ( p ) , Point . fromvector ( p * - <NUM_LIT:1> ) <EOL> @ staticmethod <EOL> def line_intersect_circle ( line , circle ) : <EOL> cross_line = line . a . vector . cross ( line . b . vector ) <EOL> cross_lc = cross_line . cross ( circle . c . vector ) <EOL> dot_circle = circle . c . vector . dot ( circle . x . vector ) <EOL> if abs ( cross_lc . z ) > eps : <EOL> a = cross_lc . dot ( cross_lc ) <EOL> b = <NUM_LIT:2> * dot_circle * cross_line . cross ( cross_lc ) . z <EOL> circle = dot_circle * dot_circle * ( cross_line . x ** <NUM_LIT:2> + cross_line . y ** <NUM_LIT:2> ) - cross_lc . z ** <NUM_LIT:2> <EOL> s = math . sqrt ( b ** <NUM_LIT:2> - <NUM_LIT:4> * a * circle ) <EOL> z1 = ( s - b ) / ( <NUM_LIT:2> * a ) <EOL> x1 = ( cross_lc . x * z1 - cross_line . y * dot_circle ) / cross_lc . z <EOL> y1 = ( cross_lc . y * z1 + cross_line . x * dot_circle ) / cross_lc . z <EOL> z2 = - ( s + b ) / ( <NUM_LIT:2> * a ) <EOL> x2 = ( cross_lc . x * z2 - cross_line . y * dot_circle ) / cross_lc . z <EOL> y2 = ( cross_lc . y * z2 + cross_line . x * dot_circle ) / cross_lc . z <EOL> return Point ( x1 , y1 , z1 ) , Point ( x2 , y2 , z2 ) <EOL> else : <EOL> return None <EOL> @ staticmethod <EOL> def circle_intersect_circle ( a , b ) : <EOL> ac = a . c . vector <EOL> bc = b . c . vector <EOL> cross = ac . cross ( bc ) <EOL> dot_a = ac . dot ( a . x . vector ) <EOL> dot_b = bc . dot ( b . x . vector ) <EOL> if abs ( cross . z ) > eps : <EOL> a = cross . dot ( cross ) <EOL> b = <NUM_LIT:2> * ( dot_b * ac . cross ( cross ) . z - dot_a * bc . cross ( cross ) . z ) <EOL> c = dot_b ** <NUM_LIT:2> * ( ac . x ** <NUM_LIT:2> + ac . y ** <NUM_LIT:2> ) - <NUM_LIT:2> * dot_a * dot_b * ( ac . x * bc . x + ac . y * bc . y ) + dot_a ** <NUM_LIT:2> * ( <EOL> bc . x ** <NUM_LIT:2> + bc . y ** <NUM_LIT:2> ) - cross . z ** <NUM_LIT:2> <EOL> s = math . sqrt ( b ** <NUM_LIT:2> - <NUM_LIT:4> * a * c ) <EOL> z1 = ( s - b ) / ( <NUM_LIT:2> * a ) <EOL> x1 = ( bc . y * dot_a - ac . y * dot_b + cross . x * z1 ) / cross . z <EOL> y1 = ( ac . x * dot_b - bc . x * dot_a + cross . y * z1 ) / cross . z <EOL> z2 = - ( s + b ) / ( <NUM_LIT:2> * a ) <EOL> x2 = ( bc . y * dot_a - ac . y * dot_b + cross . x * z2 ) / cross . z <EOL> y2 = ( ac . x * dot_b - bc . x * dot_a + cross . y * z2 ) / cross . z <EOL> return Point ( x1 , y1 , z1 ) , Point ( x2 , y2 , z2 ) <EOL> else : <EOL> return None </s>
