Search code examples
javaphysicsjscience

Units in jScience; Whats the unit of an angular velocity?


In an application I'm making, I need some physics calculations (power, forces, torques etc.). I want to use JScience, because it seems really useful when it comes to keeping track of units. For instance, to assign a velocity I would do this:

Amount<Velocity> vel = Amount.valueOf(100, SI.METERS_PER_SECOND);

My problem is that I want to assign some angular velocity in a class, but I can't wrap my head around how I am supposed to do this. Say I want to specify an angular velocity of 100 rad/s.

Amount<AngularVelocity> angVel = Amount.valueOf(100, {SOME UNIT});

I can't find any unit in JScience to use for angular velocity. The documentation says "The system unit for this quantity is "rad/s" (radian per second).", but there is no such thing as a an "SI.RAD_PER_SECOND" or any enum value like that I think...

So the question is: What do I write as {SOME UNIT} in the latter code sample?

Cheers from Birger

---EDIT--

Got suggestions to use "SI.RADIAN.divide(SI.SECOND)" as unit, but then I have to assing the variable to a different type.

// This will not compile, due to type mismatch
Amount<AngularVelocity> angVel = Amount.valueOf(100, SI.RADIAN.divide(SI.SECOND));

// This will compile, but I want to assign the amount as a AngularVelocity ...
Amount<?> angVel = Amount.valueOf(100, SI.RADIAN.divide(SI.SECOND));

// Another, working alternative. But, surely, there is a way to assign an angular velocity using rad/s ... ?
Amount<Frequency> angVel = Amount.valueOf(100 * Math.PI, SI.HERTZ);

Solution

  • I'm no expert with this particular library, but some quick tests in eclipse led me to this :

    Amount<AngularVelocity> angVel = Amount.valueOf(100, AngularVelocity.UNIT);
    

    The problem with that is that if AngularVelocity.UNIT changes, your quntity will change too. But that's unlikely I'd say.

    Otherwise, giving a less beautiful line of code :

    Amount<AngularVelocity> angVel = Amount.valueOf(100, SI.RADIAN.divide(SI.SECOND).asType(AngularVelocity.class));
    

    This leads me to a good hint when programming in Java: Use control-space. A lot. I never used this library and I was still able to find this with just a quick check in the doc for the AngularVelocity.UNIT version. The other is just control-space after your own solution.