Esempio n. 1
0
 def _map_point( point ):
     line = two_point_line( point, zero_3d )
     for hit in d20.face_hit( line ):
         # print hit[0]
         mapped_point = mappings.map_point( hit[0], hit[1] )
         if mapped_point:
             new_x, new_y = mapped_point
             c.circle( sx(new_x), sy(new_y), 0.5, stroke=0, fill=1  )
Esempio n. 2
0
    def _precalculate( self ):
        
        num_vertices = len( self.vertices )
        if num_vertices < 3:
            raise InvalidPolygon
            # we don't check for planarity

        vert_list = list( self.vertices )
        vert_list.append( vert_list[0] )
        
        # calculate the polygon normal
        self.plane = three_point_plane( vert_list[0], vert_list[1], vert_list[2] )
        self.normal = self.plane.normal
        
        # calculate the (directed) edges
        self.edges = list()
        self.edge_normals = list()
        for x in range( num_vertices ):
            self.edges.append( two_point_line( vert_list[x], vert_list[x+1] ) )
            self.edge_normals.append( self.edges[x].v.cross( self.normal ) )            
Esempio n. 3
0
def make_map( filename ):

    def _sphere_to_cart( theta, phi ):
        return vector_3d( \
            s.sin( theta ) * s.cos( phi ), \
            s.cos( theta ), \
            s.sin( theta ) * s.sin( phi ) )

    def _draw_this_circle( c, Circle ):
        pass
    
    def _draw_latitude_circle( c, latitude ):    
        pass
    
    def _draw_longitude_circle( c, longitude ):
        pass


    # set up our triangle
    c = get_letter_canvas( filename )

    # hex grid
    c.setStrokeColor( (0.75, 0.75, 1) )
    # c.setLineWidth( 0.001 )
    # draw_hexes( c, 2 )
    c.setLineWidth( 0.0005 )
    draw_hexes( c, 10 )

    c.setStrokeColor( (0.75,0.75,0.75) )
    d20 = Icosahedron( numeric = True )
    d20.rotate_vertices( rot_x( -s.atan2( s.GoldenRatio-1, s.GoldenRatio ).evalf() ) )
    d20.make_faces()
    mappings = face_mappings( d20 )

    face_plane = d20.faces[16].plane
    rot_mat = mappings.face_dict['q'][0]
    
    bag_o_points = dict()
 
    for lat in range( 90, 171, 5 ):
        for lon in range( 210, 331, 5 ):
            point = line_plane_intersect( two_point_line( \
                _sphere_to_cart( to_rad( lat ).evalf(), to_rad( lon ).evalf() ), zero_3d), face_plane, ray=True )
            mp = point.multiply( rot_mat )
            # c.circle( mp[0],mp[1],0.002,fill=1,stroke=0)
            bag_o_points[(lat,lon)] = mp
                
    for lat in range( 90, 169, 5 ):
        for lon in range( 210, 330, 5 ):
            p0 = bag_o_points[(lat, lon)]
            p1 = bag_o_points[(lat+5,lon)]
            p2 = bag_o_points[(lat,lon+5)]
            
            if lon % 5:
                c.setLineWidth( 0.0005 )
            else:
                c.setLineWidth( 0.001 )
            
            c.line( p0[0],p0[1],p1[0],p1[1] )
            
            if lat % 5:
                c.setLineWidth( 0.0005 )
            else:
                c.setLineWidth( 0.001 )
                
            c.line( p0[0],p0[1],p2[0],p2[1] )


    c.showPage()
    c.save()
Esempio n. 4
0
    def test_cube_hits( self ):
        d6 = Icosahedron( numeric = True )
        d6.rotate_vertices( rot_x( -s.atan2( s.GoldenRatio-1, s.GoldenRatio ).evalf() ) )
        d6.make_faces()
        print d6.face_hit( two_point_line( v_x, zero_3d))
        print d6.face_hit( two_point_line( -v_x, zero_3d))
        print d6.face_hit( two_point_line( v_y, zero_3d))
        print d6.face_hit( two_point_line( -v_y, zero_3d))
        print d6.face_hit( two_point_line( v_z, zero_3d))
        print d6.face_hit( two_point_line( -v_z, zero_3d))
        print d6.face_hit( two_point_line( v_x+v_y+v_z, zero_3d))
        print d6.face_hit( two_point_line( v_x+v_y-v_z, zero_3d))
        print d6.face_hit( two_point_line( v_x-v_y+v_z, zero_3d))
        print d6.face_hit( two_point_line( v_x-v_y-v_z, zero_3d))
        print d6.face_hit( two_point_line( -v_x+v_y+v_z, zero_3d))
        print d6.face_hit( two_point_line( -v_x+v_y-v_z, zero_3d))
        print d6.face_hit( two_point_line( -v_x-v_y+v_z, zero_3d))
        print d6.face_hit( two_point_line( -v_x-v_y-v_z, zero_3d))

        
Esempio n. 5
0
def make_map( filename ):

    def _sphere_to_cart( theta, phi ):
        return vector_3d( \
            s.sin( theta ) * s.cos( phi ), \
            s.cos( theta ), \
            s.sin( theta ) * s.sin( phi ) )

    def _draw_this_circle( c, Circle ):
        pass
    
    def _draw_latitude_circle( c, latitude ):    
        pass
    
    def _draw_longitude_circle( c, longitude ):
        pass


    # set up our triangle
    c = get_letter_canvas( filename )

    # hex grid
    c.setStrokeColor( (0.75, 0.75, 1) )
    # c.setLineWidth( 0.001 )
    # draw_hexes( c, 2 )
    c.setLineWidth( 0.0005 )
    draw_hexes( c, 10 )

    c.setStrokeColor( (0.75,0.75,0.75) )
    d20 = Icosahedron( numeric = True )
    d20.rotate_vertices( rot_x( -s.atan2( s.GoldenRatio-1, s.GoldenRatio ).evalf() ) )
    d20.make_faces()
    mappings = face_mappings( d20 )

    face_plane = d20.faces[0].plane
    rot_mat = mappings.face_dict['a'][0]
 
    for lat in range( 0, 40, 5 ):
        if lat % 5:
            c.setLineWidth( 0.0005 )
        else:
            c.setLineWidth( 0.001 )

        lat_rad = to_rad( lat ).evalf()
        try:
            point = line_plane_intersect( two_point_line( zero_3d, _sphere_to_cart( lat_rad, 0 ) ), face_plane )
            mp1 = point.multiply( rot_mat )
            point = line_plane_intersect( two_point_line( zero_3d, _sphere_to_cart( lat_rad, _pi/2 ) ), face_plane )
            mp2 = point.multiply( rot_mat )
            point = line_plane_intersect( two_point_line( zero_3d, _sphere_to_cart( lat_rad, -_pi/2 ) ), face_plane )
            mp3 = point.multiply( rot_mat )
            
            the_circle = three_point_circle( mp1[0], mp1[1], mp2[0], mp2[1], mp3[0], mp3[1] )
            c.circle( the_circle.x0, the_circle.y0, the_circle.radius, fill=0, stroke=1 )
            
        except:
            pass
  
    for lon in range( 0, 360, 5 ):
    
        if lon % 5:
            c.setLineWidth( 0.0005 )
        else:
            c.setLineWidth( 0.001 )
        
        try:
            point = line_plane_intersect( two_point_line( _sphere_to_cart( _pi/4, to_rad( lon).evalf() ), zero_3d ), face_plane )
            mp1 = point.multiply( rot_mat )
            
            end_pt = _pi/9
            if (lon % 5) == 0:
                end_pt = _pi/18
            if (lon % 10) == 0:
                end_pt = _pi/36
            if (lon % 30) == 0:
                end_pt = 0
            
            point = line_plane_intersect( two_point_line( _sphere_to_cart( end_pt, to_rad( lon).evalf() ), zero_3d ), face_plane )
            mp2 = point.multiply( rot_mat )
            c.line( mp1[0], mp1[1], mp2[0], mp2[1] )
            
        except:
            pass
            
        


    c.showPage()
    c.save()