Exemple #1
0
def make_mass_matrix(robot):
    """

    :param robot:
    :return: mass matrix
    """

    I, m, l, r = robot.unpack()
    theta_1 = robot.q[0]
    theta_2 = robot.q[1]
    theta_3 = robot.q[2]

    M_11 = I[1][1] * s(theta_2) ** 2 + I[2][1] * s(theta_2 + theta_3) ** 2 + \
           I[0][2] + I[1][2] * c(theta_2) ** 2 + \
           I[1][2] * c(theta_2 + theta_3) ** 2
    M_12 = 0

    M_13 = 0
    M_21 = 0
    M_22 = I[1][0] + I[2][0] + m[2] * l[0] ** 2 + \
           m[1] * r[0] ** 2 + m[1] ** 2 + \
           2 * m[2] * l[0] * r[1] * c(theta_3)

    M_23 = I[2][0] + m[2] * r[1] ** 2 + \
           m[2] * l[0] * r[1] * c(theta_3)

    M_31 = 0
    M_32 = I[2][0] + m[2] * r[1] ** 2 + \
           m[2] * l[1] * r[1] * c(theta_3)
    M_33 = I[2][0] + m[2] * r[1]**2

    M = np.matrix([[M_11, M_12, M_13], [M_21, M_22, M_23], [M_31, M_32, M_33]])
    return M
Exemple #2
0
def get_jacobian_matricies(robot):
    """

    :param robot:
    :return:
    """

    I, m, l, r = robot.unpack()
    theta_1 = robot.q[0]
    theta_2 = robot.q[1]
    theta_3 = robot.q[2]

    J_1 = np.zeros(shape=(6, 3))
    J_1[5, 0] = 1

    J_2 = np.matrix([[-r[0] * c(theta_2), 0, 0], [0, 0, 0], [0, -r[0], 0],
                     [0, -1, 0], [-s(theta_2), 0, 0], [c(theta_2), 0, 0]])

    J_3 = np.matrix([[l[1] * c(theta_2) - r[1] * c(theta_2 + theta_3), 0, 0],
                     [0, l[0] * s(theta_1), 0],
                     [0, -l[1] - l[0] * c(theta_3), -r[1]], [0, -1, -1],
                     [-s(theta_2 + theta_3), 0, 0],
                     [c(theta_2 + theta_3), 0, 0]])

    return (J_1, J_2, J_3)
Exemple #3
0
def b(x):
    if x > s(3) / 4:
        return b(s(3) / 2 - x)
    n = 0
    n += pi - acos(x) - acos(s(3) / 2 - x)
    n *= 2
    if x < 1 - s(3) / 2:
        n += 2 * acos(s(3) / 2 + x)
    return n / 2 / pi
def r_pintor_i(r_p, v_p, planet, t, t_prev):
    # From PCPF (planet centered/planet fixed) to PCI (planet centered inertial)
    rot_angle = -np.linalg.norm(planet.omega) * (t + t_prev)  # rad
    L_pi = [[c(rot_angle), s(rot_angle), 0], [-s(rot_angle),
                                              c(rot_angle), 0], [0, 0, 1]]

    r_i = np.inner((L_pi), r_p)
    v_i = np.inner((L_pi), (v_p + np.cross(planet.omega, r_p)))
    return r_I, v_I
Exemple #5
0
def data_job_retention(nSelected,nRunOver):
    """Calculate the retention for a data job"""
    from uncertainties import ufloat as u
    from math import sqrt as s
    nsel  = u((nSelected,s(nSelected)))
    nrun  = u((nRunOver,s(nRunOver)))
    out   = nsel/nrun
    print "(", 100*out, ") %"
    return out
Exemple #6
0
def mc_job_selection_efficiency(DecProdEff,DecProdEffErr,nSelected,nRunOver):
    """Calculate the selection efficiency for a MC job"""
    from uncertainties import ufloat as u
    from math import sqrt as s
    e_dpc = u((DecProdEff,DecProdEffErr))
    nsel  = u((nSelected,s(nSelected)))
    nrun  = u((nRunOver,s(nRunOver)))
    out   = e_dpc*nsel/nrun
    print "(", 100*out, ") %"
    return out
def alfadeltartor(R_RA_DEC):
    # From Geocentric Celestial Reference Frame (GCRF) to  PCI (Planet Centered Inertial)
    R = R_RA_DEC[0]
    RA = R_RA_DEC[1]
    DEC = R_RA_DEC[2]

    x = R * c(DEC) * c(RA)
    y = R * c(DEC) * s(RA)
    z = R * s(DEC)
    return [x, y, z]
Exemple #8
0
def selesaikan(a, b, c):
    a = float(a)
    b = float(b)
    c = float(c)

    D = (b**2) - (4 * a * c)
    if D > 0:
        x1 = (-b + s(D)) / (2 * a)
        x2 = (-b - s(D)) / (2 * a)
        hasil = (x1, x2)
        print(hasil)
    else:
        print("Determinan negatif. Persamaan tidak mempunyai akar real")
def r_intor_p(r_i, v_i, planet, t, t_prev):
    # From PCI (planet centered inertial) to PCPF (planet centered/planet fixed)
    rot_angle = np.linalg.norm(planet.omega) * (t + t_prev)  # rad
    # print(t,rot_angle)
    L_pi = [[c(rot_angle), s(rot_angle), 0], [-s(rot_angle),
                                              c(rot_angle), 0], [0, 0, 1]]

    r_p = np.inner(L_pi, r_i)

    #V_pf_pci = v_i - np.cross(planet.omega, r_i);  #planet relative velocity in PCI frame
    v_p = np.inner(L_pi, (v_i - np.cross(planet.omega, r_i)))

    return r_p, v_p
def latlongtoNED(H_LAN_LON):
    lon = H_LAN_LON[2]
    lat = H_LAN_LON[1]
    # Compute first in xyz coordinates(z: north pole, x - z plane: contains r, y: completes right - handed set)
    uDxyz = [-c(lat), 0, -s(lat)]
    uNxyz = [-s(lat), 0, c(lat)]
    uExyz = [0, 1, 0]

    # Rotate by longitude to change to PCPF frame
    L3 = [[c(lon), -s(lon), 0], [s(lon), c(lon), 0], [0, 0, 1]]
    uN = np.inner(L3, uNxyz)
    uE = np.inner(L3, uExyz)
    uD = np.inner(L3, uDxyz)

    return [uD, uN, uE]
def poseFromOdom(X0, Y0, THETA0, v, v_var, om, om_var):
    X = []
    Y = []
    THETA = []
    X.append(X0)
    Y.append(Y0)
    THETA.append(THETA0)

    dt = 0.1
    for i in range(1, len(v)):
        nv = np.random.normal(0, v_var)
        nom = np.random.normal(0, om_var)

        x = X[i - 1] + dt * c(THETA[i - 1]) * (v[i] + nv)
        y = Y[i - 1] + dt * s(THETA[i - 1]) * (v[i] + nv)
        theta = THETA[i - 1] + dt * (om[i] + nom)

        X.append(x)
        Y.append(y)
        THETA.append(theta)

    X = np.asarray(X)
    Y = np.asarray(Y)
    THETA = np.asarray(THETA)

    return (X, Y, THETA)
def latlongtor(LATLONGH, planet, alfa_g0, t,
               t0):  #maybe need to add t_prev orbit
    #From Geodetic to PCI
    phi = LATLONGH[0]  #geodetic latitude
    lam = LATLONGH[1]  #longitude
    h = LATLONGH[2]  #altitude

    a = planet.Rp_e
    b = planet.Rp_p
    e = (1 - b**2 / a**2)**0.5
    alfa = lam + alfa_g0 + planet.omega[2] * (t - t0)
    const = a / (1 - e**2 * s(phi)**2) + h
    x = const * c(phi) * c(alfa)
    y = const * c(phi) * s(alfa)
    z = const * s(phi)

    return [x, y, z]
def rtolatlong(r_p, planet):
    # From PCPF to LLA through Bowring's method https://www.mathworks.com/help/aeroblks/ecefpositiontolla.html;jsessionid=2ae36964c7d5f2115d2c21286db0?nocookie=true
    x_p = r_p[0]
    y_p = r_p[1]
    z_p = r_p[2]

    f = (planet.Rp_e - planet.Rp_p) / planet.Rp_e  # flattening
    e = (1 - (1 - f)**2)  # ellipticity (NOTE =  considered as square)
    r = (x_p**2 + y_p**2)**0.5

    # Calculate initial guesses for reduced latitude (latr) and planet-detic latitude (latd)
    latr = at(z_p / ((1 - f) * r))  # reduced latitude
    latd = at((z_p + (e * (1 - f) * planet.Rp_e * s(latr)**3) / (1 - e)) /
              (r - e * planet.Rp_e * c(latr)**3))

    # Recalculate reduced latitude based on planet-detic latitude
    latr2 = at((1 - f) * s(latd) / c(latd))
    diff = latr - latr2

    # Iterate until reduced latitude converges
    while diff > 1e-10:
        latr = latr2
        latd = at((z_p + (e * (1 - f) * planet.Rp_e * s(latr)**3) / (1 - e)) /
                  (r - e * planet.Rp_e * c(latr)**3))
        latr2 = at((1 - f) * s(latd) / c(latd))
        diff = latr - latr2
    lat = latd

    #Calculate longitude
    lon = atan2(y_p, x_p)  # -180<lon<180
    #Calculate altitude
    N = planet.Rp_e / (
        1 - e * s(lat)**2)**0.5  # radius of curvature in the vertical prime
    alt = r * c(lat) + (z_p + e * N * s(lat)) * s(lat) - N
    return [alt, lat, lon]
Exemple #14
0
def check(c):
    if c < 2:
        return False
    if c == 2:
        return True
    for i in range(2, int(s(c)) + 1):
        if c % i == 0:
            return False
    return True
Exemple #15
0
def prime(p):
    if p == 2:
        return True
    if p < 2:
        return False
    for pp in range(2, int(s(p)) + 1):
        if p % pp == 0:
            return False
    return True
def isprime(n):
	count=0
	if n<=1:
		return False
	
	if n==2 or n==3:
		return True


	else:
		for i in range(2, int(s(n))+1 ):
			if(n%i == 0):
				count=0
				return False
			elif (n%i != 0):
				count+=1
			if count == int(s(n))-1:
				count=0
				return True
Exemple #17
0
 def primes_to_max(self):
     mark_set = set()
     prime_list = []
     for v in range(2, self.num + 1):
         if v not in mark_set:
             prime_list.append(v)
         if v <= s(self.num):
             time = 2
             while v * time <= self.num:
                 mark_set.add(v * time)
                 time += 1
     return prime_list
    def update_states(self, ft, tx, ty, tz):
        roll_ddot = ((self.Iy - self.Iz) /
                     self.Ix) * (self.pitch_dot * self.yaw_dot) + tx / self.Ix
        pitch_ddot = ((self.Iz - self.Ix) /
                      self.Iy) * (self.roll_dot * self.yaw_dot) + ty / self.Iy
        yaw_ddot = ((self.Ix - self.Iy) /
                    self.Iz) * (self.roll_dot * self.pitch_dot) + tz / self.Iz
        x_ddot = -(ft / self.m) * (s(self.roll) * s(self.yaw) +
                                   c(self.roll) * c(self.yaw) * s(self.pitch))
        y_ddot = -(ft / self.m) * (c(self.roll) * s(self.yaw) * s(self.pitch) -
                                   c(self.yaw) * s(self.roll))
        z_ddot = -1 * (self.g - (ft / self.m) * (c(self.roll) * c(self.pitch)))

        self.roll_dot += roll_ddot * DT
        self.roll += self.roll_dot * DT
        self.pitch_dot += pitch_ddot * DT
        self.pitch += self.pitch_dot * DT
        self.yaw_dot += yaw_ddot * DT
        self.yaw += self.yaw_dot * DT

        self.x_dot += x_ddot * DT
        self.x += self.x_dot * DT
        self.y_dot += y_ddot * DT
        self.y += self.y_dot * DT
        self.z_dot += z_ddot * DT
        self.z += self.z_dot * DT

        self.states = np.array([
            self.roll, self.pitch, self.yaw, self.roll_dot, self.pitch_dot,
            self.yaw_dot, self.x_dot, self.y_dot, self.z_dot, self.x, self.y,
            self.z
        ]).T

        self.record_states()
Exemple #19
0
 def from_dh(dh_params):
     d, theta, a, alpha = dh_params
     return Frame(
         np.array([[
             c(theta), -s(theta) * c(alpha),
             s(theta) * s(alpha), a * c(theta)
         ],
                   [
                       s(theta),
                       c(theta) * c(alpha), -c(theta) * s(alpha),
                       a * s(theta)
                   ], [0., s(alpha), c(alpha), d], [0., 0., 0., 1.]]))
def factorization(n):
    a=[]
    while n%2==0:
        a.append(2)
        n = n//2

    for i in range(3,int(s(n))+1,2):
        while n%i==0:
            a.append(i)
            n = n//i
                    
    if n>2:
        a.append(n)
    return a
def color3(h1):
    h = h1*s(3)
    w = h1*3
    f = open("hex4.txt",'r')
    l = list(map(list,f.read().split("\n")))
    r = len(l)
    c = len(l[0])
    for i in range(len(l)):
        l[i] = list(map(int,l[i]))
    pairs = pairs_helper.rect_pixel_pairs(w,h,r,c,True)
    massignment = [[0 for i in range(c)] for j in range(r)]
    a = total_cost(pairs,l,r,c)
    b = total_cost(pairs,massignment,r,c)
    print(w/3, a/b)
Exemple #22
0
def fk(robot):
    """

    :param robot:
    :return:
    """
    I, m, l, r = robot.unpack()
    theta_1 = robot.q[0]
    theta_2 = robot.q[1]
    theta_3 = robot.q[2]

    pose_1 = (0, 0, l[0])

    pose_2 = (l[1] * c(theta_2) * c(theta_1), l[1] * c(theta_2) * c(theta_1),
              l[0] + l[2] * s(theta_2))

    pose_3 = (
                 ( l[1]*c(theta_2) + l[2]*c(theta_2 + theta_3) )*c(theta_1), \
                 ( l[1]*c(theta_2) + l[2]*c(theta_2 + theta_3))*s(theta_1), \
                 ( l[0] + l[1]*s(theta_1) + l[2]*s(theta_2+theta_3))
             )

    return (pose_1, pose_2, pose_3)
def divisors(num):

    bottomHalf = set()
    div = set()
    for i in range(1, int(s(num)) + 1):
        if num % i == 0:
            bottomHalf.add(i)

    div.update(bottomHalf)

    for el in bottomHalf:
        div.add(num // el)

    div.remove(num)
    return div
def fk(joints):
    """

    :param robot:
    :return:
    """
    l = helper.get_lengths()

    theta_1 = joints[0]
    theta_2 = joints[1]
    theta_3 = joints[2]

    pose_1 = (0,0,l[0])

    pose_2 = ( l[1]*c(theta_2)*c(theta_1), l[1]*c(theta_2)*s(theta_1), l[0] + l[2]*s(theta_2) )

    pose_3 = (
                 ( l[1]*c(theta_2) + l[2]*c(theta_2 + theta_3) )*c(theta_1), \
                 ( l[1]*c(theta_2) + l[2]*c(theta_2 + theta_3))*s(theta_1), \
                 ( l[0] + l[1]*s(theta_2) + l[2]*s(theta_2+theta_3))
             )


    return  pose_1, pose_2, pose_3
Exemple #25
0
 def from_dh_modified(dh_params):
     d, theta, a, alpha = dh_params
     return Frame(
         np.array([[c(theta), -s(theta), 0, a],
                   [
                       s(theta) * c(alpha),
                       c(theta) * c(alpha), -s(alpha), -s(alpha) * d
                   ],
                   [
                       s(theta) * s(alpha),
                       c(theta) * s(alpha),
                       c(alpha),
                       c(alpha) * d
                   ], [0., 0., 0., 1.]]))
def ik(robot, pose):
    """

    :param robot:
    :param pose:
    :return:
    """
    I, m, l, r = robot.unpack
    x = pose[0]
    y = pose[1]
    z = pose[2]

    theta_1 = math.atan2(y,z)
    theta_3 = -math.ac( (x*x + y*y + (z- l[0])**2 -l[1]*l[1] - l[2]*l[2])/ ( 2*l[1]*l[2] )   ) - 0.5*math.pi
    theta_2 = math.atan2( z- l[0] , math.sqrt(x*x, y*y) ) - math.atan2( l[2]*s(theta_3), l[1] + l[2]*c(theta_3) )

    return (theta_1, theta_2, theta_3)
Exemple #27
0
def T(i, j):
    theta_i = math.radians(dh_table[i][3])
    a_j = dh_table[j][1]
    alpha_j = math.radians(dh_table[j][0])
    d_i = dh_table[i][2]
    return np.array([[c(theta_i), -s(theta_i), 0, a_j],
                     [
                         c(alpha_j) * s(theta_i),
                         c(alpha_j) * c(theta_i), -s(alpha_j),
                         -d_i * s(alpha_j)
                     ],
                     [
                         s(alpha_j) * s(theta_i),
                         s(alpha_j) * c(theta_i),
                         c(alpha_j), d_i * c(alpha_j)
                     ], [0, 0, 0, 1]])
Exemple #28
0
#!/usr/bin/python3.4

from modularites.print import *
from math import sqrt as s
import random as rand

p(s(16))
p(s(54))
p(rand.randrange(0, 60))
Exemple #29
0
def f():
    x1 = r() * s(3) / 2
    angle = r() * 2 * pi
    x2 = x1 + cos(angle)
    x2 = x2 % (s(3) / 2)
    return b(x1) * b(x2)
Exemple #30
0
from math import sqrt as s
  
a=[True]*(10**12)
a[0] = a[1] = False
for i in range(2,10**12+1,2):
            a[i]=False
for i in range(3,10**12+1,2):
    if a[i]:
        for j in range(i,10**12+1,i):
            a[i]=False
#print(a)

n=int(input())
x=list(map(int,input().split()))
for i in x:
    if(a[s(i)]):
        print("YES")
    else:
        print("NO")
            

Exemple #31
0
from math import sqrt as s


def check(c):
    if c < 2:
        return False
    if c == 2:
        return True
    for i in range(2, int(s(c)) + 1):
        if c % i == 0:
            return False
    return True


n = int(input())
for k in range(n):
    a = int(input())
    if check(a):
        print(a)
    else:
        m = 2
        for i in range(2, int(s(a)) + 1):
            while a % i == 0:
                m = max(2, i)
                a //= i
        if check(a) and a > m:
            print(a)
        else:
            print(m)
Exemple #32
0
import math as m

print(m.pi)
print(m.sqrt(4.0))
print(m.sqrt(2.0))

from math import pi, sqrt

print(pi)
print(sqrt(4.0))
print(sqrt(2.0))

from math import sqrt as s, pi as p

print(p)
print(s(4.0))
print(s(2.0))

import urllib.request as r

response = r.urlopen('http://www.google.co.kr')
print(response.status)

from urllib.request import Request, urlopen

req = Request('http://www.google.co.kr')
response = urlopen(req)
print(response.status)

from urllib.request import Request as r, urlopen as u
Exemple #33
0
#Generate a list of four digit numbers in a given range with all their digits even and the  number is a perfect square.

from math import sqrt as s

n = int(input("Enter a limit:"))
p = 0
for i in range(1000, n):
    if s(i) == int(s(i)) and i % 2 == 0:
        print(i)
#! /usr/bin/env python
import math as m
print m.sqrt(45)
from math import sqrt as s
print s(45)
import math
print(math.sqrt(9))


from math import sqrt
print(sqrt(9))

import math as m
print(m.sqrt(9))

from math import sqrt as s
print(s(9))
Exemple #36
0
import math

print(math.sqrt(16))

# lehet úgy is hogy csak azt az adott osztályt hívom be a modulból amire épp szüségem van:
from math import sqrt

print(math.sqrt(25))

# időtakarékos módszer, ha egyből példányosítom az osztályt:
from math import sqrt as s

print(s(36))

# mégegy módszer:
import math as m

print(m.sqrt(49))

# ... és mégegy:
#from math import * # ez minden osztályt behív a modulból nem túl jó, mert pl. lehetnek névegyezések más modulokban lévő osztályokkal

print(sqrt(64))

help(math.sqrt)


Exemple #37
0
'''
We can re-define a function or class while importing
'''

from math import sum as s

print('Sum: ', s(3, 4))
import math as m
# m ist neu der Name des mathematischen Module 
v = m.sin(m.pi)
print v

from math import log as ln 
v = ln(5)
print v

from math import sin as s, cos as c, log as ln 

x = m.pi
v = s(x)*c(x) + ln(x)
print v