You should define radiansToDegree() before calling it.
EDIT: findBearing() is defined, but not called. So as bearing is assigned only in findBearing(), bearing is always undefined.
EDIT2:
What really confuses me is how can a vector be used to define coordinates? Which way is the arrow pointing?
You have to imagine a vector as an arrow from the origin (0, 0, 0) to its coordinates (x, y, z).
EDIT3:
A vector is not really an arrow, this is just an easy geometrical representation. Mathematically, a vector in a n-dimensional system is a group of n values relative to these n dimensions.
For example:
- in 2D, a coordinate can be represented by a vector (x, y) which is a couple of values.
- in 3D, a coordinate can be represented by a vector (x, y, z) which is a triplet of values.
- in 26D, a coordinate can be represented by a vector (a, b, c, ..., z) which is a 26-group of values.
Now, it's really easy too use vectors to represent things in 2D or 3D, so we use them. The math domain is called Vectorial spaces (well, at least in France).
But we use them for things with a lot more dimensions, like the preferences of a user:
- user intensity of preference of character 1 in a game,
- user intensity of preference of character 2 in a game,
- user intensity of preference of character 3 in a game,
- user intensity of preference of character 4 in a game,
- user intensity of preference of character 5 in a game,
- user intensity of preference of character 6 in a game.
Now we represent the intensity of preference for a user as a vector (0, 4, 6, 2, 5, 10).
And do this for all users.
And notice that the users are in groups, visible when representing geometrically all these vectors simultaneously (those liking character 1 not liking the character 3).
And do that for marketing or spam, to identify which people are likely to succumb to product X based on what we already know of them, and what already known similar people (those with near vectors) have succumbed to...