Saturday, September 27, 2014

New Blog

This weekend, I figured out how to use Jekyll, so this blog is moving to nielskornerup.github.io/Blog. I hope to see you all there!

Sunday, September 14, 2014

Elastic collisions

Hi! Today, I will tell you about a project that I have been working on in Independent study; an Elastic Collision simulator.

The Idea:
An Elastic Collision is one in which momentum and kinetic energy are conserved. Over the summer, I made a charged particle simulator, and starting this school year, I took the idea and made a gravity simulator. The primary problem with these two simulators is that particles can move inside of each other. In order to solve this problem, I want to implement Elastic Collisions, so I am working on the code with a different simulator. After I finish it, I plan to copy the code over to these two simulators to improve them as well.

The process:
To start this process, I first had to learn how Elastic collisions work. I found an equation to model the motion on Wikipedia. In order to implement this algorithm, I had to remember how to use arc tangent to compute angles from x and y speeds. The problem with arc tangent is that it has a range of (-pi/2, pi/2), so I had to figure out what the actual angle is depending on the sign on the X speed. If the X speed was negative, I would need to add pi to my result to get the correct angle. In order to calculate phi, I used the difference between x and y coordinates using the same basic system with arc tangent. In order to calculate the mass of a particle, I would square its radius.

The result:
This worked better than I expected, as a majority of the collisions looked accurate. Despite this, about 30% of my collisions were not working out as I expected them to. I started analyzing my code for bugs, but I could not find any. Eventually a classmate said that I could be having problems with particles tunneling into each other and preforming multiple collisions before escaping. Using this advice, I worked on creating anti-tunneling code.

Anti-tunneling:
In order to stop tunneling, I worked on a system where if two particles move into each-other, one will move backwards at the same angle until it is outside of the other. This seemed to solve my problem; however, I started having problems where particles would teleport when they collided. Thinking that this could be caused by multiple attempt to stop tunneling, I created a cool down timer for collisions, but this caused particles to get trapped inside of each other.

The state of my progress:
I have made significant progress on this project; however, I still have two bugs that I need to fix. I am hoping to fix these problems next week. See you then!

Tuesday, September 2, 2014

New year, new projects

Now I am in independent study for computer science, and I am working on a server that will allow clients to play games with clients that can be either AIs or actual players. We have decided on how we want to send input and output to and from the server. We have also implemented the rules for tic tack toe, which will be the default game for this project. Also, individually, I have worked on some of my own projects. I managed to get my charge simulator online, and I also wrote a gravity simulator. The charge simulator generates random charged particles at random velocities, and then simulates their movement while the gravity simulator does the same thing, but with gravity using differently sized objects. For both of these projects, I also figured out how to implement settings. The algorithms might still have a few bugs, so this is something that I plan to work on. I also plan to make a new project that tracks elastic collisions, but I need to learn how the physics behind that works first. I am also learning more javascript from this tutorial, and I plan to learn node.js for my projects. This year, I might also want to work on making my own blog using bootstrap, but I will see how things go. On a more personal level, I have been doing Aikido for about 1/2 a year now, and I have successfully advanced a rank.

Sunday, May 4, 2014

5/4/14 Update

Hi, today I will be giving you a status report on my progress. Thanks to the help of group members, I have figured out how to connect to git on a VPN. After figuring this out, I coded a signup confirmation Email using Nodemailer. Also, I wrote a java program to parse teacher names from the LASA website, which we will need for our website when students sign up for their classes. Last week, we were having difficulty connecting to koding, the service that we are using for our code, and so I worked on individual projects. First, I messed around with HTML because I haven't used it for a full  year. After that, I coded a java program that allows me to make digital quizbowl flashcards. Progress on our project has been slow, but I think that we will be able to work at full speed starting next week.

Monday, April 21, 2014

New project

Hi, and i'm back! I am currently working on a project with some of my friends where we are creating a website where students can access crowd sourced grades for assignments. I am new to web development, and so far I have been mostly working on figuring how things work. I learned how to connect to git using a terminal, and I am working on learning node and SQL. So far, we have created register and login pages, and I helped write the code for making sure that the usernames and passwords are registered. It works, but we are having a problem with how we hash our passwords. I have learned a lot, and this looks like it will be a lot of fun. I will be keeping you updated every other week with my progress.

Saturday, May 18, 2013

5/18/13 The end (for now)


Please note: in this post, I will be talking about my experience in AP computer science. If you just want to hear about what is going to happen to the blog, just read the last two paragraphs.

Thought this year, I have learned a lot about programming and java. In the beginning of the year, I was making the system council display “hello world” but by the end, I have created an AI that can play Quiz Bowl. I feel that by taking this AP computer science course, I feel confident to say that I can code fluent java. Not only do I feel that I know java, but I am also confident that I scored a 4 or 5 on the AP exam.
During the beginning of the year, we were learning about strings and I thought it inconceivable that indices start counting at 0 while the .length() method returns the last index as if the first index was 1. Later on, when we were learning about arrays, I found the idea to make perfect sense. I find it very cool how these things (like the length method and the rules for indices, as well as the range from a call of substring and the range for Math.random()) that appear to have completely nonsensical rules fit together in such an elegant manor (If you have arr[(int) (Math.random()*arr.length)], you will get a random index of arr).
I also found it cool to learn about evaluating Boolean expressions, but I wish that we would have spent more time doing that (learning about expressions like Xor and nor) and also looked at some graphic examples of the expressions (like Venn diagrams). I like how the class both prepared us for the AP, but also allowed room for learning fun and amazing concepts. The only thing that I wish I would have known better for the AP exam was Grid World (a case scenario used by the AP exam that has different actors on a Grid).
Thought the year, my favorite thing was probably when we programmed pong (and brick break for extra credit). I liked programming pong because it took all the knowledge that we had learned up to that point in the year, and use it to make a playable video game. My favorite topic that we learned this year was sorting. As you can probably tell from some of my pervious posts, I really like sorting data structures. Sorting seems like such a simple task when you first look at it (you are just sorting a list after all), but there are so many ways to do it, and they each have their own set of advantages/disadvantages. I also liked the labs where we would write a sorting algorithm and compare its speed to that of Collections.sort();.
Now that the AP exam is over, we get to spend our periods in Computer Science working on whatever CS project we want (everything from a Windows Kinect to Google apps script to coding Android apps with Java), and I wish that we would have gotten to do this kind of thing more often thought the year. As you can tell from the title of this post, it will be the last one that I am to do this year; however, my computer science teacher will probably have us continue blogging in advanced computer programming (a class that I will be taking next year), and so you may see more posts next fall.
In advanced computer programming, we will either be learning data structures in C++, Java, and Python (all programming languages), or the class will be an Independent study where we can work on our own computer science projects. As this will be the case, my future posts will be not only about Java, but also about other languages (I also plan to learn Javascript over the summer). As always, thanks for reading, and have a good summer!

Sunday, April 7, 2013

4/7/13 Recursion and divide and conquer

Recursion is when a function calls itself inside the function unless a stop condition is reached. In computer science, Recursion is not the most efficient way to solve a problem; however, it allows for you to use some algorithms that would otherwise be impossible. One such algorithm is quick sort, which works in O(n log n) time.

In quick sort, you are taking one element of an array to become a pivot point. After this, you go through all the other elements and sort them into two arrays; one with all the elements smaller than the pivot and the other with all the larger elements. After doing this, you return a new array that has the following things in the following order: A call of quick sort on the smaller array, the pivot, and then a call of quick sort on the larger array. If an array is ever one element long, quick sort just returns that one element.

Another O(n log N) sorting algorithm is called merge sort. In merge sort, you take your array and brake it down into two smaller ones. After that, you call merge sort on both of these arrays. After the arrays have been merge sorted, you know that each of them is in order, and now you just need to merge the two sub arrays. To do this, you have a counter for each sub array and you add the smaller element to your array out of the two counter's indexes and add one to that counter. If one counter is past the final element of its sub array, you just add the rest of the other sub array to the array. Then you return the newly sorted array. Again, this algorithm just returns the array if it only contains one element.

Both of these two recursive algorithms are called divide and conquer algorithms because they take the larger problem (sorting an array), and break it up into manageable peaces (one element arrays) to solve the initial problem. Such algorithms are very fast, despite the need for recursion. In general, quick sort and merge sort are two of thee fastest sorting algorithms.