def getListDiffs( args ): old = None for i in args: if old is not None: yield( subtract( i, old ) ) old = i
def getCumulativeListDiffs( args ): result = [ ] first = None for i in args: if first is None: first = i else: yield subtract( i, first )
def getTriangleArea( a, b, c ): if not isinstance( a, RPNMeasurement ): return getTriangleArea( RPNMeasurement( real( a ), 'meter' ), b, c ) if a.getDimensions( ) != { 'length' : 1 }: raise ValueError( '\'triangle_area\' argument 1 must be a length' ) if not isinstance( b, RPNMeasurement ): return getTriangleArea( a, RPNMeasurement( real( b ), 'meter' ), c ) if b.getDimensions( ) != { 'length' : 1 }: raise ValueError( '\'triangle_area\' argument 2 must be a length' ) if not isinstance( c, RPNMeasurement ): return getTriangleArea( a, b, RPNMeasurement( real( c ), 'meter' ) ) if b.getDimensions( ) != { 'length' : 1 }: raise ValueError( '\'triangle_area\' argument 3 must be a length' ) if add( a, b ).isNotLarger( c ) or add( b, c ).isNotLarger( a ) or add( a, c ).isNotLarger( b ): raise ValueError( 'invalid triangle, the sum of any two sides must be longer than the third side' ) s = divide( getSum( [ a, b, c ] ), 2 ) # semi-perimeter return getRoot( getProduct( [ s, subtract( s, a ), subtract( s, b ), subtract( s, c ) ] ), 2 )
def getAntitransitTime( body, location, date ): if isinstance( location, str ): location = getLocation( location ) if not isinstance( body, ephem.Body ) or not isinstance( location, RPNLocation ) or \ not isinstance( date, RPNDateTime ): raise ValueError( 'expected an astronomical object, a locaton and a date-time' ) location.observer.date = date.to( 'utc' ).format( ) location.observer.horizon = '0' ephemSetting = location.observer.next_setting( body ) setting = RPNDateTime.convertFromEphemDate( ephemSetting ).getLocalTime( ) rising = RPNDateTime.convertFromEphemDate( location.observer.next_rising( body, start=ephemSetting ) ).getLocalTime( ) return subtract( rising, setting )