seivan/VectorArithmetic — pull request #1 by scottsievert (2014-07-12 22:09:55+00:00)
Title: cross product

Cross product is implemented as per our conversation on twitter. I believe this fits in with the Swift magic I don't get -- I used `dotProduct` as an example. I tested it against Python and looked at your `angleInRadians` and `magnitude` to ensure they returned the correct values.

Depending on how you init your vectors, the [right hand rule][1] may take effect and switch the sign. If the sign is flipped from NumPy (below), switch either the (x, y) components or the `angle(x) - angle(y)` around.

There are [other ways][2] to compute the cross product. While [defined for only three dimensions][3], it can be defined for n dimensions using exterior algebra and the [Hodge star operator][4].

```python
In [2]: from pylab import array, cross

In [3]: x = array([1, 0])

In [4]: y = array([sqrt(3), sqrt(2)])/2

In [5]: cross(x, y)
Out[5]: 0.70710678118654757
```

[1]:https://en.wikipedia.org/wiki/Right_hand_rule
[2]:https://en.wikipedia.org/wiki/Cross_product#Alternative_formulation
[3]:http://math.stackexchange.com/questions/185991/is-the-vector-cross-product-only-defined-for-3d
[4]:http://en.wikipedia.org/wiki/Hodge_dual