コード例 #1
0
def to_rlf_robot_full_conf(robot11_confval, robot12_confval, scale=1e-3):
    # convert to full configuration of the RFL robot
    robot21_confval = [38000, 0, -4915, 0, 0, 0, 0, 0, 0]
    robot22_confval = [-12237, -4915, 0, 0, 0, 0, 0, 0]
    return Configuration(
        values=(
            *[robot11_confval[i] * scale for i in range(0, 3)],
            *[rad(robot11_confval[i]) for i in range(3, 9)],
            *[robot12_confval[i] * scale for i in range(0, 2)],
            *[rad(robot12_confval[i]) for i in range(2, 8)],
            # below fixed
            *[robot21_confval[i] * 1e-3 for i in range(0, 3)],
            *[rad(robot21_confval[i]) for i in range(3, 9)],
            *[robot22_confval[i] * 1e-3 for i in range(0, 2)],
            *[rad(robot22_confval[i]) for i in range(2, 8)],
        ),
        types=(2, 2, 2, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0,
               0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0),
        joint_names=('bridge1_joint_EA_X', 'robot11_joint_EA_Y',
                     'robot11_joint_EA_Z', 'robot11_joint_1',
                     'robot11_joint_2', 'robot11_joint_3', 'robot11_joint_4',
                     'robot11_joint_5', 'robot11_joint_6',
                     'robot12_joint_EA_Y', 'robot12_joint_EA_Z',
                     'robot12_joint_1', 'robot12_joint_2', 'robot12_joint_3',
                     'robot12_joint_4', 'robot12_joint_5', 'robot12_joint_6',
                     'bridge2_joint_EA_X', 'robot21_joint_EA_Y',
                     'robot21_joint_EA_Z', 'robot21_joint_1',
                     'robot21_joint_2', 'robot21_joint_3', 'robot21_joint_4',
                     'robot21_joint_5', 'robot21_joint_6',
                     'robot22_joint_EA_Y', 'robot22_joint_EA_Z',
                     'robot22_joint_1', 'robot22_joint_2', 'robot22_joint_3',
                     'robot22_joint_4', 'robot22_joint_5', 'robot22_joint_6'))
コード例 #2
0
ファイル: controller.py プロジェクト: pat-bert/6RUSRobot
def get_movement_from_cont(controls, pose):
    """Calculates new pose from controller-input ans returns it as a list
    `controls`:dict  inputs from controller
    `currentPose`:list  poselist of current pose"""
    # 0Z---> y
    # |
    # V x 

    dof = len(pose)
    if dof < 6:
        pose += [0] * (6 - dof)

    # Create a copy so we do not save state here
    pose = list(pose)

    # speedfactors
    rot_fac = 0.25
    trans_fac = 1

    # add controller inputs to values
    pose[0] += controls['LS_UD'] * trans_fac
    pose[1] += controls['LS_LR'] * trans_fac
    pose[2] += controls['RS_UD'] * trans_fac * -1

    pose[3] = deg(pose[3]) + (controls['LEFT'] - controls['RIGHT']) * rot_fac
    pose[4] = deg(pose[4]) + (controls['DOWN'] - controls['UP']) * rot_fac
    pose[5] = deg(pose[5]) + (controls['L1'] - controls['R1']) * rot_fac

    pose[3] = rad(pose[3])
    pose[4] = rad(pose[4])
    pose[5] = rad(pose[5])

    return pose
コード例 #3
0
    def project(self, lon, lat):
        from math import radians as rad, cos, sin
        lon, lat = self.ll(lon, lat)
        phi = rad(lat)
        lam = rad(lon)

        cos_c = sin(self.phi0) * sin(phi) + cos(
            self.phi0) * cos(phi) * cos(lam - self.lam0)
        k = (self.dist - 1) / (self.dist - cos_c)
        k = (self.dist - 1) / (self.dist - cos_c)

        k *= self.scale

        xo = self.r * k * cos(phi) * sin(lam - self.lam0)
        yo = -self.r * k * (cos(self.phi0) * sin(phi) -
                            sin(self.phi0) * cos(phi) * cos(lam - self.lam0))

        # rotate
        tilt = self.tilt_

        cos_up = cos(self.up_)
        sin_up = sin(self.up_)
        cos_tilt = cos(tilt)
        # sin_tilt = sin(tilt)

        H = self.r * (self.dist - 1)
        A = ((yo * cos_up + xo * sin_up) * sin(tilt / H)) + cos_tilt
        xt = (xo * cos_up - yo * sin_up) * cos(tilt / A)
        yt = (yo * cos_up + xo * sin_up) / A

        x = self.r + xt
        y = self.r + yt

        return (x, y)
コード例 #4
0
 def moveToAngle(self, angle):
     positions = self.fk.move(
         [rad(angle[0]), -rad(angle[1]), -rad(angle[2]), -rad(angle[3])])
     for i in range(4):
         self.robot.currentPosition[-i - 1][0] = positions[3 - i][1]
         self.robot.currentPosition[-i - 1][1] = positions[3 - i][0]
         self.robot.currentPosition[-i - 1][2] = positions[3 - i][2]
コード例 #5
0
ファイル: objetcs.py プロジェクト: Atmptdie/AstroParty
 def pew(self):
     Bullet(
         bullets, 'bullet.png', self.x + Ship.ship_iwidth // 2 -
         Ship.ship_iwidth // 2 * sin(rad(self.angle)),
         self.y + Ship.ship_iheight // 2 -
         Ship.ship_iheight // 2 * cos(rad(self.angle)), 500, 0, self.angle,
         self)
コード例 #6
0
 def project(self, lon, lat):
     lon, lat = self.ll(lon, lat)
     lam = rad(lon)
     phi = rad(lat * -1)
     x = lam * 1000
     y = math.log((1 + math.sin(phi)) / math.cos(phi)) * 1000
     return (x, y)
コード例 #7
0
    def measureError(self, spring_constants):
        for s in spring_constants:
            if s <= 0:
                return 10000
        error = 0
        for i in range(len(self.sampled_points)):
            point = self.get_z(self.sample_angles[i].copy(), spring_constants)
            origpos = self.fk.move([
                rad(self.sample_angles[i].copy()[0]),
                -rad(self.sample_angles[i].copy()[1]),
                -rad(self.sample_angles[i].copy()[2]),
                -rad(self.sample_angles[i].copy()[3])
            ])

            if i % 1 == 0:
                print("From: ", origpos[3][0], origpos[3][1], origpos[3][2])
                # temp = origpos[3][0]
                # origpos[3][0] = origpos[3][1]
                # origpos[3][1] = temp
                #print(origpos[3])
                print("To: ", point)
            h = origpos[3][2] - 10.5

            hdiff = origpos[3][2] - point[2]
            if point[2] - 10.5 < 0:
                return 10000
            if i % 1 == 0:
                print("Hdiff: ", hdiff * 10)
                print("Rdiff: ", h * 10 - self.sampled_points[i])
            point = point[0:1]
            origpos = origpos[3][0:1]
            #error += np.linalg.norm(origpos-point)+abs(hdiff*50-(h-self.sampled_points[i])*5)
            error += abs(hdiff * 10 - (h * 10 - self.sampled_points[i]))

        return error / len(self.sampled_points)
コード例 #8
0
ファイル: objetcs.py プロジェクト: Atmptdie/AstroParty
    def update(self, dt):
        super().update(dt)
        if self.rotating:
            self.angle += Ship.WSPEED * dt
            self.image = rot_center(self.base_image, self.angle)
        self.ax = -Ship.BASE_ACC * sin(rad(self.angle))
        self.ay = -Ship.BASE_ACC * cos(rad(self.angle))
        check_collision = self.collision_cirlce.update(
            self.x + Ship.ship_iwidth // 2 + 4 * sin(rad(self.angle)) - 9,
            self.y + Ship.ship_iheight // 2 + 4 * cos(rad(self.angle)) - 9)
        if check_collision['v']:
            if not self.colliding['v']:
                self.colliding['v'] = True
                self.vx_C = self.vx
            if not (self.ax * self.vx_C < 0 and self.vx_C * self.vx < 0):
                self.vx = 0
        else:
            self.colliding['v'] = False
            self.vx_C = 0

        if check_collision['h']:
            if not self.colliding['h']:
                self.colliding['h'] = True
                self.vy_C = self.vy
            if not (self.ay * self.vy_C < 0 and self.vy_C * self.vy < 0):
                self.vy = 0
        else:
            self.colliding['h'] = False
            self.vy_C = 0

        if check_collision['b']:
            self.shot()
コード例 #9
0
def calc_length(g, node_couple, pos_key):

    p1 = g.nodes[node_couple[0]][pos_key]
    p2 = g.nodes[node_couple[1]][pos_key]

    return np.sqrt((rad(p1[0]) - rad(p2[0]))**2 +
                   (rad(p1[1]) - rad(p2[1]))**2) * R_EARTH
コード例 #10
0
ファイル: vehicle_runner.py プロジェクト: Forrest-Z/prrt
def main():
    try:
        # if no arguments were passed print help
        if len(sys.argv) == 1:
            print_help()
            return
        # process shared argument across all functions
        command = int(sys.argv[1])
        vehicle_config_file = sys.argv[2]
        with open(vehicle_config_file) as f:
            vehicle_config = yaml.load(f)
        av = ArticulatedVehicleFactory.build_av(vehicle_config)
        argv_count = len(sys.argv)

        # process commands
        if command == 1 and argv_count == 7:
            test_plot(av, float(sys.argv[3]), float(sys.argv[4]),
                      rad(float(sys.argv[5])), rad(float(sys.argv[6])))
        # elif command ==2:
        #     # process command
        else:
            print_help()
    except:
        print()
        print('Error! Make sure to follow usage guidelines shown below')
        print('Error details:')
        print(traceback.print_exc())
        print_help()
コード例 #11
0
    def __init__(self, lift, duration, firing_order, advance=0):

        """
        Initialize a Camshaft instance

        :param lift: camshaft lift measured in mm
        :param duration: crank degrees between valve opening and closing
        :param firing_order: list of cylinder numbers in order of firing pattern
        :param  advance[optional]: camshaft (not crankshaft) degrees of advance
            - Positive means valve opens sooner than when piston is at TDC
            - Negative means valve opens later than when piston is at TDC
        """

        super(Camshaft, self).__init__()
        self.lift = lift
        self.duration = rad(duration)
        self.number_cylinders = len(firing_order)
        self.firing_order = firing_order
        self.advance = rad(advance)
        self.amplitude = None
        self.start_lift = tuple(rad(720 / self.number_cylinders * (cyl - 1))
                           for cyl in self.firing_order)

        # run methods to solve for parameters
        self.solve_amplitude()
コード例 #12
0
def TG(DEM,sunelevation,sunazimuth):
    from math import rad
    degree2radian = 0.01745;
    SZ_rad = sunelevation
    SA_rad = sunazimuth
    slope = rad(DEM.GetSlope())
    aspect = rad(DEM.GetAspect())
コード例 #13
0
 def project(self, lon, lat):
     lon, lat = self.ll(lon, lat)
     lam = rad(lon)
     phi = rad(lat * -1)
     x = 1032 * lam * math.cos(phi)
     y = 1032 * phi
     return (x, y)
コード例 #14
0
    def project(self, lon, lat):
        lon, lat = self.ll(lon, lat)
        lplam = rad(lon)
        lpphi = rad(lat * -1)

        p = self.C_p * math.sin(lpphi)
        V = lpphi * lpphi
        lpphi *= 0.895168 + V * (0.0218849 + V * 0.00826809)

        i = self.NITER
        while i > 0:
            c = math.cos(lpphi)
            s = math.sin(lpphi)
            V = (lpphi + s * (c + 2.) - p) / (1. + c * (c + 2.) - s * s)
            lpphi -= V
            if abs(V) < self.EPS:
                break
            i -= 1

        if i == 0:
            x = self.C_x * lplam
            y = (self.C_y, - self.C_y)[lpphi < 0]
        else:
            x = self.C_x * lplam * (1. + math.cos(lpphi))
            y = self.C_y * math.sin(lpphi)
        return (x, y)
コード例 #15
0
    def getDestination(self, distance, bearing, departure):
        """
        Returns the destination point following a orthodrome trajectory for a\ 
        given bearing and distance. `Link to
        documentation <http://www.movable-type.co.uk/scripts/latlong.html>`_.
        
        :param float distance: Distance in meters to the destination. 

        :param float bearing: Initial bearing of the orthodrome trajectory\
            starting at departure and ending at destination. In degrees.
        
        :param departure: Departure point of the trajectory.
        :type departure: list(float : lat, float : lon)
           
          
        :return: Destination reached following the othodrome trajectory. 
        :rtype: [float : lat, float : lon]
          
        """

        latDep, lonDep = [rad(departure[0]), rad(departure[1])]

        bearing = rad(bearing)

        latDest = asin(sin(latDep) * cos(distance / EARTH_RADIUS) + \
                       cos(latDep) * sin(distance / EARTH_RADIUS) * cos(bearing))

        lonDest = lonDep + atan2(sin(bearing) * sin(distance / EARTH_RADIUS) \
                                 * cos(latDep), cos(distance / EARTH_RADIUS) \
                                 - sin(latDep) * sin(latDest))

        latDest = (latDest * 180 / math.pi)
        lonDest = (lonDest * 180 / math.pi)

        return [latDest, lonDest]
コード例 #16
0
    def getDistAndBearing(self, position, destination):
        """
        Returns the distance and the initial bearing to follow to go to\
        a destination following a great circle trajectory (orthodrome). `Link to documentation`_
        
        :param position: Current position of the boat.
        :type position: list(float : lat, float : lon)
           
        :param destination: Point toward which the distance and initial bearing\
            are computed.
        :type destination: list(float : lat, float : lon)
           
          
        :return: Shortest distance between the two points in meters, and \
            initial bearing of the orthodrome trajectory in degrees. 
        :rtype: float: distance, float: bearing
        """
        latDest, lonDest = [rad(destination[0]), rad(destination[1])]
        latPos, lonPos = [rad(position[0]), rad(position[1])]

        a = (sin((latDest - latPos) / 2)) ** 2 + cos(latPos) * cos(latDest) * (sin((lonDest - lonPos) / 2)) ** 2

        distance = 2 * EARTH_RADIUS * atan2(a ** 0.5, (1 - a) ** 0.5)

        x = math.cos(latDest) * math.sin(lonDest - lonPos)
        y = math.cos(latPos) * math.sin(latDest) - math.sin(latPos) * math.cos(latDest) \
                                                   * math.cos(lonDest - lonPos)

        bearing = (math.atan2(x, y) * 180 / math.pi + 360) % 360

        return distance, bearing
コード例 #17
0
 def project(self, lon, lat):
     lon, lat = self.ll(lon, lat)
     lam = rad(lon)
     phi = rad(lat * -1)
     x = lam * 1000
     y = math.log((1 + math.sin(phi)) / math.cos(phi)) * 1000
     return (x, y)
コード例 #18
0
 def project(self, lon, lat):
     lon, lat = self.ll(lon, lat)
     lam = rad(lon)
     phi = rad(lat * -1)
     x = (lam) * math.cos(self.phi1) * 1000
     y = math.sin(phi) / math.cos(self.phi1) * 1000
     return (x, y)
コード例 #19
0
 def __init__(self, lat0=0.0, lon0=0.0, lat1=0.0, flip=0):
     self.lat0 = lat0
     self.lat1 = lat1
     self.phi0 = rad(lat0 * -1)
     self.phi1 = rad(lat1 * -1)
     self.lam0 = rad(lon0)
     Cylindrical.__init__(self, lon0=lon0, flip=flip)
コード例 #20
0
ファイル: equake_mashup.py プロジェクト: jwhite007/Mashup
def earthquake():
    url = 'http://www.seismi.org/api/eqs/2013?min_magnitude=7'
    resp = requests.get(url)
    data = json.loads(resp.text)
    city_list = ['Juneau, AK', 'Vancouver, BC', 'Seattle', 'Portland, OR', 'San Francisco, CA', 'Los Angeles, CA']
    city_dict = {}
    for city in city_list:
        lat_c = get_city_loc(city)[0]
        lng_c = get_city_loc(city)[1]
        intensity_list = []
        eq_dict = {}
        for i in range(len(data['earthquakes'])):
            stri = str(i + 1)
            timedate = data['earthquakes'][i]['timedate']
            lat_e = float(data['earthquakes'][i]['lat'])
            lng_e = float(data['earthquakes'][i]['lon'])
            mag = float(data['earthquakes'][i]['magnitude'])
            depth = float(data['earthquakes'][i]['depth'])
            #  Haversine calculation for distance using coordinates.
            R = 6371
            dLat = rad(lat_c - lat_e)
            dLon = rad(lng_c - lng_e)
            lat_er = rad(lat_e)
            lat_cr = rad(lat_c)
            a = sin(dLat/2) * sin(dLat/2) + sin(dLon/2) * sin(dLon/2) * cos(lat_er) * cos(lat_cr)
            c = 2 * atan2(sqrt(a), sqrt(1-a))
            epi_d = R * c
            depth_d = sqrt(depth**2 + epi_d**2)
            intensity = 10000 * mag / depth_d
            intensity_list.append(intensity)
            eq_dict[stri] = [timedate, str(epi_d), str(depth_d), str(mag), str(intensity)]
        intensity_avg = sum(intensity_list) / len(intensity_list)
        city_dict[city] = (str(intensity_avg), eq_dict)
    return city_dict
コード例 #21
0
    def _declination(self):
        """
        """
        appLong = self._appLong()
        oc = self._obliqCorr()

        return deg(asin(sin(rad(oc)) * sin(rad(appLong))))
コード例 #22
0
 def __init__(self, lat0=0.0, lon0=0.0, lat1=0.0, flip=0):
     self.lat0 = lat0
     self.lat1 = lat1
     self.phi0 = rad(lat0 * -1)
     self.phi1 = rad(lat1 * -1)
     self.lam0 = rad(lon0)
     Cylindrical.__init__(self, lon0=lon0, flip=flip)
コード例 #23
0
 def project(self, lon, lat):
     lon, lat = self.ll(lon, lat)
     lam = rad(lon)
     phi = rad(lat * -1)
     x = (lam) * math.cos(self.phi1) * 1000
     y = math.sin(phi) / math.cos(self.phi1) * 1000
     return (x, y)
コード例 #24
0
def flatten_delta(delta, alpha, A, D, L, x_centroid, y_centroid):
    delta = rad(delta)
    alpha = rad(alpha)
    H = sin(delta) * sin(D) + cos(delta) * cos(D) * cos(alpha - A)
    flat_delta = (sin(delta) * cos(D) -
                  cos(delta) * sin(D) * cos(alpha - A)) / H - y_centroid / L
    return flat_delta
コード例 #25
0
    def project(self, lon, lat):
        from math import radians as rad, pow, asin, cos, sin

        lon, lat = self.ll(lon, lat)
        phi = rad(lat)
        lam = rad(lon)

        cos_c = sin(self.phi0) * sin(phi) + cos(self.phi0) * cos(phi) * cos(lam - self.lam0)
        k = (self.dist - 1) / (self.dist - cos_c)
        k = (self.dist - 1) / (self.dist - cos_c)

        k *= self.scale

        xo = self.r * k * cos(phi) * sin(lam - self.lam0)
        yo = -self.r * k * (cos(self.phi0) * sin(phi) - sin(self.phi0) * cos(phi) * cos(lam - self.lam0))

        # rotate
        tilt = self.tilt_

        cos_up = cos(self.up_)
        sin_up = sin(self.up_)
        cos_tilt = cos(tilt)
        sin_tilt = sin(tilt)

        H = self.r * (self.dist - 1)
        A = ((yo * cos_up + xo * sin_up) * sin(tilt / H)) + cos_tilt
        xt = (xo * cos_up - yo * sin_up) * cos(tilt / A)
        yt = (yo * cos_up + xo * sin_up) / A

        x = self.r + xt
        y = self.r + yt

        return (x, y)
コード例 #26
0
 def ellie(a, b, orig, start_ang, stop_ang, seg):
     pts = []
     step_ang = (stop_ang - start_ang) / seg
     for ang in range(start_ang, stop_ang + step_ang, step_ang):
         pts.extend(
             [a * cos(rad(ang)) + orig[0], b * sin(rad(ang)) + orig[1]])
     return pts
コード例 #27
0
def area(pts, earthrad=6371):
	from math import radians as rad, sin, cos, asin, sqrt, pi, tan, atan
	pihalf = pi * .5

	n = len(pts)
	sum = 0
	for j in range(0,n):
		k = (j+1)%n
		if j == 0:
			lam1 = rad(pts[j][0])
			beta1 = rad(pts[j][1])
			cosB1 = cos(beta1)
		else:
			lam1 = lam2
			beta1 = beta2
			cosB1 = cosB2
		lam2 = rad(pts[k][0])
		beta2 = rad(pts[k][1])
		cosB2 = cos(beta2)
		
		if lam1 != lam2:
			hav = haversine( beta2 - beta1 ) + cosB1 * cosB2 * haversine(lam2 - lam1)
			a = 2 * asin(sqrt(hav))
			b = pihalf - beta2
			c = pihalf - beta1
			s = 0.5 * (a+b+c)
			t = tan(s*0.5) * tan((s-a)*0.5) * tan((s-b)*0.5) * tan((s-c)*0.5)
			excess = abs(4*atan(sqrt(abs(t))))
			if lam2 < lam1:
				excess = -excess
			sum += excess
	return abs(sum)*earthrad*earthrad
コード例 #28
0
ファイル: graphPolar.py プロジェクト: Clementef/Graphing-Tool
    def draw(self, expr):

        size = self.size

        temp = expr

        win = Graph.window(self)

        Graph.drawAxis(self, win)

        half = int(size / 2)

        for i in range(1000):

            expr = temp

            expr = sympify(expr)

            x = symbols('x')

            expr = expr.evalf(subs={x: i})

            point = Point(expr * cos(rad(i)) + half, half - expr * sin(rad(i)))

            point.draw(win)

        win.getMouse()
        win.close()
コード例 #29
0
ファイル: gui.py プロジェクト: buzz/sniegabuda-raspi
	def get_transformed_model(self, transforms):
		t = transforms

		scaling_matrix = np.matrix([
			[t['sx']/100, 0, 0, 1],
			[0, t['sy']/100, 0, 1],
			[0, 0, t['sz']/100, 1],
			[0, 0, 0, 1]
		])

		translation_matrix = np.matrix([
			[1, 0, 0, t['tx']],
			[0, 1, 0, t['ty']],
			[0, 0, 1, t['tz']],
			[0, 0, 0, 1   ]
		])

		rotation_matrix = np.matrix(euler_matrix(
			rad(t['rx']),
			rad(t['ry']),
			rad(t['rz'])
		))

		matrix = scaling_matrix * translation_matrix * rotation_matrix

		leds_ = leds.copy()
		leds_ = np.pad(leds_, (0,1), 'constant', constant_values=1)[:-1]
		leds_ = np.rot90(leds_, 3)
		leds_ = np.dot(matrix, leds_)
		leds_ = np.rot90(leds_)
		leds_ = np.array(leds_)

		return leds_
コード例 #30
0
 def fire_projectile(self, *kwargs):
     self.projectiles.append(
         self.projectile_type(self.physics_variables, kwargs))
     projectile = self.projectiles[-1]
     projectile.set_initial_conditions(
         [self.center[0], self.center[1], self.height], rad(self.azimuth),
         rad(self.inclination), self.vel)
     projectile.calculate_trajectory()
コード例 #31
0
    def _HaSunrise(self):
        """
        """
        declin = self._declination()

        rtn = cos(rad(90.833)) / (cos(rad(self._lat)) * cos(rad(declin)))
        rtn -= tan(rad(self._lat)) * tan(rad(declin))

        return deg(acos(rtn))
コード例 #32
0
ファイル: transform.py プロジェクト: geerk/something
def rotate_ox(m, b, a):
    cosa, sina = cos(rad(a)), sin(rad(a))
    rotm = translate(mat(1), [-b[0], -b[1], -b[2]])
    rotm = rotm * mat([[1,     0,    0, 0],
                       [0,  cosa, sina, 0],
                       [0, -sina, cosa, 0],
                       [0,     0,    0, 1]])
    rotm = rotm * translate(mat(1), b)
    return m * rotm
コード例 #33
0
ファイル: prismsort.py プロジェクト: o-date/creativity
def main():
    """Main loop; Open and save the picture file."""
    try:
        iteration = 0
        while iteration < NUM_OUTPUT:
            progress(iteration + 1, total=NUM_OUTPUT)

            # opening the file and glitching it
            im = openImage(FILENAME, RESIZE_FACT)[0]
            im = glitch(im, BLOCKS, ROTATION)

            # cropping the image to original size, except if fuzzy edges,
            # in which case a black border is left around the picture.
            trig = (abs(sin(rad(ROTATION)))
                    if abs(sin(rad(ROTATION))) > abs(cos(rad(ROTATION)))
                    else abs(cos(rad(ROTATION))))  # for fuzzy edges
            left = int((im.width -  # the current image width
                        IMAGE_WIDTH -  # the original image width
                        (0 if not FUZZY_EDGES
                         else IMAGE_WIDTH/BLOCKS*trig))/2)  # less crop
            top = int((im.height -
                       IMAGE_HEIGHT -
                       (0 if not FUZZY_EDGES
                        else IMAGE_HEIGHT/BLOCKS*trig))/2)
            right = int(IMAGE_WIDTH +
                        (im.width -
                         IMAGE_WIDTH +
                         (0 if not FUZZY_EDGES
                          else IMAGE_WIDTH/BLOCKS*trig))/2)
            bottom = int(IMAGE_HEIGHT +
                         (im.height -
                          IMAGE_HEIGHT +
                          (0 if not FUZZY_EDGES
                           else IMAGE_HEIGHT/BLOCKS*trig))/2)
            # Pillow uses (left, top, right, bottom) coordinates,
            # which define a rectangle region to keep.
            im = im.crop(box=(left, top, right, bottom))

            # saving the output
            if JPEG is None:
                im.save(FILENAME.split('.')[0]+'_out'+str(iteration)+".png")
            else:
                im.save(FILENAME.split('.')[0]+'_out'+str(iteration)+".jpg",
                        optimize=True,
                        quality=JPEG,
                        subsampling=0)  # see Pillow doc for jpeg options

            iteration += 1
            progress(done=True)
        print(BELL)  # blank line if silent

    except KeyboardInterrupt:
        print("\nCancelled."+NORM if not L
              else "\n\x1B[0m\U0001F308"
              if system() == "\x44\x61\x72\x77\x69\x6E"
              else "\n\x3A\x27\x28\x1B[0m")
        sys.exit(70)
コード例 #34
0
def rotate_ox(m, b, a):
    cosa, sina = cos(rad(a)), sin(rad(a))
    rotm = translate(mat(1), [-b[0], -b[1], -b[2]])
    rotm = rotm * mat([[1,     0,    0, 0],
                       [0,  cosa, sina, 0],
                       [0, -sina, cosa, 0],
                       [0,     0,    0, 1]])
    rotm = rotm * translate(mat(1), b)
    return m * rotm
コード例 #35
0
 def project(self, lon, lat):
     lon, lat = self.ll(lon, lat)
     lplam = rad(lon)
     lpphi = rad(lat * -1)
     phi2 = lpphi * lpphi
     phi4 = phi2 * phi2
     x = lplam * (self.A0 + phi2 * (self.A1 + phi2 * (self.A2 + phi4 * phi2 * (self.A3 + phi2 * self.A4)))) * 180 + 500
     y = lpphi * (self.B0 + phi2 * (self.B1 + phi4 * (self.B2 + self.B3 * phi2 + self.B4 * phi4))) * 180 + 270
     return (x, y)
コード例 #36
0
 def __init__(me, lon0=0, flip=0):
     me.EPS = 1e-10
     PseudoCylindrical.__init__(me, lon0=lon0, flip=flip)
     me.r = me.HALFPI * 100
     sea = []
     r = me.r
     for phi in range(0, 361):
         sea.append((math.cos(rad(phi)) * r, math.sin(rad(phi)) * r))
     me.sea = sea
コード例 #37
0
ファイル: objetcs.py プロジェクト: Atmptdie/AstroParty
 def set_active(self, x, y, angle):
     self.x = x
     self.y = y
     self.angle = angle
     self.vx = Pilot.BASE_SPEED * sin(rad(self.angle))
     self.vy = Pilot.BASE_SPEED * cos(rad(self.angle))
     self.image = rot_center(self.base_image, angle)
     self.active = True
     self.add(pilot_sprites)
コード例 #38
0
def test_place_coordinates():
  p = setup_place()
  lat = 50.1637973
  lon = 19.7855169

  assert p.lat_decimal == lat
  assert p.lat == rad(lat)
  assert p.lon_decimal == lon
  assert p.lon == rad(lon)
コード例 #39
0
ファイル: conic.py プロジェクト: Eugene-msc/kartograph.py
 def __init__(self, lat0=0, lon0=0, lat1=0, lat2=0):
     self.lat0 = lat0
     self.phi0 = rad(lat0)
     self.lon0 = lon0
     self.lam0 = rad(lon0)
     self.lat1 = lat1
     self.phi1 = rad(lat1)
     self.lat2 = lat2
     self.phi2 = rad(lat2)
コード例 #40
0
def Fs(aF_s, bF_s, Ang_zth): 
	
	'''
	Fraction of the forward aerosol scatter ratio dependant on the solar 
	zenith angle. [1] Eq: 3-11, pg 7.
	'''
	F_s = 1 - 0.5 * exp((aF_s + bF_s * cos(rad(Ang_zth))) * 
										cos(rad(Ang_zth)))
	
	return F_s
コード例 #41
0
def EdifcgWL(I_dir, I_dif_h, Ang_zth, rho_g, Ang_slp):
	
	# Ground reflected isotropic component on tilted surface.
	I_dif_c_g = pd.concat([I_dir, I_dif_h,], axis = 1
								).interpolate(method = 'linear')
	I_dif_c_g['I_dif_c_g'] = ((I_dif_c_g.I_dir * cos(rad(Ang_zth)) 
		+ I_dif_c_g.I_dif_h) * rho_g * (1 - 	cos(rad(Ang_slp))) / 2)
	I_dif_c_g = I_dif_c_g.iloc[:, -1]
	
	return I_dif_c_g
コード例 #42
0
ファイル: conic.py プロジェクト: kartograph/kartograph.py-old
	def __init__(self, lat0=0, lon0=0, lat1=0, lat2=0):
		from math import radians as rad
		self.lat0 = lat0
		self.phi0 = rad(lat0)
		self.lon0 = lon0
		self.lam0 = rad(lon0)
		self.lat1 = lat1
		self.phi1 = rad(lat1)
		self.lat2 = lat2
		self.phi2 = rad(lat2)
コード例 #43
0
def getPosition():
    """
        1) randomly pick angle from 180 to 359
        2) 3 if statements for diff regions
        3) case 1: dark green/ red region
            a) further split into < 270 and > 270
            b) calculate length of hyp of light and dark green regions using angle (abs value diff
                of angle and 270)
                and midpoint line
                randomly select distance between machine radius to min distance 
                or within dark green region
            c) calculate the x and y coordinates using trig laws
        4) case 2: left side light blue region
            a) further split into < 210 and > 210
            b) calculate the hyp formed from angle measure using the midpoint line
                and angle (abs value diff of angle and 210) 
                randomly pick distance from machine radius to hyp calculated
           c) calculate the x and y coordinates using trig laws
        5) case 3: right side light blue region
            a) further split into < 330 and > 330
            b) calculate the hyp formed from angle measure using the midpoint line
                and angle (abs value diff of angle and 330) 
                randomly pick distance from machine radius to hyp calculated
            c) calculate the x and y coordinates using trig laws
            
    """
    angle = randint(LEFT_TURN_ANGLE_MIN, RIGHT_TURN_ANGLE_MAX)
    #light blue left region
    if angle < FRONT_ANGLE_MIN:
        helperAngle = abs(angle - LEFT_MDPT)
        hyp = MAX_DISTANCE / cos(rad(helperAngle))
        pos = uniform(MACH_RADIUS + 0.0001, hyp)
        x = cos(rad(angle - 180)) * pos
        y = sin(rad(angle - 180)) * pos
        return [x * -1, y * -1]
    #dark green region
    elif angle < RIGHT_TURN_ANGLE_MIN:
        helperAngle = abs(angle - DES_OPP_ANGLE)
        lightHyp = MAX_DISTANCE / cos(rad(helperAngle))
        darkHyp = OPP_DISTANCE / cos(rad(helperAngle))
        pos = uniform(MACH_RADIUS + 0.0001, darkHyp)
        while pos >= MIN_DISTANCE and pos <= lightHyp:
            pos = uniform(MACH_RADIUS + 0.0001, darkHyp)
        y = cos(rad(abs(DES_OPP_ANGLE - angle))) * pos
        x = sin(rad(abs(DES_OPP_ANGLE - angle))) * pos
        if angle < DES_OPP_ANGLE:
            x *= -1
        return [x, y * -1]
    else:
        helperAngle = abs(angle - RIGHT_MDPT)
        hyp = MAX_DISTANCE / cos(rad(helperAngle))
        pos = uniform(MACH_RADIUS + 0.0001, hyp)
        x = cos(rad(360 - angle)) * pos
        y = sin(rad(360 - angle)) * pos
        return [x, y * -1]
コード例 #44
0
ファイル: ephem_tools.py プロジェクト: widget/iot-display
    def __init__(self, latlong_dd):
        self.observer = ephem.Observer()
        self.observer.name = 'Somewhere'
        self.observer.lat = rad(latlong_dd[0])  # lat/long in decimal degrees
        self.observer.long = rad(latlong_dd[1])
        self.observer.elevation = 0

        self.observer.date = date.today()

        self.observer.pressure = 1000
        self.gmt = pytz.timezone("GMT")
コード例 #45
0
ファイル: objetcs.py プロジェクト: Atmptdie/AstroParty
 def update(self, dt):
     self.x += self.vx * dt
     self.y += self.vy * dt
     self.rect.x = int(self.x)
     self.rect.y = int(self.y)
     if abs(self.vx) < abs(Ship.MAX_SPEED *
                           sin(rad(self.angle))) or self.ax * self.vx < 0:
         self.vx += self.ax * dt
     if abs(self.vy) < abs(Ship.MAX_SPEED *
                           cos(rad(self.angle))) or self.ay * self.vy < 0:
         self.vy += self.ay * dt
コード例 #46
0
    def project(self, lon, lat):
        me = self
        lon, lat = me.ll(lon, lat)

        lon = rad(lon)
        lat = rad(lat)

        y2 = lat * lat
        y4 = y2 * y2
        x = 1000 * lon * math.cos(lat) / (me.C1 + me.C3x3 * y2 + me.C5x5 * y4)
        y = 1000 * lat * (me.C1 + me.C3 * y2 + me.C5 * y4)
        return (x, y * -1)
コード例 #47
0
ファイル: robot.py プロジェクト: MountainNinja/-LifterBot2013
def markerDistance(marker):
    """Finds the relative forwards and sideways distance to a marker
    Input: marker
    Output: sideDist, forwardDist, totalDist"""
    forwardDist = 0
    sideDist = 0
    totalDist = 0
    p = marker.centre
    forwardDist = math.sin(math.rad(p.polar.rot_x))*p.polar.length
    sideDist = math.cos(math.rad(p.polar.rot_x))*p.polar.length
    totalDist = sideDist+forwardDist
    return sideDist, forwardDist, totalDist
コード例 #48
0
ファイル: conic.py プロジェクト: PythonCharmers/kartograph.py
    def __init__(self, lat0=0, lon0=0, lat1=0, lat2=0):
        self.lat0 = lat0
        self.phi0 = rad(lat0)
        self.lon0 = lon0
        self.lam0 = rad(lon0)
        self.lat1 = lat1
        self.phi1 = rad(lat1)
        self.lat2 = lat2
        self.phi2 = rad(lat2)

        if lon0 != 0.0:
            self.bounds = self.bounding_geometry()
コード例 #49
0
ファイル: conic.py プロジェクト: cemetek/kartograph.py
    def __init__(self, lat0=0, lon0=0, lat1=0, lat2=0):
        self.lat0 = lat0
        self.phi0 = rad(lat0)
        self.lon0 = lon0
        self.lam0 = rad(lon0)
        self.lat1 = lat1
        self.phi1 = rad(lat1)
        self.lat2 = lat2
        self.phi2 = rad(lat2)
        self.sea = self.sea_coords()

        if lon0 != 0.0:
            from Polygon import MultiPolygon as Poly
            self.inside_p = Poly(self.sea)
コード例 #50
0
ファイル: conic.py プロジェクト: kartograph/kartograph.py-old
	def project(self, lon, lat):
		lon,lat = self.ll(lon, lat)
		phi = rad(lat)
		lam = rad(lon)
		n = self.n		
		if abs(abs(phi) - self.HALFPI) < 1e-10:
			rho = 0.0
		else:
			rho = self.c * math.pow(math.tan(self.QUARTERPI + 0.5 * phi), -n)
		lam_ = (lam - self.lam0) * n
		x = 1000 * rho * math.sin(lam_)
		y = 1000 * (self.rho0 - rho * math.cos(lam_))
		
		return (x,y*-1)
コード例 #51
0
 def project(self, lon, lat):
     lon, lat = self.ll(lon, lat)
     lam = rad(lon)
     phi = rad(lat)
     if phi == self.phi0:
         x = lam * math.cos(self.phi0)
     else:
         try:
             x = lam * (phi - self.phi0) / (math.log(math.tan(self.QUARTERPI + phi * 0.5)) - math.log(math.tan(self.QUARTERPI + self.phi0 * 0.5)))
         except:
             return None
     x *= 1000
     y = 1000 * (phi - self.phi0)
     return (x, y * -1)
コード例 #52
0
ファイル: truchet.py プロジェクト: flag0010/truchet
 def __init__(self, xcenter, ycenter, style):
     self.a, self.b, self.c, self.d = [xcenter-.5, ycenter+.5],[xcenter+.5, ycenter+.5],  [xcenter-.5, ycenter-.5], [xcenter+.5, ycenter-.5]
     if style == 1:  #upper right and lower left arcs
         #first upper right
         x = [self.b[0] + cos(rad(i))/2. for i in range(180, 271)]
         y = [self.b[1] + sin(rad(i))/2. for i in range(180, 271)]
         x[44] = xcenter
         y[44] = ycenter
         self.p1 = [x,y]
         #now lower left
         x = [self.c[0] + cos(rad(i))/2. for i in range(0, 91)]
         y = [self.c[1] + sin(rad(i))/2. for i in range(0, 91)]
         x[44] = xcenter
         y[44] = ycenter
         self.p2 = [x,y]
     if style == 2:  #upper left and lower right arcs
         #first upper left
         x = [self.a[0] + cos(rad(i))/2. for i in range(270, 361)]
         y = [self.a[1] + sin(rad(i))/2. for i in range(270, 361)]
         x[44] = xcenter
         y[44] = ycenter
         self.p1 = [x,y]
         #now lower right
         x = [self.d[0] + cos(rad(i))/2. for i in range(90, 181)]
         y = [self.d[1] + sin(rad(i))/2. for i in range(90, 181)]
         x[44] = xcenter
         y[44] = ycenter
         self.p2 = [x,y]
コード例 #53
0
 def setAlpha(self, alpha):
     alpha = alpha % 360
     self.alpha = alpha
     if alpha < 45.0: # 1
         self.pos1 = self.h - 1 + self.w * tan(rad(alpha))
         self.pos2 = self.h - 1
         self.step = -1
         self.endPoints = self.endPointsH
         self.span = self.h
         return
     if 45.0 <= alpha < 90.0: # 2
         self.pos1 = self.w - 1 + self.h / tan(rad(alpha))
         self.pos2 = self.w - 1
         self.step = -1
         self.endPoints = self.endPointsV
         self.span = self.w
         return
     if 90.0 <= alpha < 135.0: # 3
         self.pos1 = self.w - 1
         self.pos2 = self.w - 1 - self.h / tan(rad(alpha))
         self.step = -1
         self.endPoints = self.endPointsV
         self.span = self.w
         return
     if 135.0 <= alpha < 180.0: # 4
         self.pos1 = self.w * tan(rad(alpha)) # this is correct since tan(pi - x) = -tan x
         self.pos2 = 0
         self.step = 1
         self.endPoints = self.endPointsH
         self.span = self.h
         return
     if 180.0 <= alpha < 225.0: # 5
         self.pos1 = 0
         self.pos2 = -self.w * tan(rad(alpha))
         self.step = 1
         self.endPoints = self.endPointsH
         self.span = self.h
         return
     if 225.0 <= alpha < 270.0: # 6
         self.pos1 = 0
         self.pos2 = -self.h / tan(rad(alpha))
         self.step = 1
         self.endPoints = self.endPointsV
         self.span = self.w
         return
     if 270.0 <= alpha < 315.0: # 7
         self.pos1 = self.h / tan(rad(alpha)) # this is correct since tan(x - 3/2 * pi) = -cot x
         self.pos2 = 0
         self.step = 1
         self.endPoints = self.endPointsV
         self.span = self.w
         return
     if 315.0 <= alpha: # 8
         self.pos1 = self.h - 1
         self.pos2 = self.h - 1 - self.w * tan(rad(alpha))
         self.step = -1
         self.endPoints = self.endPointsH
         self.span = self.h
         return
     raise ValueError("Weird Python behavior at angle: " + str(alpha))
コード例 #54
0
 def project(me, lon, lat):
     [lon, lat] = me.ll(lon, lat)
     lam = rad(lon)
     phi = rad(lat)
     c = math.sin(phi) * (me.CN, me.CS)[phi < 0.0]
     for i in range(me.NITER, 0, -1):
         th1 = (phi + math.sin(phi) - c) / (1.0 + math.cos(phi))
         phi -= th1
         if abs(th1) < me.EPS:
             break
     phi *= 0.5
     x = 1000 * me.FXC * lam * math.cos(phi)
     y = 1000 * math.sin(phi) * (me.FYCN, me.FYCS)[phi < 0.0]
     return (x, y * -1)
コード例 #55
0
 def project(me, lon, lat):
     [lon, lat] = me.ll(lon, lat)
     lam = rad(lon)
     phi = rad(lat)
     c = 0.5 * lam
     d = math.acos(math.cos(phi) * math.cos(c))
     if d != 0:
         y = 1.0 / math.sin(d)
         x = 2.0 * d * math.cos(phi) * math.sin(c) * y
         y *= d * math.sin(phi)
     else:
         x = y = 0
     if me.winkel:
         x = (x + lam * me.COSPHI1) * 0.5
         y = (y + phi) * 0.5
     return (x * 1000, y * -1000)
コード例 #56
0
ファイル: clDrawSVG.py プロジェクト: LordBlick/svgImportKiCAD
	def draw(self, cr):
		flen = len(self.fillColorA) if self.fillColorA else 0
		if flen in(3, 4):
			cr.push_group()
			cr.set_line_cap(cairo.LINE_CAP_ROUND)
			getattr(cr, 'set_source_rgb'+('', 'a')[flen==4])(*self.fillColorA)
			cr.set_line_width(self.width)
			cr.move_to(*self.start)
			cr.line_to(*self.end)
			cr.stroke()
			cr.pop_group_to_source()
			cr.paint()
		if self.frameColorA and(self.frameWidth):
			cr.push_group()
			cr.translate(*self.center)
			cr.rotate(-rad(self.orientation/10.))
			cr.translate(-self.center[0], -self.center[1])
			cr.set_line_cap(cairo.LINE_CAP_ROUND)
			cr.set_fill_rule(cairo.FILL_RULE_EVEN_ODD)
			cr.set_source_rgba(*self.frameColorA)
			cr.set_line_width(self.frameWidth)
			r = self.width/2.
			xsize = max(0, wdh - hgt)
			ysize = max(0, hgt - wdh)
			cr.move_to(ox - wdh/2., oy + ysize/2.)
			cr.arc(ox - xsize/2., oy - ysize/2., r, pi, 3 * pi/2.)
			cr.arc(ox + xsize/2., oy - ysize/2., r, 3 * pi/2., 2 * pi)
			cr.arc(ox + xsize/2., oy + ysize/2., r, 0, pi/2.)
			cr.arc(ox - xsize/2., oy + ysize/2., r, pi/2., pi)
			cr.pop_group_to_source()
			cr.paint()
コード例 #57
0
ファイル: emulation.py プロジェクト: wasmith/PyEmulate
	def calculate_int_waypoint(self, dec_lat, dec_lon, m_dist, dec_brng):
		lat = rad(dec_lat)
		lon = rad(dec_lon)
		brng = rad(dec_brng)
		dist = m_dist/1000
	
		new_lat = asin(sin(lat)*cos(dist/self.ER) + cos(lat)*sin(dist/self.ER)*cos(brng))
		new_lon = lon + atan2(sin(brng)*sin(dist/self.ER)*cos(lat),cos(dist/self.ER) - sin(lat)*sin(new_lat))
		norm_new_lon = (new_lon + (3*pi)) % (2*pi) - pi
	
		rnd_lat = deg(new_lat)
		rnd_lon = deg(norm_new_lon)
	
		new_latlon = (rnd_lat, rnd_lon);
	
		return new_latlon
コード例 #58
0
ファイル: azimuthal.py プロジェクト: Eugene-msc/kartograph.py
    def project(self, lon, lat):
        from math import radians as rad, pow, asin, cos, sin
        lon,lat = self.ll(lon, lat)
        phi = rad(lat)
        lam = rad(lon)

        k0 = 0.5
        k = 2*k0 / (1 + sin(self.phi0) * sin(phi) + cos(self.phi0)*cos(phi)*cos(lam - self.lam0))

        xo = self.r * k * cos(phi) * sin(lam - self.lam0)
        yo = -self.r * k * ( cos(self.phi0)*sin(phi) - sin(self.phi0)*cos(phi)*cos(lam - self.lam0) )

        x = self.r + xo
        y = self.r + yo

        return (x,y)
コード例 #59
0
    def project(self, lon, lat):
        lon, lat = self.ll(lon, lat)
        lplam = rad(lon)
        lpphi = rad(lat * -1)

        phi = abs(lpphi)
        i = int(phi * self.C1)
        if i >= self.NODES:
            i = self.NODES - 1
        phi = math.degrees(phi - self.RC1 * i)
        i *= 4
        x = 1000 * self._poly(self.X, i, phi) * self.FXC * lplam
        y = 1000 * self._poly(self.Y, i, phi) * self.FYC
        if lpphi < 0.0:
            y = -y

        return (x, y)