Exemplo n.º 1
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
def arcsin():
	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 sine you wish to compute the angle of.")
				time.sleep(1)
				ang_1 = float(input("Enter sine>>"))
				total = math.arcsin(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')
Exemplo n.º 3
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
Exemplo n.º 4
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}
Exemplo n.º 5
0
def getSunriseAndSunset(lat, lon, dst, year, month, day):
    localtime = 12.00
    b2 = lat
    b3 = 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 + b4 * 60) / 1440
    x30 = (720 - 4 * b3 - v30 + b4 * 60) / 1440
    y30 = (x30 * 1440 - w30 * 4) / 1440
    z30 = (x30 * 1440 + w30 * 4) / 1440
    sunrise = y30 * 24
    sunset = z30 * 24
    return (sunrise, sunset)
Exemplo n.º 6
0
def MatrixToEuler(matrix):
    """
    Converts a 3X3 matrix into a vector having Euler angles as components
    """
    if matrix.shape == (3, 3):
        try:
            theta = math.asin(- matrix[2][0])
            if math.cos(theta) != 0:
                try:
                    psi = math.atan2(matrix[2][1] / math.cos(theta), matrix[2][2] / math.cos(theta))
                except:
                    psi = math.atan(matrix[2][1])
                try:
                    phi = math.atan2(matrix[1][0] / math.cos(theta), matrix[0][0] / math.cos(theta))
                except:
                    phi = math.atan(matrix[1][0])
            else:
                phi = theta
                psi = math.arcsin(matrix[1][1])
            return [phi, theta, psi]
        except:
            raise AlgebraicError, 'the matrix is not orthogonal'
Exemplo n.º 7
0
def checkio(h, w):
    # equatorial radius = a
    a = w / 2.0

    # polar radius = c
    c = h / 2.0

    volume = (4.0 / 3.0) * pi * a**2 * c

    if (c > a):
        # prolate spheroid: polar radius > equatorial radius
        # http://mathworld.wolfram.com/ProlateSpheroid.html

        # ellipticity = e
        e = sqrt(1.0 - (a**2) / (c**2))

        area = 2.0 * pi * a**2 + 2.0 * pi * a * c / e * arcsin(e)

    elif (c < a):
        # oblate spheroid: polar radius < equatorial radius
        # http://mathworld.wolfram.com/OblateSpheroid.html

        # ellipticity = e
        e = sqrt(1.0 - (c**2) / (a**2))

        area = (2.0 * pi * a**2) + (pi * c**2 / e) * ln((1 + e) / (1 - e))

    else:
        # sphere: 4 pi r^2
        area = 4.0 * pi * a**2

    result = list(map(lambda x: round(x, 2), [volume, area]))

    print(result)

    return result
Exemplo n.º 8
0
def photon_extraction(n1,n2,theta1,theta2,n_sc):
    #snell-descarteslaw n1*math.sin(theta1)=n2*math.sin(theta2)
    theta1=(n2/n1)*math.sin(theta2)
    #critical angle of extraction
    thetac=math.arcsin(1/n_sc)*n_sc # should be approx 25degrees for LED
    n_extraction=(1-math.sin(thetac))/(2) #should be approx 5% for LED
Exemplo n.º 9
0
def do(d):
	x1=math.sqrt((d[0]-d[2])**2 + (d[1]-d[3])**2)
	x2=math.sqrt((d[2]-d[4])**2 + (d[3]-d[5])**2)
	t1=d[-2]
	t2=d[-1]
	ang1=math.arcsin(math.sin(t2)/math.sin(t1)*x1/x2)
Exemplo n.º 10
0
def get_error(img,
              up_step,
              black_step_max,
              dist_diff_max,
              black_depth_min,
              black_depth_max,
              zebra_edge=0):
    global dist_before, length

    # 越来越快地搜索黑线
    def search_black(increment=1):
        deviation = 0
        step = 1
        while 1:
            if img[depth][int(length / 2 - deviation)] < 5:
                return length / 2 - deviation
            if img[depth][int(length / 2 + deviation)] < 5:
                return length / 2 + deviation
            if deviation >= length / 2 - step:
                #print("\n\nNo Line in depth", depth, '\n')
                return -1
            deviation += step
            if step < black_step_max: step += increment

    # 在斑马线区域搜索要巡的线
    def search_black_zebra_edge(increment=1):
        deviation = zebra_edge
        step = 1
        left, right = 0, 0
        while deviation > step and not left * right:
            if img[depth][int(length / 2 - deviation)] < 5:
                left = length / 2 - deviation
            if img[depth][int(length / 2 + deviation)] < 5:
                right = length / 2 + deviation
            deviation -= step
            if step < black_step_max: step += increment
        left = int(length / 2 - zebra_edge) if not left else left
        right = int(length / 2 + zebra_edge) if not right else right
        return (left + right) / 2

    # 从下往上搜索黑线,作为控制器输入
    keep = False
    line_deviation = -1
    depth = black_depth_max
    while line_deviation == -1:
        if not zebra_edge: line_deviation = search_black()
        else: line_deviation = search_black_zebra_edge()
        dist = line_deviation - length / 2  # 车身偏左为正
        depth -= up_step
        if depth <= black_depth_min:
            keep = True
            break
    #print('[ BlackDepth', depth + up_step, ']')

    # 根据dist微分算alpha
    if abs(dist - dist_before) <= dist_diff_max:
        alpha = arcsin((dist - dist_before) / dist_diff_max)  # 车头偏右为正
    else:
        #print('\nDist Changes too Fast\n')
        alpha = 0
    #print('[ Dist', int(dist), '] [ Alpha', cut(alpha), ']', end=' ')

    dist_before = dist
    return alpha, dist, depth + up_step, keep
Exemplo n.º 11
0
def arcsin_val(r):
    if r >= -1 and r <= 1:
        p = m.arcsin(r)
        return p
    else:
        print('error')
def quaternions2rpy(w, x, y, z):
    roll = math.atan2(2*(w*x+y*z), 1-2*(x**2+y**2))
    pitch = math.arcsin(2*(w*y-z*x))
    yaw = math.atan2(2*(w*z+x*y), 1-2*(y**2+z**2))
    return roll, pitch, yaw
Exemplo n.º 13
0
def get_z(t, f0_t):
    z = numpy.empty(len(t))
    for i in range(len(t)):
        zi = t[i] - math.arcsin(f0_t[i])
        numpy.append(z, zi)
    return z
Exemplo n.º 14
0
 def arcsin(self):
     return self._gennode('sin(' + self._name + ')',
                          (lambda x: math.arcsin(self.value())), [self],
                          self._trace)