예제 #1
0
    def reflect(self, gradient):
        """Return a reflected ball for a given gradient upon which the ball is incident. Only valid for balls
           whose endpoint (self.end) has been set, in the form [x, y]. 'gradient' should be set to None for an
           infinite gradient (that is, a vertical line).
           
           Assumes ball is moving."""

        if self.end is None:
            raise Exception(
                "Ball endpoint has not been set. Set with Ball.end.")

        if gradient is None:
            incident = arccos(self.vel[1] /
                              sqrt(self.vel[0]**2 + self.vel[1]**2))
            self.rebound = incident if incident < pi / 2 else pi - incident
            return Ball(self.end, [-self.vel[0], self.vel[1]])

        if gradient == 0:
            incident = arccos(self.vel[0] /
                              sqrt(self.vel[0]**2 + self.vel[1]**2))
            self.rebound = incident if incident < pi / 2 else pi - incident
            return Ball(self.end, [self.vel[0], -self.vel[1]])

        # cos(theta) = a.b / |a||b|
        # Vector of boundary = [1, gradient]
        dot = self.vel[0] + self.vel[1] * gradient
        magnitudes = sqrt(
            (self.vel[0]**2 + self.vel[1]**2) * (1 + gradient**2))

        incident = arccos(dot / magnitudes)
        self.rebound = incident if incident < pi / 2 else pi - incident
        # Rotate by -2*theta if coming from below, else 2*theta.

        if self.vel[0] > 0:
            if gradient < self.eqn[0]:  # Ball is coming from below.
                rotation = -2 * incident
            else:  # Ball is coming from above.
                rotation = 2 * incident

        elif self.vel[0] < 0:
            if gradient < self.eqn[0]:  # Ball is coming from above.
                rotation = 2 * incident
            else:  # Ball is coming from below.
                rotation = -2 * incident

        else:  # vx == 0, ball moves vertically.
            if self.vel[1] > 0:  # Ball is coming from below.
                rotation = -2 * incident
            else:  # Ball is coming from above.
                rotation = 2 * incident

        # Rotation matrix * velocity = new velocity.
        newVel = [
            self.vel[0] * cos(rotation) - self.vel[1] * sin(rotation),
            self.vel[0] * sin(rotation) + self.vel[1] * cos(rotation)
        ]

        return Ball(self.end, newVel)
예제 #2
0
    def ec2eq(self):
        """Convert ecliptic coordinates to equatorial coordinates"""

        import math
        #from numpy.matlib import sin, cos, arcsin, arctan2
        from math import sin, cos
        from math import asin as arcsin
        from math import atan2 as arctan2
        from math import acos as arccos

        eb = self.eb
        el = self.el
        ob = math.radians(23.439281)

        dec = arcsin(sin(eb) * cos(ob) + cos(eb) * sin(ob) * sin(el))
        sra = (sin(dec) * cos(ob) - sin(eb)) / (cos(dec) * sin(ob))

        cra = cos(el) * cos(eb) / cos(dec)
        if sra < 1 and sra > -1:
            sa = arcsin(sra)
        else:
            sa = 0
        ca = arccos(cra)
        tsa = sa
        tca = ca
        if tsa < 0:
            ca = 2.0 * math.pi - ca
        if tca >= math.pi / 2.0:
            sa = math.pi - sa
        if ca >= math.pi * 2.0:
            ca = ca - math.pi * 2.0
        self.tsa = sra
        self.tca = cra
        self.ra = ca
        self.dec = dec
예제 #3
0
	def initCartesian(self, x, y, z):
		self.x = x
		self.y = y
		self.z = z
		self.r = mt.sqrt(self.x**2 + self.y**2 + self.z**2)
		self.theta = mt.arccos(self.z/self.r)
		self.fi = mt.arctan(self.y/self.x)
예제 #4
0
def distSLC(vecA, vecB):  #球面余弦定理
    a = math.sin(vecA[0, 1] * math.pi / 180) * math.sin(
        vecB[0, 1] * math.pi / 180)  #pi/180转换为弧度 ,pi  ,numpy
    b = math.cos(vecA[0, 1] * math.pi / 180) * math.cos(
        vecB[0, 1] * math.pi / 180) * math.cos(math.pi *
                                               (vecB[0, 0] - vecA[0, 0]) / 180)
    return math.arccos(a + b) * 6371.0
예제 #5
0
def phi(p):
    """Calculate and returns the angle phi for a given particle's fourmomentum, of some
       iterable type and length 4, in the form [E, px, py, pz]."""

    angle = arccos(p[2] / sqrt(p[1]**2 + p[2]**2 + p[3]**2))
    # Projected into the xy plane.
    return angle if p[1] > 0 else 2 * pi - angle
예제 #6
0
파일: MOPcoord.py 프로젝트: OSSOS/MOP
    def ec2eq(self):
        """Convert ecliptic coordinates to equatorial coordinates"""

        import math
        #from numpy.matlib import sin, cos, arcsin, arctan2
        from math import sin, cos
        from math import asin as arcsin
        from math import atan2 as arctan2
        from math import acos as arccos
        
        eb=self.eb
        el=self.el
        ob=math.radians(23.439281)
        
        dec = arcsin(sin(eb)*cos(ob)+cos(eb)*sin(ob)*sin(el))
        sra = (sin(dec)*cos(ob)-sin(eb))/(cos(dec)*sin(ob))

        cra = cos(el)*cos(eb)/cos(dec)
        if sra < 1 and sra > -1 :
            sa= arcsin(sra)
        else:
            sa = 0
        ca= arccos(cra)
        tsa=sa
        tca=ca
        if tsa<0 :
            ca=2.0*math.pi-ca
        if tca>=math.pi/2.0:
            sa=math.pi-sa
        if ca >= math.pi*2.0:
            ca=ca-math.pi*2.0
        self.tsa=sra
        self.tca=cra
        self.ra=ca
        self.dec=dec
def arccos():
	os.system('cls')
	global pi
	global e
	global cont
	print("This calculator operates in radian mode!")
	time.sleep(1)
	while cont not in ["n","N"]:
		while True:
			try:
				os.system('cls')
				print("Please enter the cosine you wish to compute the angle of.")
				time.sleep(1)
				ang_1 = float(input("Enter cos>>"))
				total = math.arccos(ang_1)
				print(total)
				time.sleep(1)
				break
			except:
				print("Error: Invalid Input")
				time.sleep(1)
				os.system('cls')
		while True:
			cont = input("Do you wish to continue:Y or N?>>")
			if cont in ["y","Y"]:
				break
			elif cont in ["n", "N"]:
				break
			else:
				print("Error: Invalid Input")
				time.sleep(1)
				os.system('cls')
		os.system('cls')
def coordenadasCartesianas(x,y,z):
    """ cambia de coordenadas cartesianas a esfericas """
    from math import arcsin, arccos, sin
    r=sqrt(x**2 + y**2 + z**2)
    t=arccos(z/r)
    f=(y/(r*sin(t)))
    
    print r,t,f
    return r,t,f
예제 #9
0
def coordenadasCartesianas(x, y, z):
    """ cambia de coordenadas cartesianas a esfericas """
    from math import arcsin, arccos, sin
    r = sqrt(x**2 + y**2 + z**2)
    t = arccos(z / r)
    f = (y / (r * sin(t)))

    print r, t, f
    return r, t, f
예제 #10
0
def getSunriseAndSunset(lat, lon, dst, year, month, day):
    localtime = 13.00
    b2 = lat
    b3 = lon
    b4 = dst
    b5 = localtime / 24
    d30 = getDayNumber(year, month, day)
    e30 = b5
    f30 = d30 + 2415018.5 + e30 - b4 / 24
    g30 = (f30 - 2451545) / 36525
    q30 = 23 + (26 + ((21.448 - g30 * (46.815 + g30 *
                                       (0.00059 - g30 * 0.001813)))) / 60) / 60
    r30 = q30 + 0.00256 * cos(radians(125.04 - 1934.136 * g30))
    j30 = 357.52911 + g30 * (35999.05029 - 0.0001537 * g30)
    k30 = 0.016708634 - g30 * (0.000042037 + 0.0000001267 * g30)
    l30 = sin(radians(j30)) * (
        1.914602 - g30 *
        (0.004817 + 0.000014 * g30)) + sin(radians(2 * j30)) * (
            0.019993 - 0.000101 * g30) + sin(radians(3 * j30)) * 0.000289
    i30 = mod(280.46646 + g30 * (36000.76983 + g30 * 0.0003032), 360)
    m30 = i30 + l30
    p30 = m30 - 0.00569 - 0.00478 * sin(radians(125.04 - 1934.136 * g30))
    t30 = degrees(arcsin(sin(radians(r30)) * sin(radians(p30))))
    u30 = tg(radians(r30 / 2)) * tg(radians(r30 / 2))
    v30 = 4 * degrees(u30 * sin(2 * radians(i30)) -
                      2 * k30 * sin(radians(j30)) + 4 * k30 * u30 *
                      sin(radians(j30)) * cos(2 * radians(i30)) -
                      0.5 * u30 * u30 * sin(4 * radians(i30)) -
                      1.25 * k30 * k30 * sin(2 * radians(j30)))
    w30 = degrees(
        arccos(
            cos(radians(90.833)) / (cos(radians(b2)) * cos(radians(t30))) -
            tg(radians(b2)) * tg(radians(t30))))
    x30 = (720 - 4 * b3 - v30 + b4 * 60) / 1440
    y30 = (x30 * 1440 - w30 * 4) / 1440
    w30 = degrees(
        arccos(
            cos(radians(90.833)) / (cos(radians(b2)) * cos(radians(t30))) -
            tg(radians(b2)) * tg(radians(t30))))
    x30 = (720 - 4 * b3 - v30 + b4 * 60) / 1440
    z30 = (x30 * 1440 + w30 * 4) / 1440
    sunrise = y30 * 24
    sunset = z30 * 24
    return (sunrise, sunset)
예제 #11
0
def targetRight(enemy_x, enemy_y, me_x, me_y):
    x = sympy.Symbol('x')
    y = sympy.Symbol('y')

    a = enemy_x
    b = enemy_y
    c = me_x
    d = me_y
    r = turnRadius

    [p,q] = sympy.nsolve([ math.sqrt((x - a) ** 2 + (y - b)) / speed_bullet - ( r * math.arccos(1 - (x - c) ** 2 - (y - d) ** 2) / (2 * r ** 2)) / speed_enemy, (x - a) ** 2 + (y - b) ** 2 - r ** 2 , [x,y], [1,1]])
    return getHeading(p,q)
예제 #12
0
파일: Fix.py 프로젝트: qzw0014/wbd
 def getAzimuthAdjustment(self, geoPosLatitude, assumedLatitude,
                          correctedAltitude, intermediateDistance):
     geoPosLatAngle = Angle()
     assLatFloat = self.latitudeConverter(assumedLatitude)
     geoPosLatAngle.setDegreesAndMinutes(geoPosLatitude)
     mem = (sin(radians(geoPosLatAngle.getDegrees())) -
            sin(radians(assLatFloat)) * intermediateDistance)
     deno = (cos(radians(assLatFloat)) * cos(radians(correctedAltitude)))
     tem = (mem / deno)
     azimuthAdjustment = arccos(tem)
     azimuthAdjustment = degrees(azimuthAdjustment)
     return azimuthAdjustment
def equatorialCoordPrecession(start_epoch, final_epoch, ra, dec):
    """ Corrects Right Ascension and Declination from one epoch to another, taking only precession into 
        account.

        Implemented from: Jean Meeus - Astronomical Algorithms, 2nd edition, pages 134-135
    
    Arguments:
        start_epoch: [float] Julian date of the starting epoch
        final_epoch: [float] Julian date of the final epoch
        ra: [float] non-corrected right ascension in degrees
        dec: [float] non-corrected declination in degrees
    
    Return:
        (ra, dec): [tuple of floats] precessed equatorial coordinates in degrees

    """

    ra = math.radians(ra)
    dec = math.radians(dec)

    T = (start_epoch - J2000_JD.days)/36525.0
    t = (final_epoch - start_epoch)/36525.0

    # Calculate correction parameters
    zeta  = ((2306.2181 + 1.39656*T - 0.000139*T**2)*t + (0.30188 - 0.000344*T)*t**2 + 0.017998*t**3)/3600
    z     = ((2306.2181 + 1.39656*T - 0.000139*T**2)*t + (1.09468 + 0.000066*T)*t**2 + 0.018203*t**3)/3600
    theta = ((2004.3109 - 0.85330*T - 0.000217*T**2)*t - (0.42665 + 0.000217*T)*t**2 - 0.041833*t**3)/3600

    # Convert parameters to radians
    zeta, z, theta = map(math.radians, (zeta, z, theta))

    # Calculate the next set of parameters
    A = math.cos(dec)  *math.sin(ra + zeta)
    B = math.cos(theta)*math.cos(dec)*math.cos(ra + zeta) - math.sin(theta)*math.sin(dec)
    C = math.sin(theta)*math.cos(dec)*math.cos(ra + zeta) + math.cos(theta)*math.sin(dec)

    # Calculate right ascension
    ra_corr = math.atan2(A, B) + z

    # Calculate declination (apply a different equation if close to the pole, closer then 0.5 degrees)
    if (math.pi/2 - abs(dec)) < math.radians(0.5):
        dec_corr = math.arccos(math.sqrt(A**2 + B**2))
    else:
        dec_corr = math.asin(C)

    # Wrap right ascension to [0, 2*pi] range
    ra_corr = ra_corr%(2*math.pi)

    # Wrap declination to [-pi/2, pi/2] range
    dec_corr = (dec_corr + math.pi/2)%math.pi - math.pi/2

    return math.degrees(ra_corr), math.degrees(dec_corr)
예제 #14
0
def angle(u, v, unit='r'):
    """Returns angle between vectors u and v."""
    if all([elem == 0 for elem in u]) or all([elem == 0 for elem in v]):
        raise ValueError("Cannot pass a zero-vector")
    if len(u) != len(v):
        raise ValueError("u and v must be of the same length")
    cos = np.dot(u,v) / norm(u) / norm(v)
    rad = math.arccos(np.clip(cos, -1, 1))
    if unit == 'r':
        return rad
    elif unit == 'd':
        return math.degrees(rad)
    else:
        raise ValueError("{0} is not a valid keyword".format(output))
예제 #15
0
 def to_angle_axis(self):
     """
     Returns the quaternion's rotation represented by an Euler angle and axis.
     If the quaternion is the identity quaternion (1, 0, 0, 0), a rotation along the x axis with angle 0 is returned.
     :return: rad, x, y, z
     """
     if self[0] == 1 and self[1] == 0 and self[2] == 0 and self[3] == 0:
         return 0, 1, 0, 0
     rad = math.arccos(self[0]) * 2
     imaginary_factor = math.sin(rad / 2)
     if abs(imaginary_factor) < 1e-8:
         return 0, 1, 0, 0
     x = self._q[1] / imaginary_factor
     y = self._q[2] / imaginary_factor
     z = self._q[3] / imaginary_factor
     return rad, x, y, z
예제 #16
0
def getSunrise_Sunset(lat, lon):
    year = datetime.datetime.now().year
    month = datetime.datetime.now().month
    day = datetime.datetime.now().day

    dst = time.localtime().tm_isdst

    if dst == 0:
       offset = -time.timezone/60
    else:
       offset = -time.altzone/60

    localtime = 12.00
    b2 = float(lat)
    b3 = float(lon)
    b4 = dst
    b5 = localtime / 24
    b6 = year
    d30 = getDayNumber(year, month, day)
    e30 = b5
    f30 = d30 + 2415018.5 + e30 - b4 / 24
    g30 = (f30 - 2451545) / 36525
    q30 = 23 + (26 + ((21.448 - g30 * (46.815 + g30 * (0.00059 - g30 * 0.001813)))) / 60) / 60
    r30 = q30 + 0.00256 * cos(radians(125.04 - 1934.136 * g30))
    j30 = 357.52911 + g30 * (35999.05029 - 0.0001537 * g30)
    k30 = 0.016708634 - g30 * (0.000042037 + 0.0000001267 * g30)
    l30 = sin(radians(j30)) * (1.914602 - g30 * (0.004817 + 0.000014 * g30)) + sin(radians(2 * j30)) * (0.019993 - 0.000101 * g30) + sin(radians(3 * j30)) * 0.000289
    i30 = mod(280.46646 + g30 * (36000.76983 + g30 * 0.0003032), 360)
    m30 = i30 + l30
    p30 = m30 - 0.00569 - 0.00478 * sin(radians(125.04 - 1934.136 * g30))
    t30 = degrees(arcsin(sin(radians(r30)) * sin(radians(p30))))
    u30 = tg(radians(r30 / 2)) * tg(radians(r30 / 2))
    v30 = 4 * degrees(u30 * sin(2 * radians(i30)) - 2 * k30 * sin(radians(j30)) + 4 * k30 * u30 * sin(radians(j30)) * cos(2 * radians(i30)) - 0.5 * u30 * u30 * sin(4 * radians(i30)) - 1.25 * k30 * k30 * sin(2 * radians(j30)))
    w30 = degrees(arccos(cos(radians(90.833)) / (cos(radians(b2)) * cos(radians(t30))) - tg(radians(b2)) * tg(radians(t30))))
    x30 = (720 - 4 * b3 - v30 +  offset) / 1440
    x30 = (720 - 4 * b3 - v30 +  offset) / 1440
    y30 = (x30 * 1440 - w30 * 4) / 1440
    z30 = (x30 * 1440 + w30 * 4) / 1440
    sunrise = y30 * 24
    sunset = z30 * 24
    status = 0

    tDate = "{0:04d}-{1:02d}-{2:02d} " . format(year, month, day)
    sr = tDate + getHHMMSS(sunrise)
    ss = tDate + getHHMMSS(sunset)

    return {'sunrise': sr, 'sunset': ss, 'status': status}
예제 #17
0
파일: MOPcoord.py 프로젝트: OSSOS/MOP
    def eq2ec(self):
        
        #from numpy.matlib import sin, cos, arcsin, arctan2
        from math import sin, cos
        from math import asin as arcsin
        from math import atan2 as arctan2
        from math import acos as arccos
	import math

        ra=self.ra
        dec=self.dec
        ob=math.radians(23.439281000000000000)

	eb=arcsin(sin(dec)*cos(ob)-cos(dec)*sin(ra)*sin(ob))
        sl=(sin(dec)-sin(eb)*cos(ob))/(cos(eb)*sin(ob))
        cl=cos(ra)*cos(dec)/cos(eb)
        if sl < -1: sl=float(-1)
        if sl > 1: sl=float(1)
        els=arcsin(sl)
        elc=arccos(cl)
        ela=0
        elb=0
        if sl < 0 and cl < 0:
            ela=math.pi*1 - els
            elb=2.0*math.pi-elc
            rule=0
        if sl < 0 and cl > 0:
            ela=2.0*math.pi+els
            elb=2.0*math.pi-elc
            rule=1
        if sl > 0 and cl > 0:
            ela=els
            elb=elc
            rule=2
        if sl > 0 and cl < 0:
            ela=math.pi-els
            elb=elc
            rule=3




        self.sl=els
        self.cl=elc
        self.eb=eb
        self.el=ela
예제 #18
0
    def eq2ec(self):

        #from numpy.matlib import sin, cos, arcsin, arctan2
        from math import sin, cos
        from math import asin as arcsin
        from math import atan2 as arctan2
        from math import acos as arccos
        import math

        ra = self.ra
        dec = self.dec
        ob = math.radians(23.439281000000000000)

        eb = arcsin(sin(dec) * cos(ob) - cos(dec) * sin(ra) * sin(ob))
        sl = (sin(dec) - sin(eb) * cos(ob)) / (cos(eb) * sin(ob))
        cl = cos(ra) * cos(dec) / cos(eb)
        if sl < -1: sl = float(-1)
        if sl > 1: sl = float(1)
        els = arcsin(sl)
        elc = arccos(cl)
        ela = 0
        elb = 0
        if sl < 0 and cl < 0:
            ela = math.pi * 1 - els
            elb = 2.0 * math.pi - elc
            rule = 0
        if sl < 0 and cl > 0:
            ela = 2.0 * math.pi + els
            elb = 2.0 * math.pi - elc
            rule = 1
        if sl > 0 and cl > 0:
            ela = els
            elb = elc
            rule = 2
        if sl > 0 and cl < 0:
            ela = math.pi - els
            elb = elc
            rule = 3

        self.sl = els
        self.cl = elc
        self.eb = eb
        self.el = ela
예제 #19
0
 def arccos(self):
     return self._gennode('arccos(' + self._name + ')',
                          (lambda x: math.arccos(self.value())), [self],
                          self._trace)
예제 #20
0
def loadWAVECAR(*wavecar):

    # INPUT
    kpoint = 80
    band = 30
    # read file
    try:
        wavecar = wavecar[0]
    except:
        # no input
        print("Warning! Either there was no input into loadWAVECAR(), or \
        the input was not a valid WAVECAR dictionary")
        wavecar = {key: None for key in _keyListWavecar()}
        return wavecar

    # CASE 1 : string (filePath) input
    if isinstance(wavecar, str):
        with open(wavecar, mode='rb') as file:

            # --- 0 --- prepare content
            print("Extracting WAVECAR content...", end="")
            wavecarContent = file.read()
            from struct import unpack
            print("...content read.")

            # --- 1 --- read 1st header
            OUTPUT = unpack("ddd", wavecarContent[:24])
            print(
                "\033[0;1;38;5;236mtmp = \033[0;38;5;239m{0} \033[2m({1})\033[0m"
                .format(OUTPUT, type(OUTPUT[0])))
            recordLength = int(OUTPUT[0])
            spinIndex = int(OUTPUT[1])
            precision = int(OUTPUT[2])
            print(
                "\033[0;38;5;089mrecordLength = {0}\nspinIndex = {1}\nprecision = {2}"
                .format(recordLength, spinIndex, precision))

            # -- 1.5 -- identify next non-zero
            idx = 24
            OUTPUT = 0.0
            while OUTPUT == 0.0:
                OUTPUT = float(
                    unpack("d", wavecarContent[8 * idx:8 * idx + 8])[0])
                idx += 1
            nextStep = idx - 1
            print("\033[0m--> NEXT STEP: {0}".format(nextStep))

            # --- 2 --- read 2nd header
            OUTPUT = unpack("dddddddddddd",
                            wavecarContent[nextStep * 8:nextStep * 8 + 8 * 12])
            print(
                "\033[0;1;38;5;236mtmp = \033[0;38;5;239m{0} \033[2m({1})\033[0m"
                .format(OUTPUT, type(OUTPUT[0])))
            kLength = int(OUTPUT[0])
            bandLength = int(OUTPUT[1])
            energyCutoff = int(OUTPUT[2])
            a1 = list(OUTPUT[3:6])
            a2 = list(OUTPUT[6:9])
            a3 = list(OUTPUT[9:12])
            print(
                "\033[0;38;5;089mk = {0}\nb = {1}\nENCUT = {2}\n\033[0;38;5;134ma1 = {3}\na2 = {4}\na3 = {5}"
                .format(kLength, bandLength, energyCutoff, a1, a2, a3))

            # --- 3 --- acquire reciprocal lattice
            (b1, b2, b3) = vecReciprocals(a1, a2, a3)
            print("\033[0;38;5;105mb1 = {0}\nb2 = {1}\nb3 = {2}\033[0m".format(
                b1, b2, b3))

            # --- 4 --- repeat wavetrans setup process
            from math import acos as arccos
            from math import asin as arcsin
            from math import sin
            from math import pi
            kMAX = (0.26246583099999998 * energyCutoff)**0.5
            deg = 180 / pi
            deg = 1
            # [A] plane-wave counting
            phi_12 = arccos(vecDot(b1, b2) / vecNorm(b1) / vecNorm(b2))
            sinphi_123 = vecDot(vecCross(b1, b2), b3) / vecNorm(b3) / vecNorm(
                vecCross(b1, b2))
            nb1maxA = int(1 + kMAX / vecNorm(b1) / abs(sin(phi_12)))
            nb2maxA = int(1 + kMAX / vecNorm(b2) / abs(sin(phi_12)))
            nb3maxA = int(1 + kMAX / vecNorm(b3) / abs(sinphi_123))
            npmaxA = int(4 * pi / 3 * nb1maxA * nb2maxA * nb3maxA + 0.5)
            print('\033[38;5;106mphi_12 = {0}\nsinphi_123 = {1}\nnpmaxA = {2}'.
                  format(phi_12 * deg, sinphi_123, npmaxA))
            # [B] plane-wave counting
            phi_13 = arccos(vecDot(b1, b3) / vecNorm(b1) / vecNorm(b3))
            sinphi_123 = vecDot(vecCross(b1, b3), b2) / vecNorm(b2) / vecNorm(
                vecCross(b1, b3))
            nb1maxB = int(1 + kMAX / vecNorm(b1) / abs(sin(phi_13)))
            nb2maxB = int(1 + kMAX / vecNorm(b2) / abs(sinphi_123))
            nb3maxB = int(1 + kMAX / vecNorm(b3) / abs(sin(phi_13)))
            npmaxB = int(4 * pi / 3 * nb1maxB * nb2maxB * nb3maxB + 0.5)
            print('\033[38;5;107mphi_13 = {0}\nsinphi_123 = {1}\nnpmaxB = {2}'.
                  format(phi_13 * deg, sinphi_123, npmaxB))
            # [C] plane-wave counting
            phi_23 = arccos(vecDot(b2, b3) / vecNorm(b2) / vecNorm(b3))
            sinphi_123 = vecDot(vecCross(b2, b3), b1) / vecNorm(b1) / vecNorm(
                vecCross(b2, b3))
            nb1maxC = int(1 + kMAX / vecNorm(b1) / abs(sinphi_123))
            nb2maxC = int(1 + kMAX / vecNorm(b2) / abs(sin(phi_23)))
            nb3maxC = int(1 + kMAX / vecNorm(b3) / abs(sin(phi_23)))
            npmaxC = int(4 * pi / 3 * nb1maxC * nb2maxC * nb3maxC + 0.5)
            print('\033[38;5;108mphi_23 = {0}\nsinphi_123 = {1}\nnpmaxC = {2}'.
                  format(phi_23 * deg, sinphi_123, npmaxC))
            # final G index limits
            nb1max = max([nb1maxA, nb1maxB, nb1maxC])
            nb2max = max([nb2maxA, nb2maxB, nb2maxC])
            nb3max = max([nb3maxA, nb3maxB, nb3maxC])
            print('\033[0;38;5;109mnb1max = {0}\nnb2max = {1}\nnb3max = {2}'.
                  format(nb1max, nb2max, nb3max))
            # 2x to handle two component spinors
            npmax = 2 * min([npmaxA, npmaxB, npmaxC])
            irec = 3 + (kpoint - 1) * (bandLength + 1)
            print('\033[0;38;5;110mnpmax = {0}\nirec = {1}\033[0m'.format(
                npmax, irec))

            # --- 5 --- allocate memory
            igall = [[0.0 for j in range(3)] for i in range(npmax)]
            coeff = [0.0 for i in range(npmax)]

            # -- 5.5 -- identify first k-index
            # Done by tracking the 1st occupancy elements, and back-tracing
            idx = nextStep + 12
            OUTPUT = 0.0
            while OUTPUT == 0.0:
                OUTPUT = float(
                    unpack("d", wavecarContent[8 * idx:8 * idx + 8])[0])
                idx += 1
            nextStep = idx - 1
            print("\033[0m--> NEXT STEP: {0}\n".format(nextStep))

            kIdx1 = 2
            kSpan = 65
            '''
            # -- 5.x -- testing stuff
            OUTPUT = [0.0,0.0,0.0]
            idx = nextStep
            q = 0
            Q = 0
            readingLimit = 0
            (vMIN,vMEAN,vMAX) = (1.0E5,0.0,-1.0E5)
            # BIG LOOP
            while readingLimit<1000000000:
                readingLimit+=1
                # pull data
                try: OUTPUT = list(unpack("ddddd",wavecarContent[idx*8:idx*8+5*8]))
                except: return
                print("idx-{0} ... ".format())
                OUTPUT = [float(OUTPUT[j]) for j in range(5)]
                # CASE 1: ending a value streak
                if OUTPUT[0]==0.0 and Q>0:
                    print("\033[38;5;226mvalues \033[2mx{0}".format(Q))
                    print("--> min  = {0}\n--> mean = {1}\n--> max  = {2}\033[0m".format(vMIN,vMEAN,vMAX))
                    (vMIN,vMEAN,vMAX) = (1.0E5,0.0,-1.0E5)
                    q=1; Q=0
                    idx += 1
                # CASE 2: continuing a zero streak
                elif OUTPUT[0]==0.0:
                    q+=1
                    idx += 1
                # CASE 3: k-point found
                elif isKpointListing(OUTPUT[:3]):
                    print("\033[38;5;160mkpoint = {0} \033[2mat {1}\033[0m".format(OUTPUT[:3],idx))
                    q=0; Q=0
                    idx += 3
                # CASE 4: some other header
                elif Q==0 and q>0 and any([ output==0.0 for output in OUTPUT ]) and any([ output!=0.0 for output in OUTPUT ]):
                    temp = OUTPUT[ : [ j for j in range(5) if OUTPUT[j]==0.0][0] ]
                    q=0; Q=0
                    temp2 = list(unpack("dddddddddd",wavecarContent[idx*8:idx*8+10*8]))[len(temp):]
                    temp2 = [ float(tempVal) for tempVal in temp2 ]
                    if any([ output!=0.0 for output in temp2 ]):
                        while len(temp)<5 and OUTPUT[len(temp)]==0.0:
                            temp.append(0.0)
                            q+=1
                    print("\033[38;5;226m{0}\033[0m".format(temp))
                    idx += len(temp)
                # CASE 5: ending zero streak
                elif OUTPUT[0]!=0.0 and q>0:
                    print("\033[0;38;5;248m0.0 \033[2mx{0}\033[0m".format(q))
                    Q=1; q=0
                    idx += 1
                # CASE 6: continuing a value streak
                elif OUTPUT[0]!=0.0:
                    Q+=1
                    if OUTPUT[0]<vMIN: vMIN = OUTPUT[0]
                    if OUTPUT[0]>vMAX: vMAX = OUTPUT[0]
                    vMEAN  =  ((Q-1)/Q) * vMEAN  +  (1/Q)*OUTPUT[0]
                    idx += 1
                # CASE 7: error...
                else:
                    print("ERROR: case not handled...")
                    print("q={0}  Q={1}  OUTPUT={2}".format(q,Q,OUTPUT))
                    return
            return
            '''

            return

            # --- 6 --- pull coefficients
            tmp = unpack("dddd", wavecarContent[8 * irec:8 * irec + 4 * 8])
            nplane = int(tmp[0])
            wk = tmp[1:]
            print("nplane = {0}\nwk = {1}".format(nplane, wk))

            return True

            print(
                "\033[0;1;38;5;236mtmp = \033[0;38;5;239m{0}  \033[2m({1})\033[0m"
                .format(tmp, type(tmp[0])))

            ncnt = 0
            sumkg = [0.0, 0.0, 0.0]
            for g3 in range(2 * nb3max):
                g3p = g3
                if g3 > nb3max: g3p = g3 - 2 * nb3max - 1
                for g2 in range(2 * nb2max):
                    g2p = g2
                    if g2 > nb2max: g2p = g2 - 2 * nb2max - 1
                    for g1 in range(2 * nb1max):
                        g1p = g1
                        if g1 > nb1max: g1p = g1 - 2 * nb1max - 1
                        for j in range(3):
                            sumkg[j] = (wk[0] + g1p) * b1[j] + (
                                wk[1] + g2p) * b2[j] + (wk[2] + g3p) * b3[j]
                            gtot = vecDot(sumkg, sumkg)**0.5
                            etot = gtot**2 / 0.2624658310
                            if etot < energyCutoff:
                                ncnt += 1
                                igall[1][ncnt] = g1p
                                igall[2][ncnt] = g2p
                                igall[3][ncnt] = g3p

    # dumb return (for now)
    wavecar = {key: None for key in _keyListWavecar()}
    return wavecar
def main():
    x1, y1 = read_coordinates()
    x2, y2 = read_coordinates()
    distance = 6371 * arccos(
        sin(x1) * sin(x2) + cos(x1) * cos(x2) * cos(y1 - y2))
    print("Distance between both coordinates:", str(round(distance)) + "Km")
예제 #22
0
 def angle_manifold(self, nabla_fint1, nabla_fint2):
     nab1, nab2 = self.nabla_fint1(), self.nabla_fint2()
     return math.arccos(abs(dot(nab1, nab2)) /
                        (norm(nab1) * norm(nab2))) * 180 / math.pi
예제 #23
0
def arccos_val(r):
    if r >= -1 and r <= 1:
        p = m.arccos(r)
        return p
    else:
        print('error')
예제 #24
0
def angle(p1: Point, p2: Point, p3: Point):
    p12 = dist(p1, p2)
    p13 = dist(p1, p3)
    p23 = dist(p2, p3)
    return math.arccos((p12 ** 2 + p13 ** 2 - p23 ** 2)/(2 * p12 * p13))