Can you do Vector addition in Java, natively?

后端 未结 6 1284
太阳男子
太阳男子 2020-12-17 09:15

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).

相关标签:
6条回答
  • 2020-12-17 09:35

    I know this is old but maybe someone will find this useful:

    There is also Apache Commons Math which has a Vector2D class.

    0 讨论(0)
  • 2020-12-17 09:45

    Yes, you'll have to write a class or use a library such as JScience

    0 讨论(0)
  • 2020-12-17 09:46

    Yes, you'll have to write a library (or use a third-party library) in order to perform vector arithmetic.

    0 讨论(0)
  • 2020-12-17 09:47

    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.

    0 讨论(0)
  • 2020-12-17 09:48

    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..

    0 讨论(0)
  • 2020-12-17 09:50

    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.

    0 讨论(0)
提交回复
热议问题