Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7402313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:42:52+00:00 2026-05-29T04:42:52+00:00

Let’s say you want to do some simple vector calculation: //this could be C++

  • 0

Let’s say you want to do some simple vector calculation:

//this could be C++
MyVectorType position = ...;
MyVectorType velocity = ...;
float dt;
//Here's the expression I want to calculate:
position += dt*velocity;

Now let’s say you want to do this in Java. There’s no operator overloading – ok, I can live without.

//this still could be C++
MyVectorType position = ...;
MyVectorType velocity = ...;
float dt;
//Here's the expression I want to calculate:
position.add(velocity.times(dt));

I would say it’s less readable, but still ok. How should I write the code above in Java? I thought I’d use javax.vecmath:

//my attempt in Java
Vector3f velocity = new Vector3f(...);
Vector3f position = new Vector3f(...);
float dt;
//Here's the expression I want to calculate - three lines.
Vector3f deltaPosition = new Vector3f(velocity);
deltaPosition.scale(dt);
position.add(deltaPosition);

Does it really require these three lines to perform such a simple operation? For people being used to reading mathematical expressions I think this is a pain, especially as the operations become more complex. Also, writing such expressions is not really a pleasure.

Am I missing something? Or is there another vector math package that leads to more readable code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:42:53+00:00Added an answer on May 29, 2026 at 4:42 am

    The javax.vecmath package is, unfortunately, kind of clunky. You might want to take a look at JAMA from NIST. It’s a matrix package, not a vector package (doesn’t have cross product, for example), but at least with that package, you can chain operations together on a single line:

    double[][] array = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}}; 
    Matrix A = new Matrix(array); 
    Matrix b = Matrix.random(3,1); 
    Matrix x = A.solve(b); 
    Matrix Residual = A.times(x).minus(b); 
    

    You can do a lot of vector arithmetic by treating vectors as 1xN matrices.

    NIST has also posted a page of links to other Java numerics packages where you might find something that’s a closer match to your needs if JAMA isn’t quite right.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have some text as follows: do this, do that, then this,
Let's say I have the string: hello world; some random text; foo; How could
Let's say i have this block of code, <div id=id1> This is some text
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have a drive such as C:\ , and I want to
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say there is a graph and some set of functions like: create-node ::
Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.