Esempio n. 1
0
def _bounce_one(a1, a2):
    # Bounces a1
    dir_angle = vectors.angle(a2.pos, a1.pos)

    vel_angle = vectors.angle(a1.velocity)

    # If they are head on then we want to swivel them a little
    if vectors.bound_angle(dir_angle[0] + 180) == vel_angle[0]:
        dir_angle[0] = vectors.bound_angle(dir_angle[0] + 40)

    # Keep trying distances further and further apart until they're
    # not going to be overlapping any more
    overlapping = True
    dist = vectors.total_velocity(a1.velocity)

    a2_rect = (a2.pos[0], a2.pos[1], a2.size[0], a2.size[1])

    while overlapping:
        new_pos = vectors.add_vectors(a1.pos, vectors.move_to_vector(dir_angle, dist))

        new_rect = (new_pos[0], new_pos[1], a1.size[0], a1.size[1])

        if not geometry.rect_collision(new_rect, a2_rect, True):
            overlapping = False

        dist += 1

    # Add a bit to be safe
    new_pos = vectors.add_vectors(a1.pos, vectors.move_to_vector(dir_angle, dist + vectors.total_velocity(a1.velocity)))

    a1.pos = new_pos
Esempio n. 2
0
def _bounce_both(a1, a2):
    # These are the angles directly away from each other
    angle1 = vectors.angle(a2.pos, a1.pos)
    angle2 = vectors.angle(a1.pos, a2.pos)

    vel_angle1 = vectors.angle(a1.velocity)
    vel_angle2 = vectors.angle(a2.velocity)

    # If they are head on then we want to swivel them a little
    if vel_angle1[0] == angle2[0] and vel_angle2[0] == angle1[0]:
        angle1[0] = vectors.bound_angle(angle1[0] + 20)
        angle2[0] = vectors.bound_angle(angle2[0] + 20)

    # Keep trying distances further and further apart until they're
    # not going to be overlapping any more
    overlapping = True
    dist_multiplier = 0.1

    while overlapping:
        dist_multiplier += 0.1

        new_pos1 = vectors.add_vectors(a1.pos, vectors.move_to_vector(angle1, max(a1.size) * dist_multiplier))

        new_pos2 = vectors.add_vectors(a2.pos, vectors.move_to_vector(angle2, max(a2.size) * dist_multiplier))

        new_rect1 = (new_pos1[0], new_pos1[1], a1.size[0], a1.size[1])
        new_rect2 = (new_pos2[0], new_pos2[1], a2.size[0], a2.size[1])

        if not geometry.rect_collision(new_rect1, new_rect2):
            overlapping = False

    a1.pos = new_pos1
    a2.pos = new_pos2
Esempio n. 3
0
def DisplayDay(lat, lon, day_of_year):
    local_timezone = TimeZoneEstimate(lat, lon)
    print "DisplayDay"
    days = day_of_year  # "August 2" (wikipedia) is 214. Set to day to calculate for.
    local_time = 12  # hours
    print "lat,lon=", [lat, lon], "timezone=", local_timezone
    year = datetime.date.today().year
    month = datetime.date.today().month
    day = datetime.date.today().day
    d = datetime.date(year, 1, 1) + datetime.timedelta(day_of_year - 1)
    print "day of year = (", day_of_year, ")", d
    print "Sunrise,Sunset=", GetSunriseSunset(days, local_time, lat, lon)
    print "As the sun travels the sky, it is at a zenith angle from"
    print "up/sky. It creates light with irradiance (Watts/meter**2) S"
    print "and illuminance (lux) and AM (solar energy atmospheric mass)."
    print "azimuth is sun's position clockwise from north (0 degrees),"
    print "east of 90, south of 180 and west of 270. zenith is angle from up"
    s = "  t zenith irradiance illum.   AM  azimuth      Sun[x,y,z]    window_angle  window_illum."
    print s
    s = "hrs   degs  W/m**2    lux      AM    degs      N/S W/E U/D        degs         lux"
    print s
    t = 0
    dt = 0.5  # hours
    year = d.day
    month = d.month
    day = d.day
    # window
    # obtain the window vector by finding two lat,lon points
    # pointing away from window:
    # import numpy as np
    # W = np.array([lat,lon,0])
    # import vectors as v
    # W = W/v.norm(W)
    # W[1] *= -1 # to switch direction of E/W to get outward normal
    W = [0.71898838, 0.6950221, 0.]  #normal to window
    import vectors as v
    while t <= 24:
        local_time = t
        z = GetZenith(days, local_time, lat, lon)
        AM = Airmass(z)
        lux = Lux(z)
        S_sunlight = lux / luminous_efficacy_sun
        azimuth = GetAzimuth(days, local_time, lat, lon)
        pt = SunPositionXYZ(lat, lon, local_time)
        pt = map(lambda val: round(val * 100000) / 100000.0, pt)
        window_angle = v.angle(W, pt)
        lux_window = max(0, cos(window_angle * pi / 180) * lux)
        s = '%4.1f %5.1f %6.1f %8.1f %6.1f %6.1f  %s  %5.1f %8.1f' % (
            t, z, S_sunlight, lux, AM, azimuth, str(pt), window_angle,
            lux_window)
        print s
        t += dt
    print "=" * 30
    return
Esempio n. 4
0
def inside_angles(a1, a2):
    """Takes two pairs and calculates the inside angles of A and B.
    Each pair is the position and angle towards C.
    """

    # Get the angles for point to point, using these we can
    # calculate the inside angles
    AC = a1[1][0]
    BC = a2[1][0]

    # Convert positions into angles
    AB = vectors.angle(a1[0], a2[0])[0]
    BA = vectors.angle(a2[0], a1[0])[0]

    # A
    if abs(AC - AB) > 180:
        if AC > AB:
            A = (360 - AC) + AB
        else:
            A = (360 - AB) + AC
    elif AB > AC:
        A = AB - AC
    else:
        A = AC - AB

    # B
    if abs(BC - BA) > 180:
        if BC > BA:
            B = (360 - BC) + BA
        else:
            B = (360 - BA) + BC
    elif BA > BC:
        B = BA - BC
    else:
        B = BC - BA

    # C
    C = 180 - A - B

    return A, B, C
Esempio n. 5
0
def inside_angles(a1, a2):
    """Takes two pairs and calculates the inside angles of A and B.
    Each pair is the position and angle towards C.
    """
    
    # Get the angles for point to point, using these we can
    # calculate the inside angles
    AC = a1[1][0]
    BC = a2[1][0]
    
    # Convert positions into angles
    AB = vectors.angle(a1[0], a2[0])[0]
    BA = vectors.angle(a2[0], a1[0])[0]
    
    # A
    if abs(AC - AB) > 180:
        if AC > AB:
            A = (360 - AC) + AB
        else:
            A = (360 - AB) + AC
    elif AB > AC:
        A = AB - AC
    else:
        A = AC - AB
    
    # B
    if abs(BC - BA) > 180:
        if BC > BA:
            B = (360 - BC) + BA
        else:
            B = (360 - BA) + BC
    elif BA > BC:
        B = BA - BC
    else:
        B = BC - BA
    
    # C
    C = 180 - A - B
    
    return A, B, C
def force_on_sails_matrix(wind, sail):         
    
    #get angle between wind and sail
    orientation = np.sign(np.cross(wind, sail))    
    angle = v.angle(wind, sail)
    if np.pi/2 < angle <= np.pi:
       angle = abs(np.pi - angle)
       orientation *= -1
       
    #get forces on sail (for 0 <= angle <= pi/2)
    drag = np.exp(abs(angle)/2) - 1
    lift = -orientation * np.exp(-20*(angle - 0.6)**2)

    return np.array([[drag, -lift], [lift, drag]])
Esempio n. 7
0
	def setKeyFrame(self, t):

		# set the position for a specific time frame
		cmds.setKeyframe(self._object, time = t, v = self._position[0], at = "tx")
		cmds.setKeyframe(self._object, time = t, v = self._position[1], at = "ty")
		cmds.setKeyframe(self._object, time = t, v = self._position[2], at = "tz")

		# take the euler from the boid (compared from original orientation)
		rotation = vectors.angle(self._velocity, V(0.0, 1.0, 0.0))
		rotationMatrix = M().rotate(self._velocity.cross(V(0.0, 1.0, 0.0)), rotation)
		eulerAngles = rotationMatrix.rotation()

		# set the euler angles for a specific time frame
		cmds.setKeyframe(self._object, time = t, v = -math.degrees(eulerAngles[0]), at = "rx")
		cmds.setKeyframe(self._object, time = t, v = -math.degrees(eulerAngles[1]), at = "ry")
		cmds.setKeyframe(self._object, time = t, v = -math.degrees(eulerAngles[2]), at = "rz")
Esempio n. 8
0
 def force_on_sails_matrix(wind, sail):         
     #1. get angle between wind and sail
     orientation = np.sign(np.cross(wind, sail))    
     angle = v.angle(wind, sail)
     if np.pi/2 < angle <= np.pi:
        angle = abs(np.pi - angle)
        orientation *= -1
        
     #2. get forces on sail (for 0 <= angle <= pi/2)
     #every ship has different parameters
     #so this is just game model boat 
     #to test control self-education ability
     drag = np.exp(abs(angle)/2) - 1
     lift = -orientation * np.exp(-20*(angle - 0.6)**2)
 
     return np.array([[drag, -lift], [lift, drag]])