<s> from __future__ import division <EOL> from numpy import * <EOL> import sys <EOL> def minBoundingRect ( hull_points_2d ) : <EOL> edges = zeros ( ( len ( hull_points_2d ) - <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> for i in range ( len ( edges ) ) : <EOL> edge_x = hull_points_2d [ i + <NUM_LIT:1> , <NUM_LIT:0> ] - hull_points_2d [ i , <NUM_LIT:0> ] <EOL> edge_y = hull_points_2d [ i + <NUM_LIT:1> , <NUM_LIT:1> ] - hull_points_2d [ i , <NUM_LIT:1> ] <EOL> edges [ i ] = [ edge_x , edge_y ] <EOL> edge_angles = zeros ( ( len ( edges ) ) ) <EOL> for i in range ( len ( edge_angles ) ) : <EOL> edge_angles [ i ] = math . atan2 ( edges [ i , <NUM_LIT:1> ] , edges [ i , <NUM_LIT:0> ] ) <EOL> for i in range ( len ( edge_angles ) ) : <EOL> edge_angles [ i ] = abs ( edge_angles [ i ] % ( math . pi / <NUM_LIT:2> ) ) <EOL> edge_angles = unique ( edge_angles ) <EOL> min_bbox = ( <NUM_LIT:0> , sys . maxint , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> for i in range ( len ( edge_angles ) ) : <EOL> R = array ( [ [ math . cos ( edge_angles [ i ] ) , math . cos ( edge_angles [ i ] - ( math . pi / <NUM_LIT:2> ) ) ] , [ math . cos ( edge_angles [ i ] + ( math . pi / <NUM_LIT:2> ) ) , math . cos ( edge_angles [ i ] ) ] ] ) <EOL> rot_points = dot ( R , transpose ( hull_points_2d ) ) <EOL> min_x = nanmin ( rot_points [ <NUM_LIT:0> ] , axis = <NUM_LIT:0> ) <EOL> max_x = nanmax ( rot_points [ <NUM_LIT:0> ] , axis = <NUM_LIT:0> ) <EOL> min_y = nanmin ( rot_points [ <NUM_LIT:1> ] , axis = <NUM_LIT:0> ) <EOL> max_y = nanmax ( rot_points [ <NUM_LIT:1> ] , axis = <NUM_LIT:0> ) <EOL> width = max_x - min_x <EOL> height = max_y - min_y <EOL> area = width * height <EOL> if ( area < min_bbox [ <NUM_LIT:1> ] ) : <EOL> min_bbox = ( edge_angles [ i ] , area , width , height , min_x , max_x , min_y , max_y ) <EOL> angle = min_bbox [ <NUM_LIT:0> ] <EOL> R = array ( [ [ math . cos ( angle ) , math . cos ( angle - ( math . pi / <NUM_LIT:2> ) ) ] , [ math . cos ( angle + ( math . pi / <NUM_LIT:2> ) ) , math . cos ( angle ) ] ] ) <EOL> proj_points = dot ( R , transpose ( hull_points_2d ) ) <EOL> min_x = min_bbox [ <NUM_LIT:4> ] <EOL> max_x = min_bbox [ <NUM_LIT:5> ] <EOL> min_y = min_bbox [ <NUM_LIT:6> ] <EOL> max_y = min_bbox [ <NUM_LIT:7> ] <EOL> center_x = ( min_x + max_x ) / <NUM_LIT:2> <EOL> center_y = ( min_y + max_y ) / <NUM_LIT:2> <EOL> center_point = dot ( [ center_x , center_y ] , R ) <EOL> corner_points = zeros ( ( <NUM_LIT:4> , <NUM_LIT:2> ) ) <EOL> corner_points [ <NUM_LIT:0> ] = dot ( [ max_x , min_y ] , R ) <EOL> corner_points [ <NUM_LIT:1> ] = dot ( [ min_x , min_y ] , R ) <EOL> corner_points [ <NUM_LIT:2> ] = dot ( [ min_x , max_y ] , R ) <EOL> corner_points [ <NUM_LIT:3> ] = dot ( [ max_x , max_y ] , R ) <EOL> return ( angle , min_bbox [ <NUM_LIT:1> ] , min_bbox [ <NUM_LIT:2> ] , min_bbox [ <NUM_LIT:3> ] , center_point , corner_points ) </s>
