Exemple #1
0
def getNthNonagonalSquareNumberOperator(n):
    p = fsum([fmul(8, sqrt(7)), fmul(9, sqrt(14)), fmul(-7, sqrt(2)), -28])
    q = fsum([fmul(7, sqrt(2)), fmul(9, sqrt(14)), fmul(-8, sqrt(7)), -28])
    sign = power(-1, n)

    index = fdiv(
        fsub(
            fmul(fadd(p, fmul(q, sign)),
                 power(fadd(fmul(2, sqrt(2)), sqrt(7)), n)),
            fmul(fsub(p, fmul(q, sign)),
                 power(fsub(fmul(2, sqrt(2)), sqrt(7)), fsub(n, 1)))), 112)

    return nint(power(nint(index), 2))
Exemple #2
0
def getNthNonagonalSquareNumber( n ):
    if real( n ) < 0:
        ValueError( '' )

    p = fsum( [ fmul( 8, sqrt( 7 ) ), fmul( 9, sqrt( 14 ) ), fmul( -7, sqrt( 2 ) ), -28 ] )
    q = fsum( [ fmul( 7, sqrt( 2 ) ), fmul( 9, sqrt( 14 ) ), fmul( -8, sqrt( 7 ) ), -28 ] )
    sign = power( -1, real_int( n ) )

    index = fdiv( fsub( fmul( fadd( p, fmul( q, sign ) ),
                              power( fadd( fmul( 2, sqrt( 2 ) ), sqrt( 7 ) ), n ) ),
                        fmul( fsub( p, fmul( q, sign ) ),
                              power( fsub( fmul( 2, sqrt( 2 ) ), sqrt( 7 ) ), fsub( n, 1 ) ) ) ), 112 )

    return nint( power( nint( index ), 2 ) )
Exemple #3
0
def getNthDecagonalCenteredSquareNumberOperator(n):
    sqrt10 = sqrt(10)

    dps = 7 * int(n)

    if mp.dps < dps:
        mp.dps = dps

    return nint(
        floor(
            fsum([
                fdiv(1, 8),
                fmul(fdiv(7, 16),
                     power(fsub(721, fmul(228, sqrt10)), fsub(n, 1))),
                fmul(
                    fmul(fdiv(1, 8),
                         power(fsub(721, fmul(228, sqrt10)), fsub(n, 1))),
                    sqrt10),
                fmul(
                    fmul(fdiv(1, 8),
                         power(fadd(721, fmul(228, sqrt10)), fsub(n, 1))),
                    sqrt10),
                fmul(fdiv(7, 16),
                     power(fadd(721, fmul(228, sqrt10)), fsub(n, 1)))
            ])))
Exemple #4
0
def _view_cone_calc(lat_geoc, lon_geoc, sat_pos, sat_vel, q_max, m):
    """Semi-private: Performs the viewing cone visibility calculation for the day defined by m.
    Note: This function is based on a paper titled "rapid satellite-to-site visibility determination
    based on self-adaptive interpolation technique"  with some variation to account for interaction
    of viewing cone with the satellite orbit.

    Args:
        lat_geoc (float): site location in degrees at the start of POI
        lon_geoc (float): site location in degrees at the start of POI
        sat_pos (Vector3D): position of satellite (at the same time as sat_vel)
        sat_vel (Vector3D): velocity of satellite (at the same time as sat_pos)
        q_max (float): maximum orbital radius
        m (int): interval offsets (number of days after initial condition)

    Returns:
        Returns 4 numbers representing times at which the orbit is tangent to the viewing cone,

    Raises:
        ValueError: if any of the 4 formulas has a complex answer. This happens when the orbit and
        viewing cone do not intersect or only intersect twice.

    Note: With more analysis it should be possible to find a correct interval even in the case
        where there are only two intersections but this is beyond the current scope of the project.
    """
    lat_geoc = (lat_geoc * mp.pi) / 180
    lon_geoc = (lon_geoc * mp.pi) / 180

    # P vector (also referred  to as orbital angular momentum in the paper) calculations
    p_unit_x, p_unit_y, p_unit_z = cross(sat_pos, sat_vel) / (mp.norm(sat_pos) * mp.norm(sat_vel))

    # Following are equations from Viewing cone section of referenced paper
    r_site_magnitude = earth_radius_at_geocetric_lat(lat_geoc)
    gamma1 = THETA_NAUGHT + mp.asin((r_site_magnitude * mp.sin((mp.pi / 2) + THETA_NAUGHT)) / q_max)
    gamma2 = mp.pi - gamma1

    # Note: atan2 instead of atan to get the correct quadrant.
    arctan_term = mp.atan2(p_unit_x, p_unit_y)
    arcsin_term_gamma, arcsin_term_gamma2 = [(mp.asin((mp.cos(gamma) - p_unit_z * mp.sin(lat_geoc))
                                             / (mp.sqrt((p_unit_x ** 2) + (p_unit_y ** 2)) *
                                              mp.cos(lat_geoc)))) for gamma in [gamma1, gamma2]]

    angle_1 = (arcsin_term_gamma - lon_geoc - arctan_term + 2 * mp.pi * m)
    angle_2 = (mp.pi - arcsin_term_gamma - lon_geoc - arctan_term + 2 * mp.pi * m)
    angle_3 = (arcsin_term_gamma2 - lon_geoc - arctan_term + 2 * mp.pi * m)
    angle_4 = (mp.pi - arcsin_term_gamma2 - lon_geoc - arctan_term + 2 * mp.pi * m)
    angles = [angle_1, angle_2, angle_3, angle_4]

    # Check for complex answers
    if any([not isinstance(angle, mp.mpf) for angle in angles]):
        raise ValueError()

    # Map all angles to 0 to 2*pi
    for idx in range(len(angles)):
        while angles[idx] < 0:
            angles[idx] += 2 * mp.pi
        while angles[idx] > 2 * mp.pi:
            angles[idx] -= 2 * mp.pi

    # Calculate the corresponding time for each angle and return
    return [mp.nint((1 / ANGULAR_VELOCITY_EARTH) * angle) for angle in angles]
Exemple #5
0
def findNthPolygonalNumber( n, k ):
    if real_int( k ) < 3:
        raise ValueError( 'the number of sides of the polygon cannot be less than 3,' )

    return nint( fdiv( fsum( [ sqrt( fsum( [ power( k, 2 ), fprod( [ 8, k, real( n ) ] ),
                                             fneg( fmul( 8, k ) ), fneg( fmul( 16, n ) ), 16 ] ) ),
                               k, -4 ] ), fmul( 2, fsub( k, 2 ) ) ) )
Exemple #6
0
def getMPFIntegerAsString(n):
    '''Turns an mpmath mpf integer value into a string for use by lexicographic
    operators.'''
    if n == 0:
        return '0'

    return nstr(nint(n), int(floor(log10(n) + 10)))[:-2]
Exemple #7
0
def getNthNonagonalOctagonalNumber( n ):
    sqrt6 = sqrt( 6 )
    sqrt7 = sqrt( 7 )

    return nint( floor( fdiv( fmul( fsub( fmul( 11, sqrt7 ), fmul( 9, sqrt6 ) ),
                                    power( fadd( sqrt6, sqrt7 ), fsub( fmul( 8, real_int( n ) ), 5 ) ) ),
                              672 ) ) )
Exemple #8
0
def getMPFIntegerAsString( n ):
    '''Turns an mpmath mpf integer value into a string for use by lexicographic
    operators.'''
    if n == 0:
        return '0'
    else:
        return nstr( nint( n ), int( floor( log10( n ) + 10  ) ) )[ : -2 ]
Exemple #9
0
def getNthOctagonalHeptagonalNumberOperator(n):
    return nint(
        floor(
            fdiv(
                fmul(fadd(17, fmul(sqrt(30), 2)),
                     power(fadd(sqrt(5), sqrt(6)), fsub(fmul(8, n), 6))),
                480)))
Exemple #10
0
def getNthOctagonalTriangularNumber( n ):
    sign = power( -1, real( n ) )

    return nint( floor( fdiv( fmul( fsub( 7, fprod( [ 2, sqrt( 6 ), sign ] ) ),
                                    power( fadd( sqrt( 3 ), sqrt( 2 ) ),
                                           fsub( fmul( 4, real_int( n ) ), 2 ) ) ),
                              96 ) ) )
Exemple #11
0
def findCenteredPolygonalNumber( n, k ):
    if real_int( k ) < 3:
        raise ValueError( 'the number of sides of the polygon cannot be less than 3,' )

    s = fdiv( k, 2 )

    return nint( fdiv( fadd( sqrt( s ),
                       sqrt( fsum( [ fmul( 4, real( n ) ), s, -4 ] ) ) ), fmul( 2, sqrt( s ) ) ) )
Exemple #12
0
def getNthOctagonalTriangularNumberOperator(n):
    sign = power(-1, n)

    return nint(
        floor(
            fdiv(
                fmul(fsub(7, fprod([2, sqrt(6), sign])),
                     power(fadd(sqrt(3), sqrt(2)), fsub(fmul(4, n), 2))), 96)))
Exemple #13
0
def duplicateOperation( valueList ):
    if g.duplicateOperations > 0:
        raise ValueError( "'dupop' must be followed by another operation" )

    if isinstance( valueList[ -1 ], list ):
        raise ValueError( "'dupop' cannot accept a list argument" )

    g.duplicateOperations = nint( floor( valueList.pop( ) ) )
Exemple #14
0
def getNthNonagonalHeptagonalNumberOperator(n):
    sqrt35 = sqrt(35)

    return nint(
        floor(
            fdiv(
                fmul(fadd(39, fmul(4, sqrt35)),
                     power(fadd(6, sqrt35), fsub(fmul(4, n), 3))), 560)))
Exemple #15
0
def quantize(c, shr, dtype=numpy.int64):
    assert numpy.all(shr >= 1)
    c = mpmath.matrix(
        [[mpmath.ldexp(c[i, j] + .5, int(shr[j]))
          for j in range(c.cols - 1)] + [c[i, c.cols - 1]]
         for i in range(c.rows)])
    return numpy.array([[int(mpmath.nint(c[i, j])) for j in range(c.cols)]
                        for i in range(c.rows)], dtype)
Exemple #16
0
def getNthDecagonalTriangularNumberOperator(n):
    return nint(
        floor(
            fdiv(
                fmul(fadd(9, fprod([4, sqrt(2),
                                    power(-1, fadd(n, 1))])),
                     power(fadd(1, sqrt(2)), fsub(fmul(4, fadd(n, 1)), 6))),
                64)))
Exemple #17
0
def getNthDecagonalHeptagonalNumber( n ):
    sqrt10 = sqrt( 10 )

    return nint( floor( fdiv( fprod( [ fsub( 11,
                                             fmul( fmul( 2, sqrt10 ),
                                                   power( -1, real_int( n ) ) ) ),
                                       fadd( 1, sqrt10 ),
                                       power( fadd( 3, sqrt10 ),
                                              fsub( fmul( 4, n ), 3 ) ) ] ), 320 ) ) )
Exemple #18
0
def getNthNonagonalPentagonalNumber( n ):
    sqrt21 = sqrt( 21 )
    sign = power( -1, real_int( n ) )

    return nint( floor( fdiv( fprod( [ fadd( 25, fmul( 4, sqrt21 ) ),
                                       fsub( 5, fmul( sqrt21, sign ) ),
                                       power( fadd( fmul( 2, sqrt( 7 ) ), fmul( 3, sqrt( 3 ) ) ),
                                              fsub( fmul( 4, n ), 4 ) ) ] ),
                              336 ) ) )
Exemple #19
0
def getNthDecagonalNonagonalNumber( n ):
    dps = 8 * int( real_int( n ) )

    if mp.dps < dps:
        mp.dps = dps

    return nint( floor( fdiv( fmul( fadd( 15, fmul( 2, sqrt( 14 ) ) ),
                                    power( fadd( fmul( 2, sqrt( 2 ) ), sqrt( 7 ) ),
                                           fsub( fmul( 8, n ), 6 ) ) ), 448 ) ) )
    def __init__(self, width, depth, height, xpoz, ypoz, zpoz, wElements, dElements, hElements):
        self.smallBlocksStructure = []
        self.xpoz = mp.mpmathify(xpoz)
        self.ypoz = mp.mpmathify(ypoz)
        self.zpoz = mp.mpmathify(zpoz)

        self.width = mp.mpmathify(width)
        self.depth = mp.mpmathify(depth)
        self.height = mp.mpmathify(height)

        self.wElements = mp.mpmathify(mp.nint(wElements))
        self.dElements = mp.mpmathify(mp.nint(dElements))
        self.hElements = mp.mpmathify(mp.nint(hElements))

        self.widthSmall = mp.mpmathify(self.width / self.wElements)
        self.depthSmall = mp.mpmathify(self.depth / self.dElements)
        self.heightSmall = mp.mpmathify(self.height / self.hElements)
        self.nElements = mp.nint((self.width * self.depth * self.height) / (self.widthSmall * self.depthSmall * self.heightSmall))
Exemple #21
0
def getNthNonagonalOctagonalNumberOperator(n):
    sqrt6 = sqrt(6)
    sqrt7 = sqrt(7)

    return nint(
        floor(
            fdiv(
                fmul(fsub(fmul(11, sqrt7), fmul(9, sqrt6)),
                     power(fadd(sqrt6, sqrt7), fsub(fmul(8, n), 5))), 672)))
Exemple #22
0
def getNthNonagonalTriangularNumber( n ):
    a = fmul( 3, sqrt( 7 ) )
    b = fadd( 8, a )
    c = fsub( 8, a )

    return nint( fsum( [ fdiv( 5, 14 ),
                         fmul( fdiv( 9, 28 ), fadd( power( b, real_int( n ) ), power( c, n ) ) ),
                         fprod( [ fdiv( 3, 28 ),
                                  sqrt( 7 ),
                                  fsub( power( b, n ), power( c, n ) ) ] ) ] ) )
Exemple #23
0
def getNthDecagonalHeptagonalNumberOperator(n):
    sqrt10 = sqrt(10)

    return nint(
        floor(
            fdiv(
                fprod([
                    fsub(11, fmul(fmul(2, sqrt10), power(-1, n))),
                    fadd(1, sqrt10),
                    power(fadd(3, sqrt10), fsub(fmul(4, n), 3))
                ]), 320)))
Exemple #24
0
def getNthSquareTriangularNumber( n ):
    neededPrecision = int( real_int( n ) * 3.5 )  # determined by experimentation

    if mp.dps < neededPrecision:
        setAccuracy( neededPrecision )

    sqrt2 = sqrt( 2 )

    return nint( power( fdiv( fsub( power( fadd( 1, sqrt2 ), fmul( 2, n ) ),
                                           power( fsub( 1, sqrt2 ), fmul( 2, n ) ) ),
                                    fmul( 4, sqrt2 ) ), 2 ) )
Exemple #25
0
def drawbox():
    global a, listindex, centerx, centery, pixdict, z, red, green, blue, canv, verbose
    if verbose:
        print('Outputting: ' + mpmath.nstr(mpmath.chop(a[listindex])))
    if mpmath.isnan(a[listindex]) or mpmath.isinf(a[listindex]):
        return
    try:
        x = int(mpmath.nint(mpmath.re(a[listindex]))) + centerx
        y = int(mpmath.nint(mpmath.im(a[listindex]))) + centery
        if (x, y) in pixdict:
            canv.delete(pixdict[(x, y)])
            del pixdict[(x, y)]
        pixdict[(x, y)] = canv.create_rectangle(x * z - z + 1,
                                                y * z - z + 1,
                                                x * z + 1,
                                                y * z + 1,
                                                fill=rgb(red, green, blue),
                                                width=0)
    except OverflowError:
        #the number is so huge it's not going to be displayed anyway, so just suppress the error and move on
        pass
Exemple #26
0
def duplicateOperation( valueList ):
    if g.duplicateOperations > 0:
        raise ValueError( "'duplicate_operator' must be followed by another operation" )

    if isinstance( valueList[ -1 ], list ):
        raise ValueError( "'duplicate_operator' cannot accept a list argument" )

    argument = nint( floor( valueList.pop( ) ) )

    if argument < 1:
        raise ValueError( "'duplicate_operator' requires an argument of 1 or more (n.b., 1 has no effect)" )

    g.duplicateOperations = argument
Exemple #27
0
def getNthSquareTriangularNumberOperator(n):
    neededPrecision = int(n * 3.5)  # determined by experimentation

    if mp.dps < neededPrecision:
        mp.dps = neededPrecision

    sqrt2 = sqrt(2)

    return nint(
        power(
            fdiv(
                fsub(power(fadd(1, sqrt2), fmul(2, n)),
                     power(fsub(1, sqrt2), fmul(2, n))), fmul(4, sqrt2)), 2))
Exemple #28
0
def getNthDecagonalCenteredSquareNumber( n ):
    sqrt10 = sqrt( 10 )

    dps = 7 * int( real_int( n ) )

    if mp.dps < dps:
        mp.dps = dps

    return nint( floor( fsum( [ fdiv( 1, 8 ),
                              fmul( fdiv( 7, 16 ), power( fsub( 721, fmul( 228, sqrt10 ) ), fsub( n, 1 ) ) ),
                              fmul( fmul( fdiv( 1, 8 ), power( fsub( 721, fmul( 228, sqrt10 ) ), fsub( n, 1 ) ) ), sqrt10 ),
                              fmul( fmul( fdiv( 1, 8 ), power( fadd( 721, fmul( 228, sqrt10 ) ), fsub( n, 1 ) ) ), sqrt10 ),
                              fmul( fdiv( 7, 16 ), power( fadd( 721, fmul( 228, sqrt10 ) ), fsub( n, 1 ) ) ) ] ) ) )
Exemple #29
0
def getNthNonagonalPentagonalNumberOperator(n):
    sqrt21 = sqrt(21)
    sign = power(-1, n)

    return nint(
        floor(
            fdiv(
                fprod([
                    fadd(25, fmul(4, sqrt21)),
                    fsub(5, fmul(sqrt21, sign)),
                    power(fadd(fmul(2, sqrt(7)), fmul(3, sqrt(3))),
                          fsub(fmul(4, n), 4))
                ]), 336)))
Exemple #30
0
    def __distance(self, a, b, type):

        if a == b:
            return 0

        xd = a[0] - b[0]
        yd = a[1] - b[1]

        dij = None

        if type == "EUC_2D":
            """
				xd= x[i]-x[j];
				yd= y[i]-y[j];
				dij= nint( sqrt( xd*xd + yd*yd));
			"""
            dij = nint(math.sqrt(pow(xd, 2) + (pow(yd, 2))))
        else:
            if type == "ATT":
                """
					xd= x[i]-x[j];
					yd= y[i]-y[j];
					rij= sqrt( (xd*xd + yd*yd)/10.0 );
					tij= nint( rij );

					if(tij<rij)
						dij= tij+1;
					else
						dij= tij;
				"""
                rij = math.sqrt((pow(xd, 2) + (pow(yd, 2))) / 10.0)
                tij = nint(rij)

                if (tij < rij):
                    dij = tij + 1
                else:
                    dij = tij

        return dij
Exemple #31
0
def getNthDecagonalNonagonalNumberOperator(n):
    dps = 8 * int(n)

    if mp.dps < dps:
        mp.dps = dps

    return nint(
        floor(
            fdiv(
                fmul(
                    fadd(15, fmul(2, sqrt(14))),
                    power(fadd(fmul(2, sqrt(2)), sqrt(7)), fsub(fmul(8, n),
                                                                6))), 448)))
Exemple #32
0
def mpIntDigits(num):
    if not mpmath.almosteq(num,0):
        a = mpmath.log(abs(num), b=10)
        b = mpmath.nint(a)
        if mpmath.almosteq(a,b):
            return int(b)+1
        else:
            c = mpmath.ceil(a)
            try:
                return int(c)
            except:
                pass
    else:
        return 0
Exemple #33
0
def mpIntDigits(num):
    if not mpmath.almosteq(num, 0):
        a = mpmath.log(abs(num), b=10)
        b = mpmath.nint(a)
        if mpmath.almosteq(a, b):
            return int(b) + 1
        else:
            c = mpmath.ceil(a)
            try:
                return int(c)
            except:
                pass
    else:
        return 0
Exemple #34
0
def lst_to_nb(el, exact=False):
    #Devolve o logaritmo do numero com os expoentes na lista el
    if exact:
        res = 1
        for i in range(len(el)):
            res *= pow(nint(exp(primes[i])), el[i])
    else:
        #print(el)
        res = 0
        for i in range(len(el)):
            #print(primes[i], el[i], res)
            res += primes[i] * el[i]

    return res
Exemple #35
0
	def global_to_map(self, global_coordinates):
		"""
		Maps global coordinates to map coordinates. Mainly used to tell which 
		voxel the mouse pointer is on. Implementation based on article:
                http://www.alcove-games.com/advanced-tutorials/isometric-tile-picking/
		"""
		(gx, gy) = global_coordinates
		
                #depth info comes from the currently activated layer
                mz = self._active_layer
                
                #turn the global coordinates into a homogenous vector
                g_coord = mp.matrix([[gx], 
                                     [gy + mz * self._voxel_dimensions[DEPTH]], 
                                     [1]])
                
                #Apply the isometric unprojection matrix from common_util
                g_coord = UNPROJECT * g_coord
                
                #divide and round the coordinates to get integer indexes.
		mx = int(mp.nint(g_coord[X]) / self._side_length)
                my = int(mp.nint(g_coord[Y]) / self._side_length)
		
		return (mx, my, mz)
Exemple #36
0
def getNthPadovanNumber( arg ):
    n = fadd( real( arg ), 4 )

    a = root( fsub( fdiv( 27, 2 ), fdiv( fmul( 3, sqrt( 69 ) ), 2 ) ), 3 )
    b = root( fdiv( fadd( 9, sqrt( 69 ) ), 2 ), 3 )
    c = fadd( 1, fmul( mpc( 0, 1 ), sqrt( 3 ) ) )
    d = fsub( 1, fmul( mpc( 0, 1 ), sqrt( 3 ) ) )
    e = power( 3, fdiv( 2, 3 ) )

    r = fadd( fdiv( a, 3 ), fdiv( b, e ) )
    s = fsub( fmul( fdiv( d, -6 ), a ), fdiv( fmul( c, b ), fmul( 2, e ) ) )
    t = fsub( fmul( fdiv( c, -6 ), a ), fdiv( fmul( d, b ), fmul( 2, e ) ) )

    return nint( re( fsum( [ fdiv( power( r, n ), fadd( fmul( 2, r ), 3 ) ),
                             fdiv( power( s, n ), fadd( fmul( 2, s ), 3 ) ),
                             fdiv( power( t, n ), fadd( fmul( 2, t ), 3 ) ) ] ) ) )
Exemple #37
0
def getCompositions( n, k ):
    value = int( real_int( n ) )
    count = int( real_int( k ) )

    if count < 1:
        raise ValueError( "'compositions' expects a size argument greater than 0'" )

    if count == 1:
        return [ [ value ] ]
    else:
        result = [ ]

        for i in range( 1, int( ( value - count ) + 2 ) ):
            result.extend( [ [ nint( i ) ] + comp for comp in getCompositions( n - i, count - 1 ) ] )

        return result
Exemple #38
0
def getCompositionsGenerator(n, k):
    value = int(n)
    count = int(k)

    if count < 1:
        raise ValueError(
            "'compositions' expects a size argument greater than 0'")

    if count == 1:
        yield [value]
    else:
        #result = [ ]

        for i in range(1, int((value - count) + 2)):
            #result.extend( [ [ nint( i ) ] + comp for comp in getCompositions( n - i, count - 1 ) ] )
            for comp in getCompositionsGenerator(n - i, count - 1):
                yield [nint(i)] + comp
Exemple #39
0
def convertToNonintegerBase(num, base):
    epsilon = power(10, -(mp.dps - 3))
    minPlace = -(floor(mp.dps / log(base)))

    output = ''
    integer = ''

    remaining = num

    # find starting place
    place = int(floor(log(remaining, base)))

    while remaining > epsilon:
        if place < minPlace:
            break

        if place == -1:
            integer = output
            output = ''

        placeValue = power(base, place)

        value = fdiv(remaining, placeValue)

        value = fmul(value, power(10, mp.dps - 3))
        value = nint(value)
        value = fdiv(value, power(10, mp.dps - 3))

        value = floor(value)
        remaining = chop(fsub(remaining, fmul(placeValue, value)))

        output += str(value)[:-2]

        place -= 1

    if place >= 0:
        integer = output + '0' * (place + 1)
        output = ''

    if integer == '':
        return output, ''

    return integer, output
Exemple #40
0
	def __init__(self, resource_handler, voxel_handler,
	             world_dimensions = (64, 64, 16),
	             voxel_dimensions = (72, 36, 36),
	             active_layer = 0,
	             visibility_flag = ONLY_SHOW_EXPOSED):
		
		
		self._world_dimensions = world_dimensions
		self._voxel_dimensions = voxel_dimensions
		grid_length = world_dimensions[WIDTH] * world_dimensions[HEIGHT] * world_dimensions[DEPTH]
		
		self._active_layer = active_layer
		self.visibility_flag = visibility_flag
                
                #The unprojected length of the horizontal side of each voxel
                self._side_length = mp.nint(self._voxel_dimensions[WIDTH] * mp.sin(mp.pi / 4))
		
		WorldBase.__init__(self, resource_handler, voxel_handler,
		                   grid_length, (0, 0))
Exemple #41
0
def convertToNonintegerBase( num, base ):
    epsilon = power( 10, -( mp.dps - 3 ) )
    minPlace = -( floor( mp.dps / log( base ) ) )

    output = ''
    integer = ''

    remaining = num

    # find starting place
    place = int( floor( log( remaining, base ) ) )

    while remaining > epsilon:
        if place < minPlace:
            break

        if place == -1:
            integer = output
            output = ''

        placeValue = power( base, place )

        value = fdiv( remaining, placeValue )

        value = fmul( value, power( 10, mp.dps - 3 ) )
        value = nint( value )
        value = fdiv( value, power( 10, mp.dps - 3 ) )

        value = floor( value )
        remaining = chop( fsub( remaining, fmul( placeValue, value ) ) )

        output += str( value )[ : -2 ]

        place -= 1

    if place >= 0:
        integer = output + '0' * ( place + 1 )
        output = ''

    if integer == '':
        return output, ''
    else:
        return integer, output
Exemple #42
0
def getNthHeptagonalPentagonalNumberOperator(n):
    return nint(
        floor(
            fdiv(
                fmul(power(fadd(2, sqrt(15)), 2),
                     power(fadd(4, sqrt(15)), fsub(fmul(4, n), 3))), 240)))
 def _distance(num):
   return mp.fabs(mp.fsub(num, mp.nint(num)))
Exemple #44
0
def getNearestInt( n ):
    if isinstance( n, RPNMeasurement ):
        return RPNMeasurement( nint( n.value ), n.units )
    else:
        return nint( n )
 def _isInteger(num, tolerance=mp.power(10, -6)):
     return mp.almosteq(num, mp.nint(num), tolerance)
Exemple #46
0
def getNthHeptagonalHexagonalNumberOperator(n):
    return nint(
        floor(
            fdiv(
                fmul(fsub(sqrt(5), 1),
                     power(fadd(2, sqrt(5)), fsub(fmul(8, n), 5))), 80)))
Exemple #47
0
def getNthDecagonalPentagonalNumber( n ):
    return nint( floor( fmul( fdiv( 25, 192 ),
                              power( fadd( sqrt( 3 ), sqrt( 2 ) ),
                                     fsub( fmul( 8, real_int( n ) ), 6 ) ) ) ) )
Exemple #48
0
def getNthDecagonalOctagonalNumber( n ):
    return nint( floor( fdiv( fmul( fadd( 13, fmul( 4, sqrt( 3 ) ) ),
                                    power( fadd( 2, sqrt( 3 ) ),
                                           fsub( fmul( 8, real_int( n ) ), 6 ) ) ), 192 ) ) )
Exemple #49
0
def getNthHexagonalPentagonalNumberOperator(n):
    return nint(
        ceil(
            fdiv(
                fmul(fsub(sqrt(3), 1),
                     power(fadd(2, sqrt(3)), fsub(fmul(4, n), 2))), 12)))
Exemple #50
0
def duplicateDigits( n, k ):
    if real( k ) < 0:
        raise ValueError( "'add_digits' requires a non-negative integer for the second argument" )

    return appendDigits( real( n ), fmod( n, power( 10, nint( floor( k ) ) ) ), k )
 def _distance(num):
     return mp.fabs(mp.fsub(num, mp.nint(num)))
Exemple #52
0
def getNthOctagonalSquareNumberOperator(n):
    return nint(floor(fdiv(power(fadd(2, sqrt(3)), fsub(fmul(4, n), 2)), 12)))
Exemple #53
0
def mpmathRoundToInt(z):
    return int(mpmath.nint(z.real))
Exemple #54
0
def getNthOctagonalPentagonalNumberOperator(n):
    return nint(
        floor(
            fdiv(
                fmul(fsub(11, fprod([6, sqrt(2), power(-1, n)])),
                     power(fadd(1, sqrt(2)), fsub(fmul(8, n), 6))), 96)))
Exemple #55
0
def getNthDecagonalHexagonalNumberOperator(n):
    return nint(
        floor(
            fdiv(
                fmul(fsub(fmul(5, sqrt(2)), 1),
                     power(fadd(sqrt(2), 1), fsub(fmul(8, n), 5))), 64)))
Exemple #56
0
def getNthDecagonalTriangularNumber( n ):
    return nint( floor( fdiv( fmul( fadd( 9, fprod( [ 4, sqrt( 2 ),
                                                      power( -1, fadd( real_int( n ), 1 ) ) ] ) ),
                              power( fadd( 1, sqrt( 2 ) ), fsub( fmul( 4, fadd( n, 1 ) ), 6 ) ) ), 64 ) ) )
Exemple #57
0
def getNthDecagonalHexagonalNumber( n ):
    return nint( floor( fdiv( fmul( fsub( fmul( 5, sqrt( 2 ) ), 1 ),
                                    power( fadd( sqrt( 2 ), 1 ),
                                           fsub( fmul( 8, real_int( n ) ), 5 ) ) ), 64 ) ) )
Exemple #58
0
def getNthDecagonalPentagonalNumberOperator(n):
    return nint(
        floor(
            fmul(fdiv(25, 192),
                 power(fadd(sqrt(3), sqrt(2)), fsub(fmul(8, n), 6)))))
Exemple #59
0
def getNthNonagonalHeptagonalNumber( n ):
    sqrt35 = sqrt( 35 )

    return nint( floor( fdiv( fmul( fadd( 39, fmul( 4, sqrt35 ) ),
                              power( fadd( 6, sqrt35 ), fsub( fmul( 4, real_int( n ) ), 3 ) ) ),
                              560 ) ) )
Exemple #60
0
def appendDigits( n, digits, digitCount ):
    if real( n ) < 0:
        return nint( fsub( fmul( floor( n ), power( 10, digitCount ) ), digits ) )
    else:
        return nint( fadd( fmul( floor( n ), power( 10, digitCount ) ), digits ) )