I Know there's a "Vector" class in java, but it seems to be just a simpler ArrayList type of deal, not an actual, mathematical Vector (as in a magnitude and a direction).
Is there any way to do Vector manipulations (particularly addition) in Java? Or am I stuck on my own having to implement it or use a third party module?
-Jenny
Yes, you'll have to write a class or use a library such as JScience
I don't think there is a built-in way to do vector addition, however I've found a series describing how this could be done.
If you are looking to make a vector in 2d space, couldn't you just go with a simple Point2D(x,y)
and let the length of your vector define magnitude?
So that Point2D a = new Point2D(1,1);
has a magnitude of 1.4, and a NE direction. And a Point2D b = new Point2D(2,2);
has the same direction but a magnitude of 2.8...
Addition would then just be: Point2D c = new Point2D(a.x + b.x, a.y + b.y);
In 3d space I would create my own class, or an entirely different data structure depending on you actual problem.
Edit: I hope he has found a solution in the past 3 years..
Java3D has various forms of Vector classes (Vector3d, Vector3f, Vector4d, etc). Java3D, of course, is somewhat risky these days, though, as it's seemingly set for abandonment.
Yes, you'll have to write a library (or use a third-party library) in order to perform vector arithmetic.
I know this is old but maybe someone will find this useful:
There is also Apache Commons Math which has a Vector2D class.