Mostrar mensagens com a etiqueta Asteroids. Mostrar todas as mensagens
Mostrar mensagens com a etiqueta Asteroids. Mostrar todas as mensagens

quarta-feira, agosto 01, 2018

Opposable Thumbs: “The Calculating Stars” by Mary Robinette Kowal




“There is nothing to see but that vast blackness. Intellectually, I know that we’ve passed into the dark side of the Earth. We slide into her shadow and then magic fills the sky. The stars come out. Millions of them in crisp, vivid splendor. These are not the stars that I remember from before the Meteor. These are clear and steady, without an atmosphere to make them twinkle. Do you remember the first time you saw the stars again? I am sitting in a capsule, on way my to the moon.”


In “The Calculating Stars” by Mary Robinette Kowal

I remember the one called "Duck and Cover". If I remember correctly, the instructions included:

1. Fill the bath with water
2. Take a door off it's hinges and prop it length-ways against an internal wall
3. Cover the door with a mattress
5. Get the family under the door.
6. Crouch down on the floor
7. Put your head between your legs
8. Kiss your arse goodbye

Even at 10 I thought that wouldn't help much...and it was bloody nonsense. How is an entire family going to take a bath before the four minute warning is up?

We're statistically overdue a large near earth object colliding with earth. Overdue in this context is wildly variable - range from 1 day to several hundred thousands of years depending on how you choose to measure. The main point is that if this does occur in the near future there is no technology available that would give a reasonable chance to even detect the damn thing. To paraphrase Doug Adams - space is big, really fucking big. We have about the same chance of seeing a significantly sized object inbound to us as a man sitting in his living room in London has of seeing a fly alighting from a randomly chosen dog turd in Moscow. Next step - assume that we manage to see this in advance and have reasonable notice. We haven't been beyond near earth orbit for 40 years. How would we get to this object and what would be brought to bear to deflect it?

I guess that educating people and getting them not to stand by a window may be advisable. In the same spirit I'm going to start training pedestrians to avoid damage from cars by hurling handfuls of peas at them from 100 yards. Knowing with certainty that a NEO will impact 30 years ahead of time, and knowing exactly how to nudge it to avoid that are unlikely in most cases -- even assuming a purely Newtonian world with perfect measurement of an object's current mass and trajectory. Except for contrived cases, the n-body motion problem in that world for n > 2 has no closed solutions. The numerical methods applied to it have some inherent and unavoidable error. Relativistic effects, although negligible, probably cannot be neglected if such precision so far ahead of time is to be achieved, further complicating the computation. And of course in the real world, measurements aren't exact. This is why this NEO work deals with probabilities, not certainties, and why (along with political difficulties) I suspect that the lead time will be shorter than 30 years and/or big bombs will be needed as opposed to little gravity tug methods. The first thing that needs sorting out, however, are the words: meteor, meteorite, meteoroid and asteroid. Meteoroids and asteroids are objects in space. Meteoroids can be bits of asteroids or bits of comets. When they are burning through Earth’s atmosphere they are, for a few seconds, called meteors. If anything survives that fiery descent, the rocks found on the ground are called meteorites. 2012DA14 was not going “too slow” for a related fragment to arrive at 17km/second: its radiant, relative velocity to the Earth before being accelerated was 5.6 km/sec. If you add to that the free-fall velocity of 11.2 km/sec (the corollary of escape velocity) you get 16.8 km/sec. Add to that the eastward rotation of the earth at 55degrees north at an Azimuth of 9 degrees south of east (0.2 km/sec) you arrive at precisely 17km/sec. This is the same calculation that Zuluaga and Ferrin (and now, NASA) must have done in reverse for their version of the reconstruction of the trajectory: I calculated the radial speed of their hypothesised orbits at the Earth’s position (r value/ radius from sun=1AU) on the day of impact (but without the Earth’s gravitational influence added) and ended up with 34.8 and 35.2 km/sec for the 2 posited orbits. That amounts to 5 and 5.4 km/sec relative to the Earth, respectively. Adding the free-fall velocity and the eastward rotation you get 16.4 and 16.8km/sec. The difference between these posited orbits and the posited 2012DA14 fragment is that they invoke the head-on trajectory solution with little or no curvature as they are pulled into the gravity well. If it’s a bulls-eye hit the curvature is zero. The Zuluaga and Ferrin video shows the meteor coming in from about 3 degrees above the solar plane. The NASA video now shows the same.





Saying something is a coincidence is essentially saying that they do not understand how it is connected. To accept such an answer is a fool's folly. And as for retracing its orbit, that is based on an assumption that this meteorite's orbit was stable and just happened to connect with the Earth when it did. The reason they make these claims is that they are still working on 100 year old models of our solar system that ignore its electric/ magnetic nature.

In fact we barely survived the asteroid or comet strike at the end of the younger Dryas 11500 years ago. We all watched Shoemaker Levy 9 crash into Jupiter with huge force, if that had struck the earth instead it would have been the end of humanity and yet funding for this area of science if virtually non existent. Asteroid strikes have shaped the world we live in and will do so again.. The danger is very real and unfortunately it will probably take a strike on a city to wake us up to the dangers...Its also a rare chance for us to come together as a species rather than trying to kill each other.....On the 'imagine if' subject of a 9-km wide asteroid impacting on the ocean, one wonders what the height of the tsunami wave would actually have been....Given that the deepest ocean is 11 Km (Mt. Everest is 8.8 Km by comparison), I see no reason why a tsunami wave might not exceed the height of Everest. Now that would be a surfer's paradise....The asteroid would probably vaporize a volume of water that would be hundreds of times its own mass also. By my calculation, a volume of water the size of Mt. Everest hitting the coast of California would be 250 billion cubic meters of water, enough to cover 2500 billion square meters to a depth of 10cm, which would only reach about 1600 Km in land. So dinosaurs east of Colorado would not even have got their feet wet, and given the natural barrier of the Rocky Mountains, I'm probably being conservative.

NASA didn't even send a woman into space until 1983, twenty years after the Soviets sent Valentina Tereshkova! They had female astronauts in training for the Apollo missions but they never got to fly because the men said it wouldn't be fair for men to miss out. Seriously. Meeting the requirements for astronaut selection were also very difficult for women. Men could get the test pilot training and flight hours through the military. Women couldn't. There's a huge gap in space science. It's a very tough field to be a woman in. From the attitudes of some of the men, to the constant assumptions about a woman's inability to do a job, it can be a nightmare. If you make a tiny mistake, it's because you were having a bad day and doesn't affect your ability to do your job, it'll be forgotten in a few hours. If a woman makes a mistake, it's because she's female and proof that women can't do the job, and it will be brought up repeatedly. That's just one tiny example of the problems women face in the industry. How women cope in the "tech bro" culture of Silicon Valley, I don't know.

We will all need to rush to the closest college or university to find a safe space to read "The Calculating Stars" and also twitter about our feelings on reading it until the comet is adequately shamed.


PS. My favorite dinosaur is the ornithomimus. I always goes for the underdog, me. If you had the ornithomimus card during dinosaur Top Trumps you were going home early. I bet T Rexes were all like, 'You won't be getting in the films, mate,' back then, and the ornithomimus would try and make a w with it's fingers but the arms were too short, it was just to v's. Imagine if they'd tried to film Clueless back in them days; that would mess that scene right up. Just goes to show, technology and culture basically proceeds at the speed it should. Always wondered why dinosaurs never developed technological intelligence seeing as they were around for so long. Perhaps they did and set off for the stars leaving the unintelligent lot behind? Because they laid eggs? Crocs have been around a very, very long time too, but laying eggs limits how much offspring can develop. Or because their claws got in the way of typing? Nah, opposable thumbs; it all comes down to those.

PPS. https://cneos.jpl.nasa.gov/sentry. Those clever people over at NASA put this together ready for their briefing session with Bruce Willis.

sexta-feira, junho 14, 2013

Advanced Python Class: Asteroids' Game (Final Project)






In 2013 I did a 3 months Python Course, where the final project was an Asteroid's Game. It took  me around 2 weeks to create it, but it was worth it...I'd to pull a lot of all-nighters...

To see the full code and play the game open the link at the end of the post and click the play button in the upper left corner. Because of sound (mp3) it's best to open it in Chrome (controls: left and right arrows rotate the ship. Up arrow activates the engines. Space bar fires missiles).

Follows the game specification handed over in class to be implemented by each student.

Game Specification:


"At the end of this project, your game will have multiple rocks and multiple missiles.  
You will lose a life if your ship collides with a rock and you will  score points if your missile collides with a rock. You will keep track  of the score and lives remaining and end the game at the proper time.  You may optionally add animated explosions when there is a collision.

Phase one -  Multiple rocks

For this phase, you will keep a set of rocks and spawn new rocks into this set.  This requires the following steps:

Remove a_rock and replace it with rock_group. Initialize the rock group to an empty set.

Modify your rock spawner to create a new rock (an instance of a Sprite object) and add it to rock_group.

Modify your rock spawner to limit the total number of rocks in the game at any one time. We suggest you limit it to 12. With too many rocks the game becomes less fun and the animation slows down significantly.

Create a helper function process_sprite_group. This function should take a set and a canvas and call the update and draw methods for each sprite in the group. Call the process_sprite_group function on rock_group in the draw handler.

Phase two - Collisions

For this phase, you will detect collisions between the ship and a rock. Upon a collision, the rock should be destroyed and the player should lose a life. To implement ship-rock collisions, you need to do the following:

Add a collide method to the Sprite class. This should take an other_object as an argument and return True if there is a collision or False otherwise. For now, this other object will always be your ship, but we want to be able to use this collide method to detect collisions with missiles later, as well.

Collisions can be detected using the radius of the two objects. This requires you to implement methods get_position and get_radius on both the Sprite and Ship classes.Implement a group_collide helper function. This function should take a set group and an a sprite other_object and check for collisions between other_object and elements of the group. If there is a collision, the colliding object should be removed from the group. To avoid removing an object from a set that you are iterating over (which can cause you a serious debugging headache), iterate over a copy of the set created via set(group). This function should return the number of collisions. Be sure to use the collide method from part 1 on the sprites in the group to accomplish this task.

In the draw handler, use the group_collide helper to determine if the ship hit any of the rocks. If so, decrease the number of lives by one. Note that you could have negative lives at this point. Don't worry about that yet.

At this point, you should have a game of "dodge 'em". You can fly around trying to avoid the rocks!

Phase three - Missiles

For this phase, you will keep a set of missiles and spawn new missiles into this set when firing using the space bar. This requires the following steps:

Remove a_missile and replace it with missile_group.  Initialize the missile group to an empty set. Modify your shoot method of my_ship to create a new missile (an instance of the Sprite class) and add it to the missile_group. If you use our code,the firing sound should play automatically each time a missile is spawned. 

In the draw handler, use your helper function process_sprite_group to process missile_group. While you can now shoot multiple missiles, you will notice that they stick around forever. To fix this, we need to modify the Sprite class and the process_sprite_group function.

In the update method of the Sprite class, increment the age of the sprite every time update is called. If the age is greater than or equal to the lifespan of the sprite, then we want to remove it. So, return False (meaning we want to keep it) if the age is less than the lifespan and True (meaning we want to remove it) otherwise.

Modify process_sprite_group to check the return value of update for sprites. If it returns True, remove the sprite from the group. Again, you will want to iterate over a copy of the sprite group in process_sprite_group to avoid deleting from the same set over which you are iterating.

Phase four - Collisions revisited

Now, we want to destroy rocks when they are hit by a missile. We can't quite use group_collide, because we want to check for collisions between two groups. All we need to do is add one more helper function:

Implement a final helper function group_group_collide that takes two groups of objects as input. group_group_collide should iterate through the elements of a copy of the first group using a for-loop and then call group_collide with each of these elements on the second group. group_group_collide should return the number of elements in the first group that collide with the second group as well as delete these elements in the first group.

Call group_group_collide in the draw handler to detect missile/rock collisions. 
Increment the score by the number of missile collisions.

Phase five - Finish it off

You now have a mostly working version of RiceRocks!!! Let's add a few final touches.

Add code to the draw handler such that, if the number of lives becomes 0, the game is reset and the splash screen appears. In particular, set the flag started to False, destroy all rocks and prevent any more rocks for spawning until the game is restarted.

When the game restarts, make sure the lives and the score are properly reset. Starting 
spawning rocks again. Restart the soundtrack.

When you spawn rocks, you want to make sure they are some distance away from the ship. 

Otherwise, you can die when a rock spawns on top of you, which isn't much fun. One simple way to acheive this effect to ignore a rock spawn event if the spawned rock is too close
to the ship.

Experiment with varying the velocity of rocks based on the score to make game play more 
difficult as the game progresses.

Tweak any constants that you have to make the game play the way you want.
Congratulations! You have completed the assignment. Enjoy playing your game!!!

Bonus

The following will not be graded. Feel free to try this, but do not break any of the other game functionality. We strongly recommend that you save your work before doing this and keeptrack of it, so you can submit a working version of the first five phases if you end up breaking your game trying to add more features.

One thing that is missing in your game is explosions when things collide. We have provided a tiled explosion image that you can use to create animated explosions. To get things working, you will need to do a few things:

In the draw method of the Sprite class, check if self.animated is True. If so, then choosethe correct tile in the image based on the age. The image is tiled horizontally. 

If self.animated is False, it should continue to draw the sprite as before.

Create an explosion_group global variable and initialize it to an empty set.

In group_collide, if there is a collision, create a new explosion (an instance of the Sprite class)and add it to the explosion_group. Make sure that each explosion plays the explosion sound.

In the draw handler, use process_sprite_group to process explosion_group.

You should now have explosions working!

Grading rubric - 13 pts (scaled to 100 pts)

Note that the animated explosions are not graded. However, please add comments concerning the quality of the explosions and general gameplay in the free comments at the bottom of the page. 

Please assess your peer's mini-projects in Chrome. If,for some reason, you must use Firefox or another browser (or had issues playing sounds in Chrome), please give your peers full credit on the sound-related rubric items.

1 pt - The program spawns multiple rocks.
1 pt - The program correctly determines whether the ship collides with a rock.
1 pt - The program removes a rock when the ship collides with a rock.
1 pt - The number of lives decreases by one when the ship collides with a rock.
1 pt - The program spawns multiple missiles.
1 pt - The program plays the firing sound when each missile is spawned.
1 pt - The program removes a missile that does not collide with a rock after 
some fixed time period.
1 pt - The program correctly determines whether a missile and a rock collide.
1 pt - The program removes missiles and rocks that collide.
1 pt - The score is updated appropriately after missile/rock collisions.
1 pt - When the lives go to zero, the splash screen reappears and all rocks 
are removed.
1 pt - When the splash screen is clicked, the lives are reset to 3, score is 
reset to zero and the soundtrack restarts.
1 pt - The game spawns rocks only when the splash screen is not visible and a 
game is in progressed."

Physics' primitives:


The game's challenge was to develop the basic primitives: vector acceleration, velocity, collision (detecting collisions between one object and a group, detecting collisions between two groups of objects), acceleration, friction, and orientation. Some of the notes from the class:







The collisons was the part that was the most tricky, because I'd to to keep redrawing the sprites and canvas at the same time:

# detecting collisions between one object and a group
def group_colide(group, other_object):
    global explosions
    collisions = 0
    for sprite in list(group):
        if sprite.colide(other_object):
            if tron:
                a_expl = Sprite(sprite.pos, [0,0], 0, 0, explosion_image, explosion_info, explosion_sound)
            else:
                a_expl = Sprite(sprite.pos, [0,0], 0, 0, explosion2_image, explosion2_info, explosion2_sound)
                
            explosions.add(a_expl)
            group.remove(sprite)
            collisions += 1
    return collisions
            
# detecting collisions between two groups of objects
def group_group_colide(group1, group2):
    collisions = 0
    for sprite in group1:
        collision = group_colide(group2, sprite)
        if collision > 0:
            group1.remove(sprite)
            collisions += collision
    return collisions

# displaying group of sprites
def process_sprite_group(sprite_set, canvas):
    if len(sprite_set)>0:
        for sprite in list(sprite_set):
            sprite.draw(canvas)
            sprite.update()
            if sprite.age == sprite.lifespan*10:
                sprite_set.remove(sprite)

For the full source code, see link. To play the game on the Google Chrome Browser the link is the same.