Can anyone tell me how using cosine similarity to see the correlation between two documents actually shows you if someone is plagiarising the other? I understand how cosine similarity works but don't understand how using this shows how closely related they are when the cosine deals with vectors and angles. How can this relate to a document?
Usually this would be used in conjunction with a bag of words model. You need to convert each document to a vector where the length of the vector is the number of words in the vocabulary. The entries in the vector correspond to the number of occurrences of each vocabulary word in the document. You can apply cosine similarity to these document vectors.
You should consider using tf-idf weighting to make sure that a small set of very common words doesn't end up dominating the distance computation. https://en.wikipedia.org/wiki/Tf%E2%80%93idf
I do NOT believe people use Cosine Similarity to detect plagiarism.
In information retrieval, using weighted TF-IDF and cosine similarity is a very common technique. It allows the system to quickly retrieve documents similar to a search query. This often works well, when the searched corpus is quite different.
However, in the case of detecting plagiarism. The searched corpus is very homogeneous from a bag of words perspective. This is because, say for an essay submission, ALL submitted essays cover the same topic so they have very similar bag of words. Also, since the same topic is covered in those essays, it is with almost certainty that those words with the highest weighted IDF such as proper nouns and uncommon words appear in most of the bags. Bag of words model is a very bad idea for this task. I would say if you run Cosine Similarity on TF-IDF vectors of the documents, there is a good chance that you find the entire class has similar essay.
I know for a fact that in order to check similarity, a much better algorithm exists. It is call 'Edit Distance', Levenshtein distance. This takes into account the order of the words in each documents. It runs slower in $O(n^2)$, but there are many ways to remedy this, and is often not a problem. This situation is different from the information retrieval situation.
For computer programs, the check can be done by turning the program into the symbolic representation. This is usually in form of a parsed tree. Then one can generate in-order, pre-order, post-order of the tree (or a set of major subtrees of this parsed tree such as of the main loop, main method etc..) and run 'Edit Distance' to compare similarity.
Remember that a TF-IDF approach does not take into account any structural property of documents unlike using parsed tree and edit distance as I mentioned above.