Python math.asin() Examples

The following are 30 code examples of math.asin(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module math , or try the search function .
Example #1
Source File: analyse_raw_telemetry.py    From SpaceXtract with MIT License 7 votes vote down vote up
def find_angle_graph(velocity, vertical_velocity, interp=False):
    angle = []

    for i in range(len(velocity)):
        if velocity[i] == 0:
            angle.append(angle[-1])
        else:
            ratio = max(-1, min(vertical_velocity[i] / velocity[i], 1))
            angle.append(asin(ratio))

    angle = savgol_filter(angle, 5, 1)

    if interp:
        angle = savgol_filter(angle, 11, 1)
        return ss.medfilt(angle, kernel_size=7)

    return angle 
Example #2
Source File: util.py    From apartment-finder with MIT License 6 votes vote down vote up
def coord_distance(lat1, lon1, lat2, lon2):
    """
    Finds the distance between two pairs of latitude and longitude.
    :param lat1: Point 1 latitude.
    :param lon1: Point 1 longitude.
    :param lat2: Point two latitude.
    :param lon2: Point two longitude.
    :return: Kilometer distance.
    """
    lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2])
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
    c = 2 * math.asin(math.sqrt(a))
    km = 6367 * c
    return km 
Example #3
Source File: geomath.py    From AboveTustin with MIT License 6 votes vote down vote up
def distance(pointA, pointB):
	"""
	Calculate the great circle distance between two points 
	on the earth (specified in decimal degrees)

	http://stackoverflow.com/questions/15736995/how-can-i-quickly-estimate-the-distance-between-two-latitude-longitude-points
	"""
	# convert decimal degrees to radians 
	lon1, lat1, lon2, lat2 = map(math.radians, [pointA[1], pointA[0], pointB[1], pointB[0]])

	# haversine formula 
	dlon = lon2 - lon1 
	dlat = lat2 - lat1 
	a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
	c = 2 * math.asin(math.sqrt(a)) 
	r = 3956  # Radius of earth in miles. Use 6371 for kilometers
	return c * r 
Example #4
Source File: geometry.py    From Localization with MIT License 6 votes vote down vote up
def gcd(self, lon1, lat1, lon2, lat2):
        """
        Calculate the great circle distance between two points
        on the earth (specified in decimal degrees)
        """
        # convert decimal degrees to radians
        lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2])

        # haversine formula
        dlon = lon2 - lon1
        dlat = lat2 - lat1
        a = math.sin(dlat / 2) ** 2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2) ** 2
        c = 2 * math.asin(math.sqrt(a))

        dis = E.R * c
        return dis 
Example #5
Source File: euclid.py    From honeybee with GNU General Public License v3.0 6 votes vote down vote up
def get_euler(self):
        t = self.x * self.y + self.z * self.w
        if t > 0.4999:
            heading = 2 * math.atan2(self.x, self.w)
            attitude = math.pi / 2
            bank = 0
        elif t < -0.4999:
            heading = -2 * math.atan2(self.x, self.w)
            attitude = -math.pi / 2
            bank = 0
        else:
            sqx = self.x ** 2
            sqy = self.y ** 2
            sqz = self.z ** 2
            heading = math.atan2(2 * self.y * self.w - 2 * self.x * self.z,
                                 1 - 2 * sqy - 2 * sqz)
            attitude = math.asin(2 * t)
            bank = math.atan2(2 * self.x * self.w - 2 * self.y * self.z,
                              1 - 2 * sqx - 2 * sqz)
        return heading, attitude, bank 
Example #6
Source File: euclid.py    From renpy-shader with MIT License 6 votes vote down vote up
def get_euler(self):
        t = self.x * self.y + self.z * self.w
        if t > 0.4999:
            heading = 2 * math.atan2(self.x, self.w)
            attitude = math.pi / 2
            bank = 0
        elif t < -0.4999:
            heading = -2 * math.atan2(self.x, self.w)
            attitude = -math.pi / 2
            bank = 0
        else:
            sqx = self.x ** 2
            sqy = self.y ** 2
            sqz = self.z ** 2
            heading = math.atan2(2 * self.y * self.w - 2 * self.x * self.z,
                                 1 - 2 * sqy - 2 * sqz)
            attitude = math.asin(2 * t)
            bank = math.atan2(2 * self.x * self.w - 2 * self.y * self.z,
                              1 - 2 * sqx - 2 * sqz)
        return heading, attitude, bank 
Example #7
Source File: macros.py    From pyth with MIT License 6 votes vote down vote up
def trig(a, b=' '):
    if is_num(a) and isinstance(b, int):

        funcs = [math.sin, math.cos, math.tan,
                 math.asin, math.acos, math.atan,
                 math.degrees, math.radians,
                 math.sinh, math.cosh, math.tanh,
                 math.asinh, math.acosh, math.atanh]

        return funcs[b](a)

    if is_lst(a):
        width = max(len(row) for row in a)
        padded_matrix = [list(row) + (width - len(row)) * [b] for row in a]
        transpose = list(zip(*padded_matrix))
        if all(isinstance(row, str) for row in a) and isinstance(b, str):
            normalizer = ''.join
        else:
            normalizer = list
        norm_trans = [normalizer(padded_row) for padded_row in transpose]
        return norm_trans
    return unknown_types(trig, ".t", a, b) 
Example #8
Source File: locations.py    From orbit-predictor with MIT License 6 votes vote down vote up
def elevation_for(self, position):
        """Returns elevation to given position in radians

        calculation is made inline to have better performance
        """
        observer_pos_ecef = self.position_ecef
        object_coords_ecef = position

        rx = object_coords_ecef[0] - observer_pos_ecef[0]
        ry = object_coords_ecef[1] - observer_pos_ecef[1]
        rz = object_coords_ecef[2] - observer_pos_ecef[2]

        a, b, c = self._cached_elevation_calculation_data

        top_z = (a * rx) + (b * ry) + (c * rz)

        range_sat = sqrt((rx * rx) + (ry * ry) + (rz * rz))

        return asin(top_z / range_sat) 
Example #9
Source File: apls_utils.py    From apls with Apache License 2.0 6 votes vote down vote up
def _haversine(lon1, lat1, lon2, lat2):
    """
    Calculate the great circle distance between two points in m
    on the earth (specified in decimal degrees)
    http://stackoverflow.com/questions/15736995/how-can-i-
        quickly-estimate-the-distance-between-two-latitude-longitude-points
    """
    # convert decimal degrees to radians
    lon1, lat1, lon2, lat2 = list(map(radians, [lon1, lat1, lon2, lat2]))
    # haversine formula
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
    c = 2 * asin(sqrt(a))
    km = 6367 * c
    m = 1000. * km
    return m

############################################################################### 
Example #10
Source File: testAccumulatorsArithmetic.py    From Finance-Python with MIT License 6 votes vote down vote up
def testAsinFunction(self):
        ma5 = MovingAverage(5, 'close')
        holder = Asin(ma5)

        sampleClose = np.sin(self.sampleClose)

        for i, close in enumerate(sampleClose):
            data = {'close': close}
            ma5.push(data)
            holder.push(data)

            expected = math.asin(ma5.result())
            calculated = holder.result()
            self.assertAlmostEqual(calculated, expected, 12, "at index {0:d}\n"
                                                             "expected:   {1:f}\n"
                                                             "calculated: {2:f}".format(i, expected, calculated)) 
Example #11
Source File: dff_importer.py    From DragonFF with GNU General Public License v3.0 6 votes vote down vote up
def align_roll( vec, vecz, tarz ):

        sine_roll = vec.normalized().dot(vecz.normalized().cross(tarz.normalized()))

        if 1 < abs(sine_roll):
            sine_roll /= abs(sine_roll)
            
        if 0 < vecz.dot( tarz ):
            return math.asin( sine_roll )
        
        elif 0 < sine_roll:
            return -math.asin( sine_roll ) + math.pi
        
        else:
            return -math.asin( sine_roll ) - math.pi

    ####################################################### 
Example #12
Source File: SideBySideFisheyeProjection.py    From vrProjector with Apache License 2.0 6 votes vote down vote up
def angular_position(texcoord):
    up = texcoord[0]
    v = texcoord[1]
    # correct for hemisphere
    if up>=0.5:
      u = 2.0*(up-0.5)
    else:
      u = 2.0*up

    # ignore points outside of circles
    if ((u-0.5)*(u-0.5) + (v-0.5)*(v-0.5))>0.25:
      return None, None

    # v: 0..1-> vp: -1..1
    phi = math.asin(2.0*(v-0.5))

    # u = math.cos(phi)*math.cos(theta)
    # u: 0..1 -> upp: -1..1
    u = 1.0-u
    theta = math.acos( 2.0*(u-0.5) / math.cos(phi) )

    if up<0.5:
       theta = theta-math.pi

    return (theta,phi) 
Example #13
Source File: euler.py    From differentiable-point-clouds with MIT License 6 votes vote down vote up
def ypr_from_campos(cx, cy, cz):
    camDist = math.sqrt(cx * cx + cy * cy + cz * cz)
    cx = cx / camDist
    cy = cy / camDist
    cz = cz / camDist
    t = math.sqrt(cx * cx + cy * cy)
    tx = cx / t
    ty = cy / t
    yaw = math.acos(tx)
    if ty > 0:
        yaw = 2 * math.pi - yaw

    roll = 0
    pitch = math.asin(cz)

    return yaw, pitch, roll 
Example #14
Source File: hypath.py    From pysplit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def find_destination(self, lat0, lon0, bearing, distance):
        """
        Find the destination given bearing, latitude, and longitude.

        Parameters
        ----------
        lat0 : float
            Latitude of starting point in degrees
        lon0 : float
            Longitude of starting point in degrees
        bearing : float
            Direction from starting point in radians (``self.circular_mean``
            is in degrees)
        distance : float
            Distance from starting point to destination in meters

        Returns
        -------
        latx : float
            Latitude of destination in degrees
        lonx : float
            Longitude of destination in degrees

        """
        d2r = distance / 6371000

        latr = math.radians(lat0)
        lonr = math.radians(lon0)

        latx = math.asin(math.sin(latr) * math.cos(d2r) +
                         math.cos(latr) * math.sin(d2r) *
                         math.cos(bearing))

        lonx = math.degrees(lonr + math.atan2(math.sin(bearing) *
                                              math.sin(d2r) * math.cos(latr),
                                              math.cos(d2r) - math.sin(latr) *
                                              math.sin(latx)))
        latx = math.degrees(latx)

        return latx, lonx 
Example #15
Source File: utils.py    From osmnet with GNU Affero General Public License v3.0 5 votes vote down vote up
def great_circle_dist(lat1, lon1, lat2, lon2):
    """
    Get the distance (in meters) between two lat/lon points
    via the Haversine formula.

    Parameters
    ----------
    lat1, lon1, lat2, lon2 : float
        Latitude and longitude in degrees.

    Returns
    -------
    d : float
        Distance in meters.

    """
    radius = 6372795  # meters

    lat1 = math.radians(lat1)
    lon1 = math.radians(lon1)
    lat2 = math.radians(lat2)
    lon2 = math.radians(lon2)

    dlat = lat2 - lat1
    dlon = lon2 - lon1

    # formula from:
    # http://en.wikipedia.org/wiki/Haversine_formula#The_haversine_formula
    a = math.pow(math.sin(dlat / 2), 2)
    b = math.cos(lat1) * math.cos(lat2) * math.pow(math.sin(dlon / 2), 2)
    d = 2 * radius * math.asin(math.sqrt(a + b))

    return d 
Example #16
Source File: robot.py    From pycozmo with MIT License 5 votes vote down vote up
def angle(self) -> util.Angle:
        """ The angle of the lift arm relative to the ground. """
        sin_angle = (self._height.mm - LIFT_PIVOT_HEIGHT.mm) / LIFT_ARM_LENGTH.mm
        angle = math.asin(sin_angle)
        return util.Angle(radians=angle) 
Example #17
Source File: notification.py    From verejne.digital with Apache License 2.0 5 votes vote down vote up
def DistancePoints(lon1, lat1, lon2, lat2):
    from math import radians, cos, sin, asin, sqrt
    # convert decimal degrees to radians 
    lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
    # haversine formula 
    dlon = lon2 - lon1 
    dlat = lat2 - lat1 
    a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
    c = 2 * asin(sqrt(a)) 
    km = 6367 * c
    return km 
Example #18
Source File: test_math.py    From oss-ftp with MIT License 5 votes vote down vote up
def testAsin(self):
        self.assertRaises(TypeError, math.asin)
        self.ftest('asin(-1)', math.asin(-1), -math.pi/2)
        self.ftest('asin(0)', math.asin(0), 0)
        self.ftest('asin(1)', math.asin(1), math.pi/2)
        self.assertRaises(ValueError, math.asin, INF)
        self.assertRaises(ValueError, math.asin, NINF)
        self.assertTrue(math.isnan(math.asin(NAN))) 
Example #19
Source File: test_math.py    From BinderFilter with MIT License 5 votes vote down vote up
def testAsin(self):
        self.assertRaises(TypeError, math.asin)
        self.ftest('asin(-1)', math.asin(-1), -math.pi/2)
        self.ftest('asin(0)', math.asin(0), 0)
        self.ftest('asin(1)', math.asin(1), math.pi/2)
        self.assertRaises(ValueError, math.asin, INF)
        self.assertRaises(ValueError, math.asin, NINF)
        self.assertTrue(math.isnan(math.asin(NAN))) 
Example #20
Source File: CubemapProjection.py    From vrProjector with Apache License 2.0 5 votes vote down vote up
def get_theta_phi(self, _x, _y, _z):
    dv = math.sqrt(_x*_x + _y*_y + _z*_z)
    x = _x/dv
    y = _y/dv
    z = _z/dv
    theta = math.atan2(y, x)
    phi = math.asin(z)
    return theta, phi 
Example #21
Source File: adsb-polar-2.py    From dump1090-tools with ISC License 5 votes vote down vote up
def latlngup_to_relxyz(c,l):
    # this converts WGS84 (lat,lng,alt) to a rotated ECEF frame
    # where the earth center is still at the origin
    # but (clat,clng,calt) has been rotated to lie on the positive X axis

    clat,clng,calt = c
    llat,llng,lalt = l

    # rotate by -clng around Z to put C on the X/Z plane
    # (this is easy to do while still in WGS84 coordinates)
    llng = llng - clng

    # find angle between XY plane and C
    cx,cy,cz = latlngup_to_ecef((clat,0,calt))
    a = math.atan2(cz,cx)

    # convert L to (rotated around Z) ECEF
    lx,ly,lz = latlngup_to_ecef((llat,llng,lalt))

    # rotate by -a around Y to put C on the X axis
    asin = math.sin(-a)
    acos = math.cos(-a)
    rx = lx * acos - lz * asin
    rz = lx * asin + lz * acos

    return (rx, ly, rz)

# great circle distance from C to L, assuming spherical geometry (~0.3% error)
# from http://www.movable-type.co.uk/scripts/latlong.html ("haversine formula") 
Example #22
Source File: adsb-polar-2.py    From dump1090-tools with ISC License 5 votes vote down vote up
def range_bearing_elevation_from(c):
    # build a function that calculates ranges, bearing, elevation from C
    clat,clng,calt = c

    # rotate by -clng to put C on the XZ plane
    # find angle between XY plane and C
    cx,cy,cz = latlngup_to_ecef((clat,0,calt))
    a = math.atan2(cz,cx)
    
    # rotate by -a around Y to put C on the X axis
    asin = math.sin(-a)
    acos = math.cos(-a)

    crx = cx * acos - cz * asin
    cry = cy                         # should be zero
    crz = cx * asin + cz * acos      # should be zero

    def rbe(l):
        # rotate L into our new reference frame
        llat,llng,lalt = l
        # rotate by -clng, convert to ECEF
        lx,ly,lz = latlngup_to_ecef((llat,llng - clng,lalt))

        # rotate by -a around Y
        lrx = lx * acos - lz * asin
        lry = ly
        lrz = lx * asin + lz * acos

        # Now we have cartesian coordinates with C on
        # the +X axis, ground plane YZ, north along +Z.

        dx, dy, dz = lrx-crx, lry-cry, lrz-crz
        slant = math.sqrt(dx*dx + dy*dy + dz*dz)             # true line-of-sight range
        bearing = (360 + 90 - rtod(math.atan2(dz,dy))) % 360 # bearing around X axis
        elev = rtod(math.asin(dx / slant))                   # elevation from horizon (YZ plane)
        horiz_range = math.sqrt(dy*dy + dz*dz)               # distance projected onto YZ (ground/horizon plane); something like ground distance if the Earth was flat
        return (slant, horiz_range, bearing, elev, (lrx,lry,lrz))

    return rbe

# calculate true range, bearing, elevation from C to L 
Example #23
Source File: zxbparser.py    From zxbasic with GNU General Public License v3.0 5 votes vote down vote up
def p_expr_trig(p):
    """ bexpr : math_fn bexpr %prec UMINUS
    """
    p[0] = make_builtin(p.lineno(1), p[1],
                        make_typecast(TYPE.float_, p[2], p.lineno(1)),
                        {'SIN': math.sin,
                         'COS': math.cos,
                         'TAN': math.tan,
                         'ASN': math.asin,
                         'ACS': math.acos,
                         'ATN': math.atan,
                         'LN': lambda y: math.log(y, math.exp(1)),  # LN(x)
                         'EXP': math.exp,
                         'SQR': math.sqrt
                         }[p[1]]) 
Example #24
Source File: adsb-polar-2.py    From dump1090-tools with ISC License 5 votes vote down vote up
def range_bearing_elevation(c,l):
    # rotate C onto X axis
    crx, cry, crz = latlngup_to_relxyz(c,c)
    # rotate L in the same way
    lrx, lry, lrz = latlngup_to_relxyz(c,l)

    # Now we have cartesian coordinates with C on
    # the +X axis, ground plane YZ, north along +Z.

    dx, dy, dz = lrx-crx, lry-cry, lrz-crz
    slant = math.sqrt(dx*dx + dy*dy + dz*dz)             # true line-of-sight range
    bearing = (360 + 90 - rtod(math.atan2(dz,dy))) % 360 # bearing around X axis
    elev = rtod(math.asin(dx / slant))                   # elevation from horizon (YZ plane)
    horiz_range = math.sqrt(dy*dy + dz*dz)               # distance projected onto YZ (ground/horizon plane); something like ground distance if the Earth was flat
    return (slant, horiz_range, bearing, elev, (lrx,lry,lrz)) 
Example #25
Source File: math.py    From SkittBot with GNU General Public License v3.0 5 votes vote down vote up
def arcsin(bot: Bot, update: Update, args):
    message = update.effective_message
    message.reply_text(math.asin(int(args[0]))) 
Example #26
Source File: utils.py    From quadcopter-simulation with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def RotToRPY(R):
    phi = asin(R[1,2])
    theta = atan2(-R[0,2]/cos(phi),R[2,2]/cos(phi))
    psi = atan2(-R[1,0]/cos(phi),R[1,1]/cos(phi))
    return phi, theta, psi 
Example #27
Source File: coordinate_systems.py    From orbit-predictor with MIT License 5 votes vote down vote up
def horizon_to_az_elev(top_s, top_e, top_z):
    range_sat = sqrt((top_s * top_s) + (top_e * top_e) + (top_z * top_z))
    elevation = asin(top_z / range_sat)
    azimuth = atan2(-top_e, top_s) + pi
    return azimuth, elevation 
Example #28
Source File: coordinate_systems.py    From orbit-predictor with MIT License 5 votes vote down vote up
def eci_to_radec(eci_coords):
    xequat, yequat, zequat = eci_coords

    # convert equatorial rectangular coordinates to RA and Decl:
    r = _euclidean_distance(xequat, yequat, zequat)
    RA = atan2(yequat, xequat)
    DEC = asin(zequat/r)

    return RA, DEC, r 
Example #29
Source File: suncalc.py    From suncalcPy with MIT License 5 votes vote down vote up
def declination(l, b):    
	return asin(sin(b) * cos(e) + cos(b) * sin(e) * sin(l)) 
Example #30
Source File: mirrorball.py    From pivy with ISC License 5 votes vote down vote up
def generateMirrorBall(radius, tileheight, tilewidth):
    root = SoSeparator()
    
    tilethickness = ((tilewidth + tileheight)/2.0)/50.0 # looks nice
    tile = generateTile(tileheight, tilewidth, tilethickness)
        
    radiustrans = SoTranslation()
    radiustrans.translation = SbVec3f(radius,0,0)

    mirrormat = SoMaterial()
    mirrormat.specularColor = (1, 1, 1)
    mirrormat.diffuseColor = (0.2, 0.2, 0.2)    
    mirrormat.shinyness = 0.5
    root.addChild(mirrormat)

    rot1 = SbRotation()
    rot2 = SbRotation() 

    x = M_PI
    anglesteplong = M_PI / (2.0 * math.asin(tileheight / (2.0 * radius)))
    anglesteplat = M_PI / (2.0 * math.asin(tilewidth / (2.0 * radius)))

    while x > 0:
        y = M_PI*2
        while y > 0:
            sep = SoSeparator()
            rot1.setValue(SbVec3f(0,0,1), x)
            rot2.setValue(SbVec3f(1, 0, 0), y)
            y = y - (M_PI*2 / ((anglesteplong*2)*math.sin(x)))            
            rot = SoRotation()
            rot.rotation = (rot1*rot2)
            sep.addChild(rot)
            sep.addChild(radiustrans)
            sep.addChild(tile)
            root.addChild(sep)
        x = x - (M_PI / anglesteplat)

    return root
    
##############################################################