#NEWLINE# def farthest_points( * args ) : #NEWLINE# #INDENT# 'Return the subset of points from a set of points that were\n    the furthest apart from each other in the 2D plane.\n\n    Parameters\n    ==========\n\n    args : a collection of Points on 2D plane.\n\n    Notes\n    =====\n\n    This can only be performed on a set of points whose coordinates can\n    be ordered on the number line. If there are no ties then a single\n    pair of Points will be in the set.\n\n    References\n    ==========\n\n    [1] http://code.activestate.com/recipes/117225-convex-hull-and-diameter-of-2d-point-sets/\n\n    [2] Rotating Callipers Technique\n    https://en.wikipedia.org/wiki/Rotating_calipers\n\n    Examples\n    ========\n\n    >>> from sympy.geometry import farthest_points, Point2D, Triangle\n    >>> Triangle(sss=(3, 4, 5)).args\n    (Point2D(0, 0), Point2D(3, 0), Point2D(3, 4))\n    >>> farthest_points(*_)\n    set([(Point2D(0, 0), Point2D(3, 4))])\n\n    ' #NEWLINE# from math import hypot , sqrt as _sqrt #NEWLINE# def rotatingCalipers( Points ) : #NEWLINE# #INDENT# ( U , L ) = convex_hull ( * Points , ** dict ( polygon = False ) ) #NEWLINE# if ( L is None ) : #NEWLINE# #INDENT# if isinstance ( U , Point ) : #NEWLINE# #INDENT# raise ValueError ( 'At least two distinct points must be given.' ) #NEWLINE# #UNINDENT# ( yield U . args ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# i = 0 #NEWLINE# j = ( len ( L ) - 1 ) #NEWLINE# while ( ( i < ( len ( U ) - 1 ) ) or ( j > 0 ) ) : #NEWLINE# #INDENT# ( yield ( U [ i ] , L [ j ] ) ) #NEWLINE# if ( i == ( len ( U ) - 1 ) ) : #NEWLINE# #INDENT# j -= 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( j == 0 ) : #NEWLINE# #INDENT# i += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( ( U [ ( i + 1 ) ] . y - U [ i ] . y ) * ( L [ j ] . x - L [ ( j - 1 ) ] . x ) ) > ( ( L [ j ] . y - L [ ( j - 1 ) ] . y ) * ( U [ ( i + 1 ) ] . x - U [ i ] . x ) ) ) : #NEWLINE# #INDENT# i += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# j -= 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# p = [ Point2D ( i ) for i in set ( hypot ) ] #NEWLINE# if any ( ( ( not i . is_Rational ) for j in p for i in j . args ) ) : #NEWLINE# #INDENT# def hypot( x , y ) : #NEWLINE# #INDENT# arg = ( ( x * x ) + ( y * y ) ) #NEWLINE# if arg . is_Rational : #NEWLINE# #INDENT# return _sqrt ( arg ) #NEWLINE# #UNINDENT# return sqrt ( arg ) #NEWLINE# #UNINDENT# #UNINDENT# rv = [ ] #NEWLINE# diam = 0 #NEWLINE# for pair in rotatingCalipers ( args ) : #NEWLINE# #INDENT# ( h , q ) = _ordered_points ( pair ) #NEWLINE# d = hypot ( ( h . x - q . x ) , ( h . y - q . y ) ) #NEWLINE# if ( d > diam ) : #NEWLINE# #INDENT# rv = [ ( h , q ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( d == diam ) : #NEWLINE# #INDENT# rv . append ( ( h , q ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# diam = d #NEWLINE# #UNINDENT# return set ( rv )